-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplopfile.js
110 lines (110 loc) · 2.95 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
/* eslint-disable func-names */
module.exports = function (plop) {
// paths
const path = 'src/containers/{{classname}}';
const reducerPath = 'src/containers/{{classname}}/store';
const viewsPath = 'src/containers/{{classname}}/views';
const testPath = 'src/containers/{{classname}}/__test__/{{classname}}.test.js';
const componentPath = 'src/components/{{componentname}}/index.js';
const componentTestPath = 'src/components/{{componentname}}/__test__/{{componentname}}.test.js';
// block generator
plop.setGenerator('Create New Pages', {
description: 'Generate class for pages',
prompts: [
{
type: 'input',
name: 'classname',
message: 'Your Class Name',
},
{
type: 'input',
name: 'reducer',
message: 'Your Reducer Name',
},
],
actions: [
// import file
{
type: 'add',
path: `${path}/index.js`,
templateFile: 'templates/exportPage.hbs',
},
{
type: 'add',
path: `${reducerPath}/actions.js`,
templateFile: 'templates/actions.hbs',
},
{
type: 'add',
path: `${reducerPath}/constants.js`,
templateFile: 'templates/constants.hbs',
},
{
type: 'add',
path: `${reducerPath}/reducer.js`,
templateFile: 'templates/reducer.hbs',
},
{
type: 'add',
path: `${viewsPath}/{{classname}}.scss`,
templateFile: 'templates/Style.hbs',
},
{
type: 'add',
path: `${viewsPath}/index.js`,
templateFile: 'templates/Page.hbs',
},
{
type: 'add',
path: `${testPath}`,
templateFile: 'templates/test.hbs',
},
{
path: 'src/store/reducers.js',
pattern: /(\/\/ REDUCERIMPORT)/g,
template: `import {{reducer}} from 'containers/{{classname}}/store/reducer';\n$1`,
type: 'modify',
},
{
path: 'src/store/reducers.js',
pattern: /(\/\/ COMBINEREDUCER)/g,
template: `{{reducer}},\n$1`,
type: 'modify',
},
],
});
plop.setGenerator('Create New Components', {
description: 'Generate class for pages',
prompts: [
{
type: 'input',
name: 'componentname',
message: 'Your Component Name',
},
],
actions: [
{
type: 'add',
path: `${componentPath}`,
templateFile: 'templates/Component.hbs',
},
{
type: 'add',
path: `${componentTestPath}`,
templateFile: 'templates/componentTest.hbs',
},
{
path: 'src/components/index.js',
pattern: /(\/\/ IMPORTCOMPONENT)/g,
template: `import {{componentname}}Component from './{{componentname}}';\n$1`,
type: 'modify',
},
{
path: 'src/components/index.js',
pattern: /(\/\/ EXPORTCOMPONENT)/g,
template: `{{componentname}}Component,\n$1`,
type: 'modify',
},
],
});
};