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) { function getFolder(path) {
const components = [] const components = []
@ -13,7 +13,7 @@ function getFolder(path) {
return components return components
} }
module.exports = { export default {
description: '创建组件', description: '创建组件',
prompts: [ prompts: [
{ {

View File

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

View File

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

View File

@ -1,4 +1,4 @@
module.exports = { export default {
description: '创建全局状态', description: '创建全局状态',
prompts: [ 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('请选择需要创建的模式:') plop.setWelcomeMessage('请选择需要创建的模式:')
fs.readdirSync('./plop-templates').forEach((item) => { const items = await fs.readdir('./plop-templates')
fs.lstatSync(`./plop-templates/${item}`).isDirectory() && plop.setGenerator(item, require(`./plop-templates/${item}/prompt`)) 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)
}
}
} }