Skip to content

Commit

Permalink
修复 plop 无法使用
Browse files Browse the repository at this point in the history
  • Loading branch information
hooray committed Oct 31, 2023
1 parent e670ddd commit e7cfe91
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions plop-templates/component/prompt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('node:fs')
import fs from 'node:fs'

function getFolder(path) {
const components = []
Expand All @@ -13,7 +13,7 @@ function getFolder(path) {
return components
}

module.exports = {
export default {
description: '创建组件',
prompts: [
{
Expand Down
6 changes: 3 additions & 3 deletions plop-templates/mock/prompt.js
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -14,7 +14,7 @@ function getFolder(path) {
return components
}

module.exports = {
export default {
description: '创建标准模块 Mock',
prompts: [
{
Expand Down
6 changes: 3 additions & 3 deletions plop-templates/page/prompt.js
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -14,7 +14,7 @@ function getFolder(path) {
return components
}

module.exports = {
export default {
description: '创建页面',
prompts: [
{
Expand Down
2 changes: 1 addition & 1 deletion plop-templates/store/prompt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
description: '创建全局状态',
prompts: [
{
Expand Down
15 changes: 10 additions & 5 deletions plopfile.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit e7cfe91

Please sign in to comment.