fix: 修复 plop 无法使用

This commit is contained in:
Hooray Hu 2023-10-31 20:57:30 +08:00
parent 3c3fbd1ece
commit 2e4af7c2f5
5 changed files with 19 additions and 14 deletions

View File

@ -1,4 +1,4 @@
const fs = require('node:fs')
import fs from 'node:fs'
function getFolder(path) {
const components = []
@ -13,7 +13,7 @@ function getFolder(path) {
return components
}
module.exports = {
export default {
description: '创建组件',
prompts: [
{

View File

@ -1,5 +1,5 @@
const path = require('node:path')
const fs = require('node:fs')
import path from 'node:path'
import fs from 'node:fs'
function getFolder(path) {
const components = []
@ -14,7 +14,7 @@ function getFolder(path) {
return components
}
module.exports = {
export default {
description: '创建标准模块 Mock',
prompts: [
{

View File

@ -1,5 +1,5 @@
const path = require('node:path')
const fs = require('node:fs')
import path from 'node:path'
import fs from 'node:fs'
function getFolder(path) {
const components = []
@ -14,7 +14,7 @@ function getFolder(path) {
return components
}
module.exports = {
export default {
description: '创建页面',
prompts: [
{

View File

@ -1,4 +1,4 @@
module.exports = {
export default {
description: '创建全局状态',
prompts: [
{

View File

@ -1,8 +1,13 @@
const fs = require('node:fs')
import { promises as fs } from 'node:fs'
module.exports = function (plop) {
export default async function (plop) {
plop.setWelcomeMessage('请选择需要创建的模式:')
fs.readdirSync('./plop-templates').forEach((item) => {
fs.lstatSync(`./plop-templates/${item}`).isDirectory() && plop.setGenerator(item, require(`./plop-templates/${item}/prompt`))
})
const items = await fs.readdir('./plop-templates')
for (const item of items) {
const stat = await fs.lstat(`./plop-templates/${item}`)
if (stat.isDirectory()) {
const prompt = await import(`./plop-templates/${item}/prompt.js`)
plop.setGenerator(item, prompt.default)
}
}
}