-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
76 lines (65 loc) · 2.17 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
const capitalize = (str) => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
const camelCase = (str) => {
return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
};
// eslint-disable-next-line no-unused-vars,import/no-unused-modules,func-names
export default function (plop) {
plop.setHelper("capitalize", (text) => {
return capitalize(camelCase(text));
});
plop.setHelper("camelCase", (text) => {
return camelCase(text);
});
plop.setGenerator("package", {
description: `Generates a package`,
prompts: [
{
type: "input",
name: `packageName`,
message: `Enter package name:`,
validate: (value) => {
if (!value) {
return `package name is required`;
}
// check is case is correct
if (value !== value.toLowerCase()) {
return `package name must be in lowercase`;
}
// cannot have spaces
if (value.includes(" ")) {
return `package name cannot have spaces`;
}
return true;
},
},
{
type: "input",
name: "description",
message: `The description of this package:`,
},
],
actions(answers) {
const actions = [];
if (!answers) return actions;
const { description, outDir } = answers;
const generatorName = answers[`packageName`] ?? "";
const data = {
[`packageName`]: generatorName,
description,
outDir,
};
actions.push({
type: "addMany",
templateFiles: `plop/package/**`,
destination: `./packages//{{dashCase packageName}}`,
base: `plop/package`,
globOptions: { dot: true },
data,
abortOnFail: true,
});
return actions;
},
});
}