-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
65 lines (64 loc) · 1.9 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
module.exports = plop => {
console.log('Plop');
plop.addHelper('dash-case', text => {
const [head, ...tail] = text;
return (
head.toLowerCase() +
tail.join('').replace(/[A-Z]/g, m => `-${m.toLowerCase()}`)
);
});
plop.addHelper('camelCase', text => {
const [head, ...tail] = text;
return head.toLowerCase() + tail.join('');
});
plop.setGenerator('actions', {
description: 'Generate file types',
prompts: [
{
type: 'input',
name: 'componentName',
message:
'What shall we name this component? Exclude extension, PascalCase (MyComponent).',
},
],
actions: () => {
const actions = [];
actions.push({
type: 'add',
path: 'src/lib/{{componentName}}/{{componentName}}.jsx',
templateFile: 'plop-templates/Component.hbs',
});
actions.push({
type: 'add',
path: 'src/lib/{{componentName}}/{{componentName}}.test.jsx',
templateFile: 'plop-templates/Component.test.hbs',
});
actions.push({
type: 'add',
path: 'src/documentation/components/{{componentName}}.mdx',
templateFile: 'plop-templates/Component.mdx.hbs',
});
actions.push({
type: 'add',
path:
'src/lib/{{componentName}}/{{camelCase componentName}}.module.scss',
templateFile: 'plop-templates/scss.module.hbs',
});
actions.push({
type: 'modify',
path: 'src/CHANGELOG.mdx',
pattern: '# Changelog',
template:
'# Changelog\n\n#### [v. TODO]\n\n- Init `<{{componentName}}/>`\n\n_TODO_',
});
actions.push({
type: 'modify',
path: 'src/lib/index.js',
pattern: '\nexport {',
template:
"import {{componentName}} from './{{componentName}}/{{componentName}}';\n\nexport {\n {{componentName}},",
});
return actions;
},
});
};