forked from growthbook/growthbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
163 lines (156 loc) · 4.74 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
module.exports = function (plop) {
// region Back-end
plop.setGenerator("router", {
description: "[back-end] Generates a router and controller",
prompts: [
{
type: "input",
name: "resource",
message:
"What is the name of the resource? Use the singular form, e.g. event for API GET /event",
},
],
actions: [
{
type: "add",
skipIfExists: true,
path:
"./packages/back-end/src/routers/{{kebabCase resource}}/{{kebabCase resource}}.router.ts",
templateFile: "./plop-templates/back-end/router.hbs",
},
{
type: "add",
skipIfExists: true,
path:
"./packages/back-end/src/routers/{{kebabCase resource}}/{{kebabCase resource}}.controller.ts",
templateFile: "./plop-templates/back-end/controller.hbs",
},
],
});
// endregion Back-end
// region Front-end
plop.setGenerator("component", {
description: "[front-end] Generates a component and a Storybook story",
prompts: [
{
type: "input",
name: "component",
message: "What should the name of the component be?",
},
],
actions: [
{
type: "add",
skipIfExists: true,
path:
"./packages/front-end/components/{{pascalCase component}}/{{pascalCase component}}.tsx",
templateFile: "./plop-templates/front-end/component.hbs",
},
{
type: "add",
skipIfExists: true,
path:
"./packages/front-end/components/{{pascalCase component}}/{{pascalCase component}}.stories.tsx",
templateFile: "./plop-templates/front-end/component-story.hbs",
},
],
});
plop.setGenerator("api-object", {
description: "[back-end] Generate REST API list and get endpoints",
prompts: [
{
type: "input",
name: "object",
message:
"The singular name of the API object (e.g. 'metric' or 'data source')",
},
],
actions: [
{
type: "add",
skipIfExists: true,
path:
"./packages/back-end/src/api/{{kebabCase object}}s/{{kebabCase object}}s.router.ts",
templateFile: "./plop-templates/back-end/api/router.hbs",
},
{
type: "add",
skipIfExists: true,
path:
"./packages/back-end/src/api/{{kebabCase object}}s/list{{pascalCase object}}s.ts",
templateFile: "./plop-templates/back-end/api/list.hbs",
},
{
type: "add",
skipIfExists: true,
path:
"./packages/back-end/src/api/{{kebabCase object}}s/get{{pascalCase object}}.ts",
templateFile: "./plop-templates/back-end/api/get.hbs",
},
{
type: "add",
skipIfExists: true,
path:
"./packages/back-end/src/api/openapi/schemas/{{pascalCase object}}.yaml",
templateFile: "./plop-templates/back-end/api/openapi_model.hbs",
},
{
type: "add",
skipIfExists: true,
path:
"./packages/back-end/src/api/openapi/paths/list{{pascalCase object}}s.yaml",
templateFile: "./plop-templates/back-end/api/openapi_list.hbs",
},
{
type: "add",
skipIfExists: true,
path:
"./packages/back-end/src/api/openapi/paths/get{{pascalCase object}}.yaml",
templateFile: "./plop-templates/back-end/api/openapi_get.hbs",
},
{
type: "append",
path: "./packages/back-end/src/api/openapi/schemas/_index.yaml",
template: `
{{pascalCase object}}:
$ref: './{{pascalCase object}}.yaml'
`.trim(),
},
{
type: "append",
path: "./packages/back-end/src/api/openapi/openapi.yaml",
pattern: /PLOP_INSERT_PATHS_HERE/,
template: ` /{{kebabCase object}}s:
$ref: "./paths/list{{pascalCase object}}s.yaml"
/{{kebabCase object}}s/{id}:
$ref: "./paths/get{{pascalCase object}}.yaml"`,
},
],
});
plop.setGenerator("next-page", {
description: "[front-end] Generates a Next.js page",
prompts: [
{
type: "input",
name: "route",
message:
"What is the path this should live? e.g. settings/webhooks/[eventwebhookid] if you want to create the file settings/webhooks/[eventwebhookid].tsx",
},
{
type: "input",
name: "pageName",
message:
"What is the name of this page? This is used internally in the file and will have a `Page` suffix, e.g. EventWebHookDetail will be EventWebHookDetailPage",
},
],
actions: [
{
type: "add",
skipIfExists: true,
path: "./packages/front-end/pages/{{route}}.tsx",
templateFile: "./plop-templates/front-end/next-page.hbs",
},
],
});
// endregion Front-end
};