This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
202 lines (197 loc) · 5.64 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
const path = require("path");
const nodeInputs = [
{
type: "input",
name: "nodeName",
message: "What would you like to name your node?",
default: "node-1",
},
{
type: "input",
name: "nodeCategory",
message: "Which category should your node belong to?",
default: "new category",
},
{
type: "input",
name: "nodeColor",
message: "What color should represent your node?",
default: "#FFFFFF",
validate: function (value) {
const hexColorRegex = /^#([0-9A-F]{3}|[0-9A-F]{6})$/i;
if (hexColorRegex.test(value)) {
return true;
}
return "Please enter a valid hex color code (e.g., #FFFFFF or #FFF)";
},
},
{
type: "input",
name: "nodeInputs",
message: "How many inputs should your node have?",
default: 1,
validate: function (value) {
const numberValue = parseInt(value, 10);
if (numberValue === 0 || numberValue === 1) {
return true;
}
return "Inputs must be either 0 or 1.";
},
},
{
type: "input",
name: "nodeOutputs",
message: "How many outputs should your node have?",
default: 1,
validate: function (value) {
const numberValue = parseInt(value, 10);
if (numberValue >= 0) {
return true;
}
return "Outputs must be 0 or more.";
},
},
];
const nodeActions = [
{
type: "add",
path: "{{projectName}}/src/nodes/{{dashCase nodeName}}/client/index.js",
templateFile: "templates/src/node/client/index.js.hbs",
},
{
type: "add",
path: "{{projectName}}/src/nodes/{{dashCase nodeName}}/client/index.html",
templateFile: "templates/src/node/client/index.html.hbs",
},
{
type: "add",
path: "{{projectName}}/src/nodes/{{dashCase nodeName}}/server/index.js",
templateFile: "templates/src/node/server/index.js.hbs",
},
{
type: "add",
path: "{{projectName}}/src/nodes/{{dashCase nodeName}}/client/locales/docs/en-US.html",
templateFile: "templates/src/node/client/locales/docs/en-US.html.hbs",
},
{
type: "add",
path: "{{projectName}}/src/nodes/{{dashCase nodeName}}/client/locales/labels/en-US.json",
templateFile: "templates/src/node/client/locales/labels/en-US.json.hbs",
},
{
type: "add",
path: "{{projectName}}/src/nodes/{{dashCase nodeName}}/client/icons/icon.png",
templateFile: "templates/src/node/client/icons/icon.png.hbs",
},
];
const nrgCliVersionInput = {
type: "input",
name: "nrgCliVersion",
message: "Which version of @allanoricil/nrg-cli would you like to use?",
default: "1.3.2",
};
module.exports = function (plop) {
const cwd = process.cwd();
plop.setGenerator("create", {
description: "Create new Project",
prompts: [
{
type: "input",
name: "projectName",
message: "What would you like to name your project?",
default: "nrg-project",
},
...nodeInputs,
nrgCliVersionInput,
],
actions: [
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/.husky/commit-msg"),
templateFile: "templates/.husky/commit-msg.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/.husky/pre-commit"),
templateFile: "templates/.husky/pre-commit.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/.browserslistrc"),
templateFile: "templates/.browserslistrc.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/.eslintignore"),
templateFile: "templates/.eslintignore.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/.eslintrc.json"),
templateFile: "templates/.eslintrc.json.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/.gitignore"),
templateFile: "templates/.gitignore.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/.npmignore"),
templateFile: "templates/.npmignore.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/.prettierignore"),
templateFile: "templates/.prettierignore.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/.prettierrc.json"),
templateFile: "templates/.prettierrc.json.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/.releaserc.json"),
templateFile: "templates/.releaserc.json.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/commitlint.config.js"),
templateFile: "templates/commitlint.config.js.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/jsconfig.json"),
templateFile: "templates/jsconfig.json.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/nrg.config.js"),
templateFile: "templates/nrg.config.js.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/package.json"),
templateFile: "templates/package.json.hbs",
},
{
type: "add",
path: path.resolve(cwd, "{{projectName}}/README.md"),
templateFile: "templates/README.md.hbs",
},
...nodeActions.map((action) => ({
...action,
path: path.resolve(cwd, action.path),
})),
],
});
plop.setGenerator("create:node", {
description: "Create new Node",
prompts: [...nodeInputs, nrgCliVersionInput],
actions: [...nodeActions].map((action) => ({
...action,
path: action.path.replace("{{projectName}}", process.cwd()),
})),
});
};