diff --git a/plop-templates/component/prompt.js b/plop-templates/component/prompt.js index 44204df..984efab 100755 --- a/plop-templates/component/prompt.js +++ b/plop-templates/component/prompt.js @@ -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: [ { diff --git a/plop-templates/mock/prompt.js b/plop-templates/mock/prompt.js index 070e724..186a385 100755 --- a/plop-templates/mock/prompt.js +++ b/plop-templates/mock/prompt.js @@ -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: [ { diff --git a/plop-templates/page/prompt.js b/plop-templates/page/prompt.js index b84ea3a..bf05dc0 100755 --- a/plop-templates/page/prompt.js +++ b/plop-templates/page/prompt.js @@ -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: [ { diff --git a/plop-templates/store/prompt.js b/plop-templates/store/prompt.js index 2cefa24..3ccc785 100755 --- a/plop-templates/store/prompt.js +++ b/plop-templates/store/prompt.js @@ -1,4 +1,4 @@ -module.exports = { +export default { description: '创建全局状态', prompts: [ { diff --git a/plopfile.js b/plopfile.js index faa98cc..0d2aa5f 100755 --- a/plopfile.js +++ b/plopfile.js @@ -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) + } + } }