-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
117 lines (114 loc) · 3.15 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const path = require("path");
const dedent = require("dedent");
const glob = require("glob");
module.exports = function (plop) {
plop.setPrompt("search-list", require("inquirer-search-list"));
plop.setGenerator("component", {
prompts: [
{
type: "input",
name: "name",
},
{
type: "search-list",
name: "category",
message: "Choose a category",
choices: [
"Actions",
"Structure",
"Forms",
"Images and icons",
"Feedback indicators",
"Titles and text",
"Behavior",
"Lists and tables",
"Navigation",
"Overlays",
],
},
],
actions: [
{
type: "add",
path: "src/components/{{properCase name}}/{{properCase name}}.tsx",
templateFile: "plop-templates/component/Component.tsx.hbs",
},
{
type: "add",
path: "src/components/{{properCase name}}/index.ts",
templateFile: "plop-templates/component/index.ts.hbs",
},
{
type: "add",
path: "src/components/{{properCase name}}/{{properCase name}}.module.css",
templateFile: "plop-templates/component/Component.module.css.hbs",
},
{
type: "add",
path: "src/components/{{properCase name}}/{{properCase name}}.stories.mdx",
templateFile: "plop-templates/component/Component.stories.mdx.hbs",
},
{
type: "append",
path: "src/components/index.ts",
template:
'export { {{properCase name }} } from "./{{properCase name}}";',
},
],
});
plop.setGenerator("subcomponent", {
prompts: [
{
type: "input",
name: "name",
},
{
type: "search-list",
name: "parent",
message: "Choose the parent component",
choices: () =>
glob.sync("src/components/*/").map((p) => path.basename(p)),
},
],
actions: [
{
type: "add",
path: "src/components/{{parent}}/components/{{properCase name}}/{{properCase name}}.js",
templateFile: "plop-templates/component/Component.js.hbs",
},
{
type: "add",
path: "src/components/{{parent}}/components/{{properCase name}}/index.js",
templateFile: "plop-templates/component/index.js.hbs",
},
{
type: "add",
path: "src/components/{{parent}}/components/index.js",
skipIfExists: true,
},
{
type: "append",
path: "src/components/{{parent}}/components/index.js",
template:
'export { {{properCase name }} } from "./{{properCase name}}";',
},
{
type: "append",
path: "src/components/{{parent}}/{{parent}}.module.css",
template: dedent`
.{{properCase name}} {
@apply utilityClass;
}
`,
},
{
type: "append",
path: "src/components/{{parent}}/{{parent}}.js",
template: dedent`
import { {{properCase name}} } from "./components";
{{properCase parent}}.{{properCase name}} = {{properCase name}};
`,
},
],
});
};