-
Notifications
You must be signed in to change notification settings - Fork 13
/
plopfile.js
85 lines (76 loc) · 2.48 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
/* eslint-disable no-console */
const addToComponent = (filename, { path = '' } = {}) => {
const componentName = '{{pascalCase name}}';
const templatePath = path.replace('{{kebabCase name}}', 'name');
const nextFilename = filename.replace('Component', '{{pascalCase name}}');
return {
type: 'add',
path: `packages/flame/src/${componentName}/${path}${nextFilename}`,
templateFile: `scripts/plop/templates/component/${templatePath}${filename}.hbs`,
};
};
const addToAddon = (filename, { path = '' } = {}) => {
const packageName = 'flame-{{kebabCase name}}';
const templatePath = path.replace('{{kebabCase name}}', 'name');
const nextFilename = filename.replace('Component', '{{pascalCase name}}');
return {
type: 'add',
path: `packages/${packageName}/${path}${nextFilename}`,
templateFile: `scripts/plop/templates/addon/${templatePath}${filename}.hbs`,
};
};
const exitMessage = answers => {
const { name } = answers;
console.log(
`We gucci, folks. Next steps:\n\n`,
`1. Run \`yarn dev\`\n`,
`2. Open Storybook on http://localhost:6006 and go to the ${name} Story to start developing 🎉\n`,
);
return '';
};
module.exports = plop => {
plop.setActionType('exitMessage', exitMessage);
plop.addHelper('currentYear', () => new Date().getFullYear());
plop.setGenerator('Mainline component', {
description: 'Create a new mainline component',
prompts: [
{
type: 'input',
name: 'name',
message: 'Enter component name',
default: 'Component',
},
],
actions: [
addToComponent('Component.test.tsx', { path: '__tests__/' }),
addToComponent('Component.tsx'),
addToComponent('index.tsx'),
addToComponent('README.md'),
addToComponent('story.tsx'),
{ type: 'exitMessage' },
],
});
plop.setGenerator('Add-on component', {
description: 'Create a new add-on/experimental component',
prompts: [
{
type: 'input',
name: 'name',
message: 'Enter component name',
default: 'Component',
},
],
actions: [
addToAddon('Component.test.tsx', { path: 'src/__tests__/' }),
addToAddon('Component.tsx', { path: 'src/' }),
addToAddon('index.tsx', { path: 'src/' }),
addToAddon('CHANGELOG.md'),
addToAddon('LICENSE'),
addToAddon('package.json'),
addToAddon('README.md'),
addToAddon('story.tsx'),
addToAddon('tsconfig.types.json'),
{ type: 'exitMessage' },
],
});
};