-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathplopfile.js
141 lines (135 loc) · 4.37 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* eslint-disable unicorn/better-regex */
const { execSync } = require('child_process');
module.exports = (plop) => {
plop.setHelper('userFullName', () => {
const name = execSync('git config --global --includes user.name').toString();
return name.replace(/\n$/, '').trim();
});
plop.setHelper('userEmail', () => {
const email = execSync('git config --global --includes user.email').toString();
return email.replace(/\n$/, '').trim();
});
plop.setGenerator('package', {
description: 'Create new package in monorepo',
prompts: [
{
type: 'input',
name: 'packageName',
message: 'package name',
},
{
type: 'input',
name: 'packageDescription',
message: 'package description',
},
],
actions: [
{
type: 'add',
path: 'packages/{{kebabCase packageName}}/src/{{kebabCase packageName}}.js',
templateFile: 'plop-templates/library/main.js.hbs',
},
{
type: 'add',
path: 'packages/{{kebabCase packageName}}/tests/{{kebabCase packageName}}.test.js',
templateFile: 'plop-templates/library/main.test.js.hbs',
},
{
type: 'add',
path: 'packages/{{kebabCase packageName}}/package.json',
templateFile: 'plop-templates/library/package.json.hbs',
},
{
type: 'add',
path: 'packages/{{kebabCase packageName}}/README.md',
templateFile: 'plop-templates/library/README.md.hbs',
},
],
});
plop.setGenerator('api resource', {
description: 'Create new api resource',
prompts: [
{
type: 'input',
name: 'resourceName',
message: 'resource name',
},
{
type: 'confirm',
name: 'isMicroservice',
message: 'Is this resource for a microservice?',
default: false,
},
],
actions: (data) => {
const actions = [
{
type: 'add',
path: 'packages/api-axios/src/{{camelCase resourceName}}.js',
templateFile: 'plop-templates/resource/api-axios-resource.js.hbs',
},
{
type: 'add',
path: 'packages/api-axios/src/resources/tests/{{camelCase resourceName}}.test.js',
templateFile: 'plop-templates/resource/api-axios-test.js.hbs',
},
{
type: 'append',
path: 'packages/api-axios/src/index.js',
pattern: "import AvMicroserviceApi from './ms';",
template: "import Av{{pascalCase resourceName}} from './resources/{{camelCase resourceName}}';",
},
{
type: 'append',
path: 'packages/api-axios/src/index.js',
pattern: "import AvProxyApi from './proxy';",
template: "import av{{pascalCase resourceName}}Api from './{{camelCase resourceName}}';",
},
{
type: 'append',
path: 'packages/api-axios/src/index.js',
pattern: 'AvProxyApi,',
template: ' av{{pascalCase resourceName}}Api,',
},
{
type: 'append',
path: 'packages/api-axios/README.md',
pattern: '- `AvProxyApi`',
template: '- `av{{pascalCase resourceName}}Api`',
},
{
type: 'append',
path: 'packages/api-axios/README.md',
pattern: ' AvProxyApi,',
template: ' av{{pascalCase resourceName}}Api,',
},
{
type: 'append',
path: 'packages/api-axios/src/tests/api.test.js',
pattern: 'AvProxyApi,',
template: ' av{{pascalCase resourceName}}Api,',
},
{
type: 'append',
path: 'packages/api-axios/src/tests/api.test.js',
pattern: /describe\('API Definitions', \(\) => \{\n.*test\('should be defined', \(\) => \{/,
template: ' expect(av{{pascalCase resourceName}}Api).toBeDefined();',
},
];
if (data.isMicroservice) {
actions.push({
type: 'add',
path: 'packages/api-axios/src/resources/{{camelCase resourceName}}.js',
templateFile: 'plop-templates/resource/api-axios-ms-resource.js.hbs',
});
} else {
actions.push({
type: 'add',
path: 'packages/api-axios/src/resources/{{camelCase resourceName}}.js',
templateFile: 'plop-templates/resource/api-axios-resource.js.hbs',
});
}
return actions;
},
});
};