-
-
Notifications
You must be signed in to change notification settings - Fork 173
/
plopfile.js
99 lines (84 loc) · 2.29 KB
/
plopfile.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const camelCase = (str) => {
return str.replace(/[-_]([a-z])/g, (g) => g[1].toUpperCase())
}
const capitalize = (str) => {
return str.charAt(0).toUpperCase() + str.slice(1)
}
const multiCapitalize = (str) => {
return str.split("-").map(capitalize).join(" ")
}
/**
* @param {import("plop").NodePlopAPI} plop
*/
module.exports = function main(plop) {
plop.setHelper("camelize", camelCase)
plop.setHelper("capitalize", capitalize)
plop.setHelper("multiCapitalize", multiCapitalize)
plop.setGenerator("machine", {
description: "Generates a new ui machine",
prompts: [
{
type: "input",
name: "machine",
message: "Enter machine name (e.g. menu, popover):",
},
],
actions(answers) {
const actions = []
if (!answers) return actions
const { machine } = answers
actions.push({
type: "addMany",
templateFiles: "plop/machine/**",
destination: `packages/machines/{{dashCase machine}}`,
base: "plop/machine/",
data: { machine, name: machine },
abortOnFail: true,
})
actions.push({
type: "addMany",
templateFiles: "plop/machine-examples/**",
destination: `examples`,
base: "plop/machine-examples/",
data: { machine, name: machine },
abortOnFail: true,
})
actions.push({
type: "modify",
path: "shared/src/routes.ts",
pattern: /\= \[/,
template: '= [\n { label: "{{multiCapitalize machine}}", path: "/{{machine}}" },',
})
return actions
},
})
plop.setGenerator("utility", {
description: "Generates a utils package",
prompts: [
{
type: "input",
name: "name",
message: "Enter package name:",
},
{
type: "input",
name: "description",
message: "The description of this package:",
},
],
actions(answers) {
const actions = []
if (!answers) return actions
const { name, description } = answers
actions.push({
type: "addMany",
templateFiles: "plop/utility/**",
destination: `packages/utilities/{{dashCase name}}`,
base: "plop/utility/",
data: { description, name },
abortOnFail: true,
})
return actions
},
})
}