forked from falconmick/JSUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
130 lines (112 loc) · 2.94 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
module.exports = function(plop) {
/* Helpers */
plop.addHelper('upperCase', function(text) {
return text.toUpperCase();
});
var files = {
index: 'plop-templates/index.js',
story: 'plop-templates/stories.js',
indexConnected: 'plop-templates/index-connected.js',
styles: 'plop-templates/styles.js',
mstModel: 'plop-templates/mst-model.js',
dialog: {
index: 'plop-templates/Dialog/index.js',
style: 'plop-templates/Dialog/styles.js'
}
};
/* Files */
var createComponent = function(data) {
const isNested = data.nested && data.nested.trim() !== '';
const prefix = isNested
? 'src/components/{{pascalCase nested}}/components/{{pascalCase name}}/'
: 'src/components/{{pascalCase name}}/';
return [
{
type: 'add',
path: prefix + 'styles.js',
templateFile: files.styles
},
{
type: 'add',
path: prefix + 'index.js',
templateFile: files.index
},
{
type: 'add',
path: prefix + 'stories.js',
templateFile: files.story
}
];
};
var createViewStory = {
type: 'add',
path: 'src/views/{{pascalCase name}}/stories.js',
templateFile: files.story
};
/* Files */
var createView = {
type: 'add',
path: 'src/views/{{pascalCase name}}/index.js',
templateFile: files.index
};
var createDialog = {
type: 'add',
path: 'src/components/{{pascalCase name}}/index.js',
templateFile: files.dialog.index
};
var createDialogStyle = {
type: 'add',
path: 'src/components/{{pascalCase name}}/styles.js',
templateFile: files.dialog.style
};
var createMstModel = {
type: 'add',
path: 'src/models/{{pascalCase name}}.js',
templateFile: files.mstModel
};
var createViewStyle = {
type: 'add',
path: 'src/views/{{pascalCase name}}/styles.js',
templateFile: files.styles
};
/* Questions */
var getComponentName = {
type: 'input',
name: 'name',
message: 'Name?',
validate: function(value) {
if (/.+/.test(value)) {
return true;
}
return 'name is required';
}
};
var getNestedFolder = {
type: 'input',
name: 'nested',
message: 'Nest it in a folder?'
};
/* Options */
plop.setGenerator('Component', {
description: 'Generate a component',
prompts: [getComponentName, getNestedFolder],
actions: function(data) {
return createComponent(data);
}
});
plop.setGenerator('View', {
description: 'Generate a view component',
prompts: [getComponentName],
actions: [createView, createViewStyle, createViewStory]
});
plop.setGenerator('Dialog', {
description: 'Generate a dialog component',
prompts: [getComponentName],
actions: [createDialog, createDialogStyle]
});
plop.setGenerator('MST Model', {
description: 'Generate a mobx-state-tree model',
prompts: [getComponentName],
actions: [createMstModel]
});
};