mirror of
https://github.com/wmn1525/grasscutterTools.git
synced 2024-11-29 02:27:19 +00:00
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
const path = require('path')
|
|
const fs = require('fs')
|
|
|
|
function getFolder(path) {
|
|
let components = []
|
|
const files = fs.readdirSync(path)
|
|
files.forEach(function (item) {
|
|
let stat = fs.lstatSync(path + '/' + item)
|
|
if (stat.isDirectory() === true && item != 'components') {
|
|
components.push(path + '/' + item)
|
|
components.push.apply(components, getFolder(path + '/' + item))
|
|
}
|
|
})
|
|
return components
|
|
}
|
|
|
|
module.exports = {
|
|
description: '创建页面',
|
|
prompts: [
|
|
{
|
|
type: 'list',
|
|
name: 'path',
|
|
message: '请选择页面创建目录',
|
|
choices: getFolder('src/pages')
|
|
},
|
|
{
|
|
type: 'input',
|
|
name: 'name',
|
|
message: '请输入文件名',
|
|
validate: v => {
|
|
if (!v || v.trim === '') {
|
|
return '文件名不能为空'
|
|
} else {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
],
|
|
actions: data => {
|
|
let relativePath = path.relative('src/pages', data.path)
|
|
const actions = [
|
|
{
|
|
type: 'add',
|
|
path: `${data.path}/{{dotCase name}}.vue`,
|
|
templateFile: 'plop-tpls/page/index.hbs',
|
|
data: {
|
|
componentName: `${relativePath} ${data.name}`
|
|
}
|
|
}
|
|
]
|
|
return actions
|
|
}
|
|
} |