-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplopfile.js
111 lines (106 loc) · 3.62 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
const data = require('./code-gen-templates/data-helper');
const config = (plop) => {
plop.setGenerator('Generic', {
description: 'Add a new empty component',
prompts: [{
type: 'input',
name: 'name',
message: 'Please provide component name, default :',
default: 'GenericComponent',
}],
actions: () => {
data.Temp = [];
return [{
type: 'add',
path: 'src/components/{{dashCase name}}/{{pascalCase name}}.vue',
templateFile: 'code-gen-templates/generic.hsb',
},
{
type: 'add',
path: 'src/components/{{dashCase name}}/doc.mdx',
templateFile: 'code-gen-templates/doc.hsb',
data,
},
{
type: 'add',
path: 'src/stories/{{pascalCase name}}.stories.js',
templateFile: 'code-gen-templates/story.hsb',
data: {
templateData: '{ message: \'Welcome !\' }',
},
},
{
type: 'add',
path: 'tests/unit/{{dashCase name}}.spec.js',
templateFile: 'code-gen-templates/test.hsb',
data,
}];
},
});
plop.setGenerator('Test', {
description: 'Add unit test for a component',
prompts: [{
type: 'input',
name: 'name',
message: 'Please provide component name, default :',
default: 'GenericComponent',
}],
actions: () => {
data.Temp = [];
return [{
type: 'add',
path: 'tests/unit/{{dashCase name}}.spec.js',
templateFile: 'code-gen-templates/test.hsb',
data,
}];
},
});
plop.setGenerator('Table', {
description: 'Add a new table component',
prompts: [{
type: 'input',
name: 'name',
message: 'Please provide component name, default :',
default: 'TableComponent',
},
{
type: 'input',
name: 'templateData',
message: 'Please provide model data, default :',
default: JSON.stringify(data.templateData),
}],
actions: [{
type: 'add',
path: 'src/components/{{dashCase name}}/{{pascalCase name}}.vue',
templateFile: 'code-gen-templates/table.hsb',
data,
},
{
type: 'add',
path: 'src/components/{{dashCase name}}/doc.mdx',
templateFile: 'code-gen-templates/doc.hsb',
data,
},
{
type: 'add',
path: 'src/stories/{{pascalCase name}}.stories.js',
templateFile: 'code-gen-templates/story.hsb',
data,
},
{
type: 'add',
path: 'tests/unit/{{dashCase name}}.spec.js',
templateFile: 'code-gen-templates/test.hsb',
data,
}],
});
plop.setHelper('wrapCurly', (text, parent) => `{{${parent}.${text}}}`);
plop.setHelper('titleCase', (text) => {
let result = text.replace(/([A-Z]{1,})/g, ' $1');
result = result.charAt(0).toUpperCase() + result.slice(1);
return result.trim();
});
plop.setHelper('parseObject', (text) => JSON.stringify(text));
plop.setHelper('lowerCase', (text) => text.toLowerCase());
};
module.exports = config;