-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.cjs
62 lines (59 loc) · 1.6 KB
/
plopfile.cjs
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
const COMPONENT_TYPES = ['component', 'layout', 'page']
const requireField = (fieldName) => {
return (value) => {
if (String(value).length === 0) return `${fieldName} is required`
return true
}
}
module.exports = (plop) => {
// Component
plop.setGenerator('component', {
description: 'Create a component',
prompts: [
{
type: 'list',
choices: COMPONENT_TYPES,
name: 'type',
message: 'What is your component type?',
validate: requireField('type')
},
{
type: 'input',
name: 'name',
message: 'What is your component name?',
validate: requireField('name')
}
],
actions: [
{
type: 'add',
path: 'src/{{camelCase type}}s/{{pascalCase name}}/{{pascalCase name}}.tsx',
templateFile:
'plop/component/component.hbs'
},
{
type: 'add',
path: 'src/{{camelCase type}}s/{{pascalCase name}}/{{pascalCase name}}.test.tsx',
templateFile:
'plop/component/component.test.hbs'
},
{
type: 'add',
path: 'src/{{camelCase type}}s/{{pascalCase name}}/index.ts',
templateFile: 'plop/component/index.hbs'
},
{
type: 'add',
path: 'src/{{camelCase type}}s/index.ts',
templateFile: 'plop/injectableIndex.hbs',
skipIfExists: true
},
{
type: 'append',
path: 'src/{{camelCase type}}s/index.ts',
pattern: '/* PLOP_INJECT_EXPORT */',
template: 'export { default as {{pascalCase name}} } from \'./{{pascalCase name}}\''
}
]
})
}