-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplopfile.js
87 lines (84 loc) · 2.38 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
module.exports = (plop) => {
plop.setGenerator('component', {
description: 'Generate a new component',
prompts: [{
type: 'input',
name: 'name',
message: 'Name of the component',
},
{
type: 'confirm',
name: 'addJS',
message: 'Add a JS class?',
default: false,
},
],
actions: (data) => {
const actions = [{
type: 'add',
path: 'src/components/{{dashCase name}}/{{dashCase name}}.hbs',
templateFile: 'plop-templates/component.hbs.hbs',
},
{
type: 'add',
path: 'src/components/{{dashCase name}}/{{dashCase name}}.scss',
templateFile: 'plop-templates/component.scss.hbs',
},
{
type: 'modify',
path: 'src/index.scss',
pattern: /(@import .*\.scss";)/s,
template: '$1\r\n@import "./components/{{dashCase name}}/{{dashCase name}}.scss";',
}];
if (data.addJS) {
actions.push(
{
type: 'add',
path: 'src/components/{{dashCase name}}/{{dashCase name}}.js',
templateFile: 'plop-templates/component.js.hbs',
},
{
type: 'modify',
path: 'src/index.js',
pattern: /(import .*";)/s,
template: '$1\r\nimport { {{properCase name}} } from "./components/{{dashCase name}}/{{dashCase name}}.js";',
},
{
type: 'modify',
path: 'src/index.js',
pattern: /(setupComponents\(\[(\{.*\})*)\]/s,
templateFile: 'plop-templates/js.snippet.hbs',
},
);
}
return actions;
},
});
plop.setGenerator('component class', {
description: 'Generate a new class for a existing component',
prompts: [{
type: 'input',
name: 'name',
message: 'Name of the component',
},
],
actions: [{
type: 'add',
path: 'src/components/{{dashCase name}}/{{dashCase name}}.js',
templateFile: 'plop-templates/component.js.hbs',
},
{
type: 'modify',
path: 'src/index.js',
pattern: /(import .*";)/s,
template: '$1\r\nimport { {{properCase name}} } from "./components/{{dashCase name}}/{{dashCase name}}.js";',
},
{
type: 'modify',
path: 'src/index.js',
pattern: /(setupComponents\(\[(\{.*\})*)\]/s,
templateFile: 'plop-templates/js.snippet.hbs',
},
],
});
};