-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplopfile.js
75 lines (72 loc) · 2.03 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
const capitalize = str => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
const camelCase = str => {
return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
};
module.exports = plop => {
plop.setHelper('capitalize', text => {
return capitalize(camelCase(text));
});
plop.setGenerator('component', {
description: 'Add a new component',
prompts: [
{
type: 'input',
name: 'name',
message: 'Enter component name:',
},
{
type: 'input',
name: 'description',
message: 'The description of this component:',
},
],
actions: [
{
type: 'add',
templateFile: 'plop-templates/component/component.tsx.hbs',
path: `packages/react/src/{{dashCase name}}/{{capitalize name}}.tsx`,
},
{
type: 'add',
templateFile: 'plop-templates/component/index.ts.hbs',
path: `packages/react/src/{{dashCase name}}/index.ts`,
},
{
type: 'add',
templateFile: 'plop-templates/component/doc.mdx.hbs',
path: `apps/docs/src/content/docs/components/{{dashCase name}}.mdx`,
},
{
type: 'add',
templateFile: 'plop-templates/component/snippets.ts.hbs',
path: `apps/docs/src/components/configs/{{dashCase name}}.ts`,
},
{
type: 'add',
templateFile: 'plop-templates/component/theme.ts.hbs',
path: `packages/themes/src/{{dashCase name}}.ts`,
},
{
type: 'modify',
path: './packages/react/src/index.ts',
pattern: /(\/\/ ADD NEW COMPONENTS EXPORTS HERE)/g,
template: "export * from './{{dashCase name}}';\n// ADD NEW COMPONENTS EXPORTS HERE",
},
{
type: 'modify',
path: './apps/docs/src/constants.ts',
pattern: /(\/\/ INJECT NEW COMPONENTS HERE)/g,
template:
"{ title: '{{capitalize name}}', href: '/docs/components/{{dashCase name}}', status: 'New' },\n\t\t\t// INJECT NEW COMPONENTS HERE",
},
{
type: 'modify',
path: './packages/themes/src/index.ts',
pattern: /(\/\/ ADD NEW COMPONENTS EXPORTS HERE)/g,
template: "export * from './{{dashCase name}}';\n// ADD NEW COMPONENTS EXPORTS HERE",
},
],
});
};