-
Notifications
You must be signed in to change notification settings - Fork 23
/
plopfile.js
90 lines (84 loc) · 2.91 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
module.exports = (
/** @type {import('plop').NodePlopAPI} */
plop,
) => {
plop.setHelper('preCurly', (t) => `{${t}`)
plop.setGenerator('basic component', {
description: 'Generate a basic component',
prompts: [
{
type: 'input',
name: 'componentName',
message: 'What is the component name?',
},
{
type: 'confirm',
name: 'isSubcomponent',
message: 'Is this a subcomponent?',
default: false,
},
{
type: 'input',
name: 'parentComponentName',
message: 'What is the parent component name?',
when: (answers) => answers.isSubcomponent,
},
{
type: 'confirm',
name: 'isFuture',
message: 'Is this a future component?',
default: false,
},
],
actions: ({ isSubcomponent, isFuture, componentName, parentComponentName }) => {
const src = isFuture ? 'src/__future__' : 'src'
const componentNamePascal = plop.getHelper('pascalCase')(componentName)
if (isSubcomponent) {
const parentComponentNamePascal = plop.getHelper('pascalCase')(parentComponentName)
return [
{
type: 'addMany',
destination: `packages/components/${src}/{{pascalCase parentComponentName}}/subcomponents/{{pascalCase componentName}}`,
base: 'plop-templates/basic-component/src',
templateFiles: 'plop-templates/basic-component/src/**/*.hbs',
},
{
type: 'addMany',
destination: `packages/components/${src}/{{pascalCase parentComponentName}}/subcomponents/{{pascalCase componentName}}/_docs`,
base: 'plop-templates/basic-component/docs',
templateFiles: 'plop-templates/basic-component/docs/**/!(*.mdx.hbs)',
data: {
storyTitle: `Components/${parentComponentNamePascal}/${componentNamePascal}`,
},
},
]
}
return [
{
type: 'addMany',
destination: `packages/components/${src}/{{pascalCase componentName}}`,
base: 'plop-templates/basic-component/src',
templateFiles: 'plop-templates/basic-component/src/**/*.hbs',
},
{
type: 'addMany',
destination: `packages/components/${src}/{{pascalCase componentName}}/_docs`,
base: 'plop-templates/basic-component/docs',
templateFiles: 'plop-templates/basic-component/docs/**/*.hbs',
data: {
storyTitle: `Components/${componentNamePascal}`,
},
},
{
type: 'modify',
path: `packages/components/${src}/index.ts`,
transform: (content) => {
const exportStatement = `export * from "./${componentNamePascal}"`
if (content.includes(exportStatement)) return content
return `${content.trim()}\n${exportStatement}\n`
},
},
]
},
})
}