forked from Availity/sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plopfile.js
187 lines (181 loc) · 5.8 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
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}}/{{kebabCase packageName}}.js',
templateFile: 'plop-templates/library/main.js.hbs',
},
{
type: 'add',
path:
'packages/{{kebabCase packageName}}/{{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-angular/src/{{camelCase resourceName}}.js',
templateFile: 'plop-templates/resource/api-angular-resource.js.hbs',
},
{
type: 'add',
path: 'packages/api-axios/src/{{camelCase resourceName}}.js',
templateFile: 'plop-templates/resource/api-axios-resource.js.hbs',
},
{
type: 'add',
path:
'packages/api-core/src/resources/tests/{{camelCase resourceName}}.test.js',
templateFile: 'plop-templates/resource/api-core-test.js.hbs',
},
{
type: 'append',
path: 'packages/api-core/src/index.js',
pattern: "import AvMicroservice from './ms';",
template:
"import Av{{pascalCase resourceName}} from './resources/{{camelCase resourceName}}';",
},
{
type: 'append',
path: 'packages/api-core/src/index.js',
pattern: 'export {',
template: ' Av{{pascalCase 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-angular/src/index.js',
pattern: "import AvProxyApiFactory from './proxy';",
template:
"import av{{pascalCase resourceName}}ApiFactory from './{{camelCase resourceName}}';",
},
{
type: 'append',
path: 'packages/api-angular/src/index.js',
pattern: ".factory('AvProxyApi', AvProxyApiFactory)",
template:
" .factory('av{{pascalCase resourceName}}Api', av{{pascalCase resourceName}}ApiFactory)",
},
{
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-angular/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();',
},
{
type: 'append',
path: 'packages/api-angular/src/tests/api.test.js',
pattern: /beforeEach\(\(\) => \{\n.*angular\.mock\.module\(avModule\);\n.*\}\);/,
templateFile: 'plop-templates/resource/test-api-angular.hbs',
separator: '\n\n',
},
];
if (data.isMicroservice) {
actions.push({
type: 'add',
path: 'packages/api-core/src/resources/{{camelCase resourceName}}.js',
templateFile: 'plop-templates/resource/api-core-ms-resource.js.hbs',
});
} else {
actions.push({
type: 'add',
path: 'packages/api-core/src/resources/{{camelCase resourceName}}.js',
templateFile: 'plop-templates/resource/api-core-resource.js.hbs',
});
}
return actions;
},
});
};