优化 plop 启动脚本,自动读取模版目录

This commit is contained in:
Hooray Hu 2023-06-01 23:46:17 +08:00
parent 0e55453f3d
commit 33bef7bd93

View File

@ -1,6 +1,8 @@
const fs = require('node:fs')
module.exports = function (plop) {
plop.setWelcomeMessage('请选择需要创建的模式:')
plop.setGenerator('page', require('./plop-templates/page/prompt'))
plop.setGenerator('component', require('./plop-templates/component/prompt'))
plop.setGenerator('store', require('./plop-templates/store/prompt'))
fs.readdirSync('./plop-templates').forEach((item) => {
plop.setGenerator(item, require(`./plop-templates/${item}/prompt`))
})
}