-
Notifications
You must be signed in to change notification settings - Fork 8
/
plopfile.js
142 lines (129 loc) · 2.98 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
140
141
142
const modulePath = "pages/{{camelCase name}}.js";
const SRC_PATH = './';
const ns = 'px-';
const COMP_SRC = './src/components/px';
/**
helpers
camelCase: changeFormatToThis
snakeCase: change_format_to_this
dashCase/kebabCase: change-format-to-this
dotCase: change.format.to.this
pathCase: change/format/to/this
properCase/pascalCase: ChangeFormatToThis
lowerCase: change format to this
sentenceCase: Change format to this,
constantCase: CHANGE_FORMAT_TO_THIS
titleCase: Change Format To This
pkg: look up a property from a package.json file in the same folder as the plopfile.
*/
module.exports = function(plop) {
const ACTIONS = {
ADD_COMPONENT: {
type: "add",
path: COMP_SRC + "/{{dashCase name}}/index.js",
templateFile: "plop-templates/component.tmpl.js"
}
};
plop.addHelper("upperCase", function(text) {
return text.toUpperCase();
});
plop.addHelper('unprefixedName', function(text) {
return text.replace(ns, '');
});
//component
plop.setGenerator("component", {
description: "Create a new React Component",
prompts: [
{
type: "input",
name: "name",
message: "What is the name?"
}
],
actions: [
//component
ACTIONS.ADD_COMPONENT,
//scss styles
/*
{
type: "add",
path: COMP_SRC + "/{{dashCase name}}/styles/index.scss",
templateFile: "plop-templates/component.tmpl.scss"
},
*/
//test
{
type: "add",
path: COMP_SRC +"/{{dashCase name}}/index.test.js",
templateFile: "plop-templates/component.test.tmpl.js"
},
//readme
{
type: "add",
path: COMP_SRC +"/{{dashCase name}}/README.md",
templateFile: "plop-templates/component.tmpl.md"
}
]
});
//Test spec
plop.setGenerator("test", {
description: "Create a new React Test",
prompts: [
{
type: "input",
name: "name",
message: "What is the name?"
}
],
actions: [
{
type: "add",
//path: "__tests__/components/{{dashCase name}}.test.js",
path: "src/{{dashCase name}}/{{dashCase name}}.test.js",
templateFile: "plop-templates/component.test.tmpl.js"
}
]
});
//Readme
plop.setGenerator('readme', {
description: 'Create a new component README.md',
prompts: [
{
type: "input",
name: "name",
message: "What is the name?"
}
],
actions: [
{
type: "add",
path: "src/{{dashCase name}}/README.md",
templateFile: "plop-templates/component.tmpl.md"
}
]
});
//Batch create
plop.setGenerator('batch-test', {
description: 'Create a bunch of tests',
prompts: [
{
type: "input",
name: "names",
message: "What are the names?"
}
],
actions: function(data) {
var files = data.names.split(',');
console.log('create', files);
var actions = [];
actions.push({
type: "add",
path: "src/{{dashCase name}}/{{dashCase name}}.test.js",
templateFile: "plop-templates/component.test.tmpl.js"
});
return actions;
}
});
//const generators = plop.getGeneratorList();
//console.log('registered generators', generators);
};