-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
63 lines (57 loc) · 1.46 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
module.exports = function(plop) {
// create your generators here
plop.addHelper('splitOnCaps', splitOnCaps);
plop.setGenerator('component', {
description: 'this generates an entirely new component',
prompts: [
{
type: 'input',
name: 'name',
message: 'the name of the component (PascalCase, no Component at the end)',
validate: isPascalCased,
},
{
type: 'confirm',
name: 'isFetching',
message: 'Will the component fetch data over the network?',
},
],
actions: answers => {
const fetching = answers.isFetching ? '.fetching' : '';
return [
{
type: 'add',
path: 'src/components/{{dashCase name}}.ts',
templateFile: `templates/component${fetching}.hsb`,
},
{
type: 'modify',
path: 'src/index.ts',
pattern: /(import)/i,
template:
"import { {{camelCase name}}Component } from './components/{{dashCase name}}';\n$1",
},
{
type: 'modify',
path: 'src/index.ts',
pattern: /(\/\/log components)/i,
template: "$1\nconsole.log({{camelCase name}}Component('cool value'));",
},
() => `Component creation succesful!`,
];
},
});
};
/** Helper Functions */
const isPascalCased = input => {
if (isUpperCase(input.charAt(0))) {
return true;
}
return `string ${input} must be PascalCased.`;
};
const isUpperCase = myString => {
return myString === myString.toUpperCase();
};
const splitOnCaps = txt => {
return txt.split(/(?=[A-Z])/).join(' ');
};