-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathplopfile.js
More file actions
70 lines (69 loc) · 2.29 KB
/
plopfile.js
File metadata and controls
70 lines (69 loc) · 2.29 KB
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
const kebabCase = str =>
str
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/[\s_]+/g, '-')
.toLowerCase();
export default function (plop) {
// name of custom element tag
plop.setPartial('tagnamePartial', 'uui-{{name}}');
// name of LitElement class
plop.setHelper('className', function (name) {
const camel = name.replace(/-([a-z])/g, g => g[1].toUpperCase());
return `UUI${camel.charAt(0).toUpperCase() + camel.substring(1)}Element`;
});
// name used as title in storybook and documentation
plop.setHelper('displayName', function (name) {
const spaced = name.replace(/-([a-z])/g, g => ` ${g[1].toUpperCase()}`);
return spaced.charAt(0).toUpperCase() + spaced.substring(1);
});
plop.setGenerator('component', {
description: 'application controller logic',
prompts: [
{
type: 'input',
name: 'name',
message:
'UUI element name (i.e. color-area). uui- prefix will be added automatically',
validate: answer => {
if (answer.length < 1) {
return "There is no way we're moving forward without a name for your component.";
} else return true;
},
// Convert the input into kebab case if not provided as such and strip prefix
filter: response => kebabCase(response.replace(/^uui-/, '')),
},
],
actions: [
{
type: 'add',
path: './src/components/{{name}}/{{name}}.ts',
templateFile: './templates/plop-templates/index.ts.hbs',
},
{
type: 'add',
path: './src/components/{{name}}/{{name}}.element.ts',
templateFile: './templates/plop-templates/component.ts.hbs',
},
{
type: 'add',
path: './src/components/{{name}}/{{name}}.test.ts',
templateFile: './templates/plop-templates/test.ts.hbs',
},
{
type: 'add',
path: './src/components/{{name}}/{{name}}.story.ts',
templateFile: './templates/plop-templates/stories.ts.hbs',
},
{
type: 'add',
path: './src/components/{{name}}/README.md',
templateFile: './templates/plop-templates/README.md.hbs',
},
{
type: 'append',
path: './src/components/index.ts',
template: "export * from './{{name}}/{{name}}.js';",
},
],
});
}