-
Notifications
You must be signed in to change notification settings - Fork 46
/
plopfile.js
90 lines (89 loc) · 3.04 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
const { kebabCase } = require('lodash');
module.exports = 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 => {
return g[1].toUpperCase();
});
camel[0] = camel[0].toUpperCase();
const capitalized = camel.charAt(0).toUpperCase() + camel.substring(1);
return `UUI${capitalized}Element`;
});
// uui-base version
plop.setHelper('uuiBaseVersion', function () {
const basePackageJson = require('./packages/uui-base/package.json');
return basePackageJson.version;
});
// name used as title in storybook and documentation
plop.setHelper('displayName', function (name) {
const camel = name.replace(/-([a-z])/g, g => {
return ` ${g[1].toUpperCase()}`;
});
camel[0] = camel[0].toUpperCase();
const capitalized = camel.charAt(0).toUpperCase() + camel.substring(1);
return capitalized;
});
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: './packages/{{> tagnamePartial }}/lib/index.ts',
templateFile: './templates/plop-templates/index.ts.hbs',
},
{
type: 'add',
path: './packages/{{> tagnamePartial }}/lib/{{> tagnamePartial }}.element.ts',
templateFile: './templates/plop-templates/component.ts.hbs',
},
{
type: 'add',
path: './packages/{{> tagnamePartial }}/lib/{{> tagnamePartial }}.test.ts',
templateFile: './templates/plop-templates/test.ts.hbs',
},
{
type: 'add',
path: './packages/{{> tagnamePartial }}/lib/{{> tagnamePartial }}.story.ts',
templateFile: './templates/plop-templates/stories.ts.hbs',
},
{
type: 'add',
path: './packages/{{> tagnamePartial }}/README.md',
templateFile: './templates/plop-templates/README.md.hbs',
},
{
type: 'add',
path: './packages/{{> tagnamePartial }}/rollup.config.js',
templateFile: './templates/plop-templates/rollup.config.hbs',
},
{
type: 'add',
path: './packages/{{> tagnamePartial }}/package.json',
templateFile: './templates/plop-templates/package.json.hbs',
},
{
type: 'append',
path: './packages/uui/lib/index.ts',
template:
"export * from '@umbraco-ui/{{> tagnamePartial }}/lib/index.js';",
},
],
});
};