From 2e4af7c2f50e9258e6dd475c4f5838cc73ac50a5 Mon Sep 17 00:00:00 2001 From: Hooray Hu <304327508@qq.com> Date: Tue, 31 Oct 2023 20:57:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20plop=20=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plop-templates/component/prompt.js | 4 ++-- plop-templates/mock/prompt.js | 6 +++--- plop-templates/page/prompt.js | 6 +++--- plop-templates/store/prompt.js | 2 +- plopfile.js | 15 ++++++++++----- 5 files changed, 19 insertions(+), 14 deletions(-) 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) + } + } }