-
Notifications
You must be signed in to change notification settings - Fork 23
/
plopfile.js
89 lines (77 loc) · 1.98 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
const workspaces = ['apps']
const generators = ['app']
const defaultOutDirs = {
app: 'apps'
}
/**
* @param {import("plop").NodePlopAPI} plop
*/
module.exports = function main(plop) {
generators.forEach((gen) => {
plop.setGenerator(gen, {
description: `Generates a ${gen}`,
prompts: [
{
type: 'input',
name: `${gen}Name`,
message: `Enter ${gen} name:`,
validate: (value) => {
if (!value) {
return `${gen} name is required`
}
// check is case is correct
if (value !== value.toLowerCase()) {
return `${gen} name must be in lowercase`
}
// cannot have spaces
if (value.includes(' ')) {
return `${gen} name cannot have spaces`
}
return true
}
},
{
type: 'input',
name: 'description',
message: `The description of this ${gen}:`
},
{
type: 'list',
name: 'outDir',
message: `where should this ${gen} live?`,
default: defaultOutDirs[gen],
choices: workspaces,
validate: (value) => {
if (!value) {
return `outDir is required`
}
return true
}
}
],
actions(answers) {
const actions = []
if (!answers) return actions
const { description, outDir } = answers
const generatorName = answers[`${gen}Name`] ?? ''
const data = {
[`${gen}Name`]: generatorName,
description,
outDir
}
actions.push({
type: 'addMany',
templateFiles: `plop/${gen}/**`,
destination: `./{{outDir}}/{{dashCase ${gen}Name}}`,
base: `plop/${gen}`,
data,
abortOnFail: true,
globOptions: {
dot: true
}
})
return actions
}
})
})
}