-
Notifications
You must be signed in to change notification settings - Fork 5
/
plopfile.js
139 lines (136 loc) · 4.65 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
// Run `yarn plop` to use the generators defined in this file.
// see READMEs/generators.md for more information.
// eslint-disable-next-line import/no-anonymous-default-export
export default function (plop) {
// Create a new component with a test stub and Storybook entry.
plop.setGenerator('Component', {
description: 'New React component',
prompts: [
{
type: 'input',
name: 'name',
message: 'Component Name',
},
],
actions: [
{
type: 'add',
path: 'src/templates/components/{{camelCase name}}/index.tsx',
templateFile: 'generator-templates/component/index.hbs',
},
{
type: 'add',
path: 'src/templates/components/{{camelCase name}}/index.test.tsx',
templateFile: 'generator-templates/component/test.hbs',
},
{
type: 'add',
path: 'src/templates/components/{{camelCase name}}/{{camelCase name}}.stories.ts',
templateFile: 'generator-templates/component/story.hbs',
},
],
})
// Create a new data query. This defaults to Drupal boilerplate.
// TODO: option for non-drupal data sources.
plop.setGenerator('Query', {
description: 'New Data query',
prompts: [
{
type: 'input',
name: 'name',
message: 'Query name please',
},
],
actions: [
{
type: 'add',
path: 'src/data/queries/{{camelCase name}}.ts',
templateFile: 'generator-templates/query/query.hbs',
},
{
type: 'add',
path: 'src/data/queries/tests/{{camelCase name}}.test.tsx',
templateFile: 'generator-templates/query/test.hbs',
},
{
type: 'add',
path: 'src/mocks/{{camelCase name}}.mock.json',
templateFile: 'generator-templates/query/mock.hbs',
},
{
type: 'add',
path: 'src/types/formatted/{{camelCase name}}.ts',
templateFile: 'generator-templates/type/formatted.hbs',
},
// Strings can be added to print a comment in the terminal.
'You will need to do a few steps manually:',
'- Import & add your query to src/data/queries/index.ts',
'- Add your resource type to src/lib/constants/resourceTypes.ts',
'- Update the mock.json with correct data. See src/pages/_playgroud/api-explorer.tsx',
'- Run `yarn test:u` to update test snapshots for your new query!',
],
})
// Generate all files needed to render a new content type from Drupal.
// It also generates an additional test file for E2E testing the page via Playwright.
plop.setGenerator('Content Type', {
description: 'Generate boilerplate for new FE Page based on Content Type',
prompts: [
{
type: 'input',
name: 'name',
message: 'Page name please',
},
],
actions: [
// Create query files for new Page type.
{
type: 'add',
path: 'src/data/queries/{{camelCase name}}.ts',
templateFile: 'generator-templates/query/query.hbs',
},
{
type: 'add',
path: 'src/data/queries/tests/{{camelCase name}}.test.tsx',
templateFile: 'generator-templates/query/test.hbs',
},
{
type: 'add',
path: 'src/mocks/{{camelCase name}}.mock.json',
templateFile: 'generator-templates/query/mock.hbs',
},
{
type: 'add',
path: 'src/types/formatted/{{camelCase name}}.ts',
templateFile: 'generator-templates/type/formatted.hbs',
},
'You will need to do a few steps manually:',
'- Import & add your query to src/data/queries/index.ts',
'- Add your resource type to src/lib/constants/resourceTypes.ts',
'- Update the mock.json with correct data. See src/pages/_playgroud/api-explorer.tsx',
'- Run `yarn test:u` to update test snapshots for your new query!',
// Create react component + test files for new Page type.
{
type: 'add',
path: 'src/templates/layouts/{{camelCase name}}/index.tsx',
templateFile: 'generator-templates/component/index.hbs',
},
{
type: 'add',
path: 'src/templates/layouts/{{camelCase name}}/index.test.tsx',
templateFile: 'generator-templates/component/test.hbs',
},
{
type: 'add',
path: 'src/templates/layouts/{{camelCase name}}/{{camelCase name}}.stories.ts',
templateFile: 'generator-templates/component/story.hbs',
},
{
type: 'add',
path: 'playwright/tests/{{camelCase name}}.spec.js',
templateFile: 'generator-templates/component/playwright.hbs',
},
'To render your new page type, update [[...slug]].tsx',
],
})
// Add additional generators here
}