-
Notifications
You must be signed in to change notification settings - Fork 0
/
plop-comp.js
46 lines (46 loc) · 1.07 KB
/
plop-comp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { compCreator } from "./lib/CompCreator.js"
import path from "path"
import { cwd } from "process"
export default plop => {
plop.setHelper("pathName", function (input) {
console.log(input)
return path.basename(input)
})
plop.setGenerator("comp", {
description: "生成component",
prompts: [
{
type: "input",
name: "path",
message: "请输入component目标路径?",
},
],
actions: function () {
const addRouterPath = `${path.join(cwd(), "/src/router/routes.ts")}`
console.log(addRouterPath)
const res = [
{
type: "add",
path: compCreator.targetPath,
templateFile: "templates/vue/component.vue",
},
]
if (compCreator.options.children) {
res.push({
type: "append",
path: addRouterPath,
pattern: /(\/\/ -- APPEND CHILD ROUTER HERE --)/gi,
template: ` children: [
{
path: '/{{camelCase path}}',
name: '{{pathName path}}',
component: () => import('@/views//index.vue'),
meta: { title: '线索记录', ruleCode: 'pAdminClueLog' }
}
],`,
})
}
return res
},
})
}