-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
58 lines (52 loc) · 1.46 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
/**
* @param {import('plop').NodePlopAPI} plop
*/
export default function (plop) {
plop.setGenerator("element", {
description: "adds a new element",
prompts: [
{
type: "input",
name: "name",
message: "name of the element",
filter(value) {
const val = String(value);
return val.replace("usa-", "");
},
},
],
actions: [
{
type: "addMany",
destination: "src/lib/{{kebabCase name}}",
base: "generators/element",
templateFiles: "generators/element",
},
{
type: "modify",
path: "src/lib/define.ts",
transform(template, { name }) {
const kebabCase = plop.getHelper("kebabCase")(name);
const imprt = `import "./${kebabCase}/${kebabCase}.element.js"`;
if (template.includes(imprt)) {
return template;
}
return `${template.trim()}\n${imprt}`;
},
},
{
type: "modify",
path: "src/lib.ts",
transform(template, { name }) {
const kebabCase = plop.getHelper("kebabCase")(name);
const pascalCase = plop.getHelper("pascalCase")(name);
const exprt = `export { USA${pascalCase}Element } from "./lib/${kebabCase}/${kebabCase}.element.js";`;
if (template.includes(exprt)) {
return template;
}
return `${template.trim()}\n${exprt}`;
},
},
],
});
}