-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
100 lines (98 loc) · 2.85 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
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable global-require */
// eslint-disable-next-line func-names
const { readdirSync } = require("fs");
module.exports = function (plop) {
/**
* Generate a feature Page
*/
plop.setGenerator("Page", {
description: "Create new page",
prompts: [
{
type: "input",
name: "featureName",
message: "Feature name",
},
{
type: "input",
name: "pageName",
message: "Screen name",
},
],
actions: [
{
type: "add",
path: "src/pages/{{pascalCase featureName}}/{{pascalCase pageName}}/index.tsx",
templateFile: "templates/page/index.hbs",
skipIfExists: true,
},
{
type: "add",
path: "src/pages/{{pascalCase featureName}}/{{pascalCase pageName}}/index.test.tsx",
templateFile: "templates/page/test.hbs",
skipIfExists: true,
},
{
type: "append",
path: "src/routes/index.tsx",
pattern: `// Import screens`,
template: `import {{pascalCase pageName}} from '@pages/{{pascalCase featureName}}/{{pascalCase pageName}}'`,
},
{
type: "append",
path: "src/routes/index.tsx",
pattern: `{/* App Routes */}`,
template: ` <AppStack.Screen name="{{pascalCase pageName}}" component={ {{pascalCase pageName}} } />`,
},
{
type: "append",
path: "src/routes/types.ts",
pattern: `export type AppStackParamList = {`,
template: ` {{pascalCase pageName}}: undefined;`,
},
],
});
plop.setGenerator("Component", {
description: "Create new component",
prompts: [
{
type: "list",
name: "componentType",
message: "Component type",
choices: () =>
readdirSync(`${plop.getPlopfilePath()}/src/components`, {
withFileTypes: true,
})
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name),
},
{
type: "input",
name: "componentName",
message: "Component name",
},
],
actions: [
{
type: "add",
path: "src/components/{{componentType}}/{{pascalCase componentName}}/index.tsx",
templateFile: "templates/component/index.hbs",
skipIfExists: true,
},
{
type: "add",
path: "src/components/{{componentType}}/{{pascalCase componentName}}/index.test.tsx",
templateFile: "templates/component/test.hbs",
skipIfExists: true,
},
{
type: "add",
path: "src/components/{{componentType}}/{{pascalCase componentName}}/styles.ts",
templateFile: "templates/component/styles.hbs",
skipIfExists: true,
},
],
});
};