-
Notifications
You must be signed in to change notification settings - Fork 3
/
plopfile.js
117 lines (115 loc) · 3.36 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
// @flow
// eslint-disable-next-line cup/no-undef
module.exports = function(plop) {
// page generator
plop.setGenerator('Generate Component', {
description: 'react functional atomic design component generator',
prompts: [
{
type: 'list',
name: 'componentType',
choices: ['atom', 'organism', 'molecule'],
message: 'Select component type',
},
{
type: 'input',
name: 'name',
message: 'component name',
},
],
actions: () => {
return [
{
type: 'add',
path: 'src/components/{{componentType}}s/{{kebabCase name}}/index.js',
templateFile: 'plop-templates/component/index.js.hbs',
abortOnFail: true,
},
{
type: 'add',
path:
'src/components/{{componentType}}s/{{kebabCase name}}/{{kebabCase name}}.story.js',
templateFile: 'plop-templates/component/componentName.story.js.hbs',
abortOnFail: true,
},
{
type: 'add',
path:
'src/components/{{componentType}}s/{{kebabCase name}}/__tests__/{{kebabCase name}}.node.js',
templateFile: 'plop-templates/component/componentName.node.js.hbs',
abortOnFail: true,
},
{
type: 'append',
path: 'src/components/{{componentType}}s/index.js',
template: "export * from './{{kebabCase name}}';",
},
];
},
});
// page generator
plop.setGenerator('Generate Page', {
description: 'react functional page generator',
prompts: [
{
type: 'input',
name: 'name',
message: 'Enter page name please',
},
{
type: 'input',
name: 'subPath',
message:
'Optional: sub path in page you want this file to be generated in example /auth/others. Note it must start with a leading slash and end with none',
},
],
actions: ({subPath}) => {
let newPath = '../';
if (subPath) {
console.log('subPath', subPath)
const d = subPath.split('/');
for (let i = 0; i < d.length; i++) {
if (d[i].length > 0) {
newPath = newPath.concat('../');
}
}
console.log('newPath', newPath);
}
return [
{
type: 'add',
path: 'src/pages{{subPath}}/{{kebabCase name}}.page.js',
templateFile: 'plop-templates/pages/pageName.page.js.hbs',
data: {
newPath,
},
abortOnFail: true,
},
{
type: 'add',
path: 'src/content/{{kebabCase name}}/index.js',
templateFile: 'plop-templates/content/index.js.hbs',
abortOnFail: true,
},
{
type: 'add',
path: 'src/content/{{kebabCase name}}/{{kebabCase name}}.content.js',
templateFile: 'plop-templates/content/contentName.content.js.hbs',
abortOnFail: true,
},
{
type: 'add',
path:
'src/content/{{kebabCase name}}/__tests__/{{kebabCase name}}-content.node.js',
templateFile: 'plop-templates/content/contentName.node.js.hbs',
abortOnFail: true,
},
{
type: 'append',
path: 'src/content/index.js',
template: "export * from './{{kebabCase name}}';",
},
];
},
});
};