-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
129 lines (117 loc) · 3.11 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
118
119
120
121
122
123
124
125
126
127
128
129
module.exports = function (plop) {
plop.addHelper("upperCase", function (text) {
return text.toUpperCase();
});
var pascalCase = (s) =>
s.replace(/\w+/g, function (w) {
return w[0].toUpperCase() + w.slice(1);
});
var files = {
mainComponent: "plop-templates/main-component.js",
styledComponent: "plop-templates/styled-component.js",
storybookStory: "plop-templates/storybook-story.js",
cssSnippet: "plop-templates/css.js",
indexFile: "plop-templates/index-file.js"
};
var createIndexFile = {
type: "add",
path: "src/components/{{kebabCase name}}/index.ts",
templateFile: files.indexFile,
};
var createFunctionComponent = {
type: "add",
path: "src/components/{{kebabCase name}}/{{pascalCase name}}.tsx",
templateFile: files.mainComponent,
};
var createStyledComp = {
type: "add",
path:
"src/components/{{kebabCase name}}/styles/S{{pascalCase name}}{{pascalCase suffix}}.tsx",
templateFile: files.styledComponent,
};
var createStyle = {
type: "add",
path: "src/components/{{kebabCase name}}/styles/S{{pascalCase name}}.tsx",
templateFile: files.styledComponent,
};
var createCssSnippet = {
type: "add",
path: "src/components/{{kebabCase name}}/styles/CSS{{pascalCase name}}{{pascalCase suffix}}.tsx",
templateFile: files.cssSnippet,
};
var createStory = {
type: "add",
path: "src/components/{{kebabCase name}}/{{pascalCase name}}.stories.tsx",
templateFile: files.storybookStory,
};
plop.setActionType("Usage:", function (answers, config, plop) {
const { name, suffix } = answers;
if (name && suffix) {
return `Usage:
<S${pascalCase(name)}${pascalCase(suffix)}/>
<S${pascalCase(name)}${pascalCase(suffix)}> </S${pascalCase(name)}${pascalCase(suffix)}>
`;
}
if (name) {
return `Usage:
<S${pascalCase(name)}/>
<S${pascalCase(name)}> </S${pascalCase(name)}>
`;
}
return ``;
});
/* Input Options */
var getComponentName = {
type: "input",
name: "name",
message: "What is the component name?",
validate: function (value) {
if (/.+/.test(value)) {
return true;
}
return "name is required";
},
};
var getStyleSuffix = {
type: "input",
name: "suffix",
message: "What is the styled component suffix?",
validate: function (value) {
if (/.+/.test(value)) {
return true;
}
return "name is required";
},
};
/* Generators */
plop.setGenerator("fc", {
description: "Function Component",
prompts: [getComponentName],
actions: [
createIndexFile,
createFunctionComponent,
createStyle,
createStory,
{
type: "Usage:",
},
],
});
plop.setGenerator("s", {
description: "Styled Component",
prompts: [getComponentName, getStyleSuffix],
actions: [
createStyledComp,
{
type: "Usage:",
},
],
});
plop.setGenerator("css", {
description: "Css Snippet",
prompts: [getComponentName, getStyleSuffix],
actions: [
createCssSnippet,
],
});
};