@pega/dx-component-builder-sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli.js +6 -0
- package/src/constants.js +366 -0
- package/src/tasks/authenticate/index.js +3 -1
- package/src/tasks/build/helper.js +46 -66
- package/src/tasks/build/index.js +16 -6
- package/src/tasks/bundle/index.js +2 -2
- package/src/tasks/create/index.js +3 -7
- package/src/tasks/delete/helper.js +47 -6
- package/src/tasks/delete/index.js +19 -6
- package/src/tasks/delete-all/helper.js +47 -7
- package/src/tasks/delete-all/index.js +16 -4
- package/src/tasks/index.js +1 -0
- package/src/tasks/list/helper.js +36 -5
- package/src/tasks/list/index.js +20 -6
- package/src/tasks/map/map.js +3 -1
- package/src/tasks/override/index.js +208 -0
- package/src/tasks/publish/index.js +3 -1
- package/src/tasks/publish-all/index.js +5 -2
- package/src/tasks/validator/index.js +20 -3
- package/src/util.js +212 -50
|
@@ -169,7 +169,7 @@ const validateSchema = ajv.compile(schema);
|
|
|
169
169
|
|
|
170
170
|
|
|
171
171
|
|
|
172
|
-
export default async option => {
|
|
172
|
+
export default async (option, category = "custom") => {
|
|
173
173
|
let componentToValidate = null;
|
|
174
174
|
if (option.params && option.params[3]) {
|
|
175
175
|
componentToValidate = option.params[3];
|
|
@@ -189,9 +189,26 @@ export default async option => {
|
|
|
189
189
|
componentToValidate = option;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
const componentDirectory = await getComponentDirectoryPath(componentToValidate);
|
|
192
|
+
const componentDirectory = await getComponentDirectoryPath(componentToValidate, category);
|
|
193
193
|
const configFile = path.join(componentDirectory, 'config.json');
|
|
194
|
-
|
|
194
|
+
let configData;
|
|
195
|
+
try {
|
|
196
|
+
configData = fs.readFileSync(path.resolve(configFile), 'utf8');
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
if (category == "custom") {
|
|
200
|
+
throw new Error(`Missing config file for: ${componentToValidate}`);
|
|
201
|
+
}
|
|
202
|
+
else if (category == "override") {
|
|
203
|
+
// for now, if now file just end
|
|
204
|
+
console.log(`${chalk.bold.yellow('config file not availabe for: ' + componentToValidate)}`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
//const data = JSON.parse(fs.readFileSync(path.resolve(configFile), 'utf8'));
|
|
210
|
+
const data = JSON.parse(configData);
|
|
211
|
+
|
|
195
212
|
const valid = validateSchema(data);
|
|
196
213
|
|
|
197
214
|
if (valid) {
|
package/src/util.js
CHANGED
|
@@ -3,6 +3,8 @@ import { join } from 'path';
|
|
|
3
3
|
import { promisify } from 'util';
|
|
4
4
|
import https from 'https';
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
import { URL, fileURLToPath } from 'url';
|
|
6
8
|
|
|
7
9
|
import chalk from 'chalk';
|
|
8
10
|
import mustache from 'mustache';
|
|
@@ -20,11 +22,23 @@ import {
|
|
|
20
22
|
FIELD_PATH,
|
|
21
23
|
WIDGET_PATH,
|
|
22
24
|
TEMPLATE_PATH,
|
|
25
|
+
FORMS_PATH,
|
|
26
|
+
TEMPLATES_PATH,
|
|
27
|
+
WIDGETS_PATH,
|
|
28
|
+
DSE_PATH,
|
|
29
|
+
INFRA_PATH,
|
|
23
30
|
COMPONENT_PREFIX_FIELD_PATH,
|
|
24
31
|
COMPONENT_PREFIX_TEMPLATE_PATH,
|
|
25
|
-
COMPONENT_PREFIX_WIDGET_PATH
|
|
32
|
+
COMPONENT_PREFIX_WIDGET_PATH,
|
|
33
|
+
COMPONENT_PREFIX_FORMS_PATH,
|
|
34
|
+
COMPONENT_PREFIX_TEMPLATES_PATH,
|
|
35
|
+
COMPONENT_PREFIX_WIDGETS_PATH,
|
|
36
|
+
COMPONENT_PREFIX_DSE_PATH,
|
|
37
|
+
COMPONENT_PREFIX_INFRA_PATH
|
|
26
38
|
} from './constants.js';
|
|
27
39
|
|
|
40
|
+
|
|
41
|
+
|
|
28
42
|
const access = promisify(fs.access);
|
|
29
43
|
|
|
30
44
|
export const checkPathAccess = async (path, options = {}) => {
|
|
@@ -59,12 +73,15 @@ export const deleteLocalComponent = async (componentKey, category = "custom") =>
|
|
|
59
73
|
|
|
60
74
|
const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
|
|
61
75
|
|
|
62
|
-
fs.rmdir(directory, { recursive: true }, err => {
|
|
76
|
+
//fs.rmdir(directory, { recursive: true }, err => {
|
|
77
|
+
fs.rm(directory, { recursive: true }, err => {
|
|
63
78
|
if (err) {
|
|
64
79
|
throw err;
|
|
65
80
|
}
|
|
66
81
|
|
|
67
82
|
console.log(`${chalk.red.bold(componentKey)} is deleted from Local`);
|
|
83
|
+
|
|
84
|
+
|
|
68
85
|
});
|
|
69
86
|
};
|
|
70
87
|
|
|
@@ -122,29 +139,71 @@ export const getComponents = async (showSeparator = false, category = "custom")
|
|
|
122
139
|
process.exit(1);
|
|
123
140
|
}
|
|
124
141
|
|
|
142
|
+
|
|
125
143
|
const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory);
|
|
144
|
+
let compList = new Array();
|
|
126
145
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
146
|
+
switch (category) {
|
|
147
|
+
case "custom":
|
|
148
|
+
const fieldComps = await getSubComponents(directory, FIELD_PATH);
|
|
149
|
+
const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
|
|
150
|
+
const widgetComps = await getSubComponents(directory, WIDGET_PATH);
|
|
130
151
|
|
|
131
|
-
let compList = new Array();
|
|
132
152
|
|
|
133
|
-
if (fieldComps.length > 0) {
|
|
134
|
-
if (showSeparator) compList.push(new inquirer.Separator("---- fields ----"));
|
|
135
|
-
compList.push(...fieldComps);
|
|
136
|
-
}
|
|
137
153
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
154
|
+
if (fieldComps.length > 0) {
|
|
155
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- fields ----"));
|
|
156
|
+
compList.push(...fieldComps);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (templateComps.length > 0) {
|
|
160
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- templates ----"));
|
|
161
|
+
compList.push(...templateComps);
|
|
162
|
+
}
|
|
142
163
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
164
|
+
if (widgetComps.length > 0) {
|
|
165
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- widgets ----"));
|
|
166
|
+
compList.push(...widgetComps);
|
|
167
|
+
}
|
|
168
|
+
break;
|
|
169
|
+
case "override":
|
|
170
|
+
const formsComps = await getSubComponents(directory, FORMS_PATH);
|
|
171
|
+
const templatesComps = await getSubComponents(directory, TEMPLATES_PATH);
|
|
172
|
+
const widgetsComps = await getSubComponents(directory, WIDGETS_PATH);
|
|
173
|
+
const dseComps = await getSubComponents(directory, DSE_PATH);
|
|
174
|
+
const infraComps = await getSubComponents(directory, INFRA_PATH);
|
|
175
|
+
|
|
176
|
+
if (formsComps.length > 0) {
|
|
177
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- forms (fields) ----"));
|
|
178
|
+
compList.push(...formsComps);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (templatesComps.length > 0) {
|
|
182
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- templates ----"));
|
|
183
|
+
compList.push(...templatesComps);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (widgetsComps.length > 0) {
|
|
187
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- widgets ----"));
|
|
188
|
+
compList.push(...widgetsComps);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (dseComps.length > 0) {
|
|
192
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- design system extensions ----"));
|
|
193
|
+
compList.push(...dseComps);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (infraComps.length > 0) {
|
|
197
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- infrastructure ----"));
|
|
198
|
+
compList.push(...infraComps);
|
|
199
|
+
}
|
|
200
|
+
break;
|
|
146
201
|
}
|
|
147
202
|
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
148
207
|
return compList;
|
|
149
208
|
|
|
150
209
|
};
|
|
@@ -176,53 +235,132 @@ export const getComponentsObj = async (showSeparator = false, category = "custom
|
|
|
176
235
|
}
|
|
177
236
|
|
|
178
237
|
const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory);
|
|
238
|
+
let compList = new Array();
|
|
179
239
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
240
|
+
switch (category) {
|
|
241
|
+
case "custom":
|
|
242
|
+
const fieldComps = await getSubComponents(directory, FIELD_PATH);
|
|
243
|
+
const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
|
|
244
|
+
const widgetComps = await getSubComponents(directory, WIDGET_PATH);
|
|
183
245
|
|
|
184
|
-
|
|
246
|
+
if (fieldComps.length > 0) {
|
|
247
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- fields ----"));
|
|
248
|
+
|
|
249
|
+
compList.push(...fieldComps.map(
|
|
250
|
+
name => {
|
|
251
|
+
const container = {};
|
|
252
|
+
container.name = name;
|
|
253
|
+
container.value = COMPONENT_PREFIX_FIELD_PATH + name;
|
|
254
|
+
|
|
255
|
+
return container;
|
|
256
|
+
}
|
|
257
|
+
));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (templateComps.length > 0) {
|
|
261
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- templates ----"));
|
|
262
|
+
compList.push(...templateComps.map(
|
|
263
|
+
name => {
|
|
264
|
+
const container = {};
|
|
265
|
+
container.name = name;
|
|
266
|
+
container.value = COMPONENT_PREFIX_TEMPLATE_PATH + name;
|
|
185
267
|
|
|
186
|
-
|
|
187
|
-
|
|
268
|
+
return container;
|
|
269
|
+
}
|
|
270
|
+
));
|
|
271
|
+
}
|
|
188
272
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
273
|
+
if (widgetComps.length > 0) {
|
|
274
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- widgets ----"));
|
|
275
|
+
compList.push(...widgetComps.map(
|
|
276
|
+
name => {
|
|
277
|
+
const container = {};
|
|
278
|
+
container.name = name;
|
|
279
|
+
container.value = COMPONENT_PREFIX_WIDGET_PATH + name;
|
|
194
280
|
|
|
195
|
-
|
|
281
|
+
return container;
|
|
282
|
+
}
|
|
283
|
+
));
|
|
284
|
+
}
|
|
285
|
+
break;
|
|
286
|
+
case "override":
|
|
287
|
+
const formsComps = await getSubComponents(directory, FORMS_PATH);
|
|
288
|
+
const templatesComps = await getSubComponents(directory, TEMPLATES_PATH);
|
|
289
|
+
const widgetsComps = await getSubComponents(directory, WIDGETS_PATH);
|
|
290
|
+
const dseComps = await getSubComponents(directory, DSE_PATH);
|
|
291
|
+
const infraComps = await getSubComponents(directory, INFRA_PATH);
|
|
292
|
+
|
|
293
|
+
if (formsComps.length > 0) {
|
|
294
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- forms (fields) ----"));
|
|
295
|
+
|
|
296
|
+
compList.push(...formsComps.map(
|
|
297
|
+
name => {
|
|
298
|
+
const container = {};
|
|
299
|
+
container.name = name;
|
|
300
|
+
container.value = COMPONENT_PREFIX_FORMS_PATH + name;
|
|
301
|
+
|
|
302
|
+
return container;
|
|
303
|
+
}
|
|
304
|
+
));
|
|
196
305
|
}
|
|
197
|
-
));
|
|
198
|
-
}
|
|
199
306
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
307
|
+
if (templatesComps.length > 0) {
|
|
308
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- templates ----"));
|
|
309
|
+
compList.push(...templatesComps.map(
|
|
310
|
+
name => {
|
|
311
|
+
const container = {};
|
|
312
|
+
container.name = name;
|
|
313
|
+
container.value = COMPONENT_PREFIX_TEMPLATES_PATH + name;
|
|
207
314
|
|
|
208
|
-
|
|
315
|
+
return container;
|
|
316
|
+
}
|
|
317
|
+
));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (widgetsComps.length > 0) {
|
|
321
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- widgets ----"));
|
|
322
|
+
compList.push(...widgetsComps.map(
|
|
323
|
+
name => {
|
|
324
|
+
const container = {};
|
|
325
|
+
container.name = name;
|
|
326
|
+
container.value = COMPONENT_PREFIX_WIDGETS_PATH + name;
|
|
327
|
+
|
|
328
|
+
return container;
|
|
329
|
+
}
|
|
330
|
+
));
|
|
209
331
|
}
|
|
210
|
-
));
|
|
211
|
-
}
|
|
212
332
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
333
|
+
if (dseComps.length > 0) {
|
|
334
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- designSystemExtensions ----"));
|
|
335
|
+
compList.push(...dseComps.map(
|
|
336
|
+
name => {
|
|
337
|
+
const container = {};
|
|
338
|
+
container.name = name;
|
|
339
|
+
container.value = COMPONENT_PREFIX_DSE_PATH + name;
|
|
220
340
|
|
|
221
|
-
|
|
341
|
+
return container;
|
|
342
|
+
}
|
|
343
|
+
));
|
|
222
344
|
}
|
|
223
|
-
|
|
345
|
+
|
|
346
|
+
if (infraComps.length > 0) {
|
|
347
|
+
if (showSeparator) compList.push(new inquirer.Separator("---- infrastructure ----"));
|
|
348
|
+
compList.push(...infraComps.map(
|
|
349
|
+
name => {
|
|
350
|
+
const container = {};
|
|
351
|
+
container.name = name;
|
|
352
|
+
container.value = COMPONENT_PREFIX_INFRA_PATH + name;
|
|
353
|
+
|
|
354
|
+
return container;
|
|
355
|
+
}
|
|
356
|
+
));
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
break;
|
|
224
360
|
}
|
|
225
361
|
|
|
362
|
+
|
|
363
|
+
|
|
226
364
|
return compList;
|
|
227
365
|
}
|
|
228
366
|
|
|
@@ -279,6 +417,21 @@ export const removeComponentPrefix = (componentName) => {
|
|
|
279
417
|
else if (componentName.indexOf(COMPONENT_PREFIX_WIDGET_PATH) == 0) {
|
|
280
418
|
componentName = componentName.substring(COMPONENT_PREFIX_WIDGET_PATH.length);
|
|
281
419
|
}
|
|
420
|
+
else if (componentName.indexOf(COMPONENT_PREFIX_FORMS_PATH) == 0) {
|
|
421
|
+
componentName = componentName.substring(COMPONENT_PREFIX_FORMS_PATH.length);
|
|
422
|
+
}
|
|
423
|
+
else if (componentName.indexOf(COMPONENT_PREFIX_TEMPLATES_PATH) == 0) {
|
|
424
|
+
componentName = componentName.substring(COMPONENT_PREFIX_TEMPLATES_PATH.length);
|
|
425
|
+
}
|
|
426
|
+
else if (componentName.indexOf(COMPONENT_PREFIX_WIDGETS_PATH) == 0) {
|
|
427
|
+
componentName = componentName.substring(COMPONENT_PREFIX_WIDGETS_PATH.length);
|
|
428
|
+
}
|
|
429
|
+
else if (componentName.indexOf(COMPONENT_PREFIX_DSE_PATH) == 0) {
|
|
430
|
+
componentName = componentName.substring(COMPONENT_PREFIX_DSE_PATH.length);
|
|
431
|
+
}
|
|
432
|
+
else if (componentName.indexOf(COMPONENT_PREFIX_INFRA_PATH) == 0) {
|
|
433
|
+
componentName = componentName.substring(COMPONENT_PREFIX_INFRA_PATH.length);
|
|
434
|
+
}
|
|
282
435
|
|
|
283
436
|
return componentName;
|
|
284
437
|
}
|
|
@@ -326,6 +479,7 @@ export const getComponentDirectoryPath = async (componentKey, category = "custom
|
|
|
326
479
|
return join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
|
|
327
480
|
};
|
|
328
481
|
|
|
482
|
+
|
|
329
483
|
export const compileMustacheTemplate = (file, data) => {
|
|
330
484
|
const content = fs.readFileSync(file, 'utf8');
|
|
331
485
|
return mustache.render(content, data);
|
|
@@ -383,6 +537,14 @@ export const validateRulesetVersion = str => {
|
|
|
383
537
|
return regex.test(str);
|
|
384
538
|
};
|
|
385
539
|
|
|
540
|
+
export const showVersion = () => {
|
|
541
|
+
// get package version, so can display at start
|
|
542
|
+
const require = createRequire(import.meta.url);
|
|
543
|
+
const pData = require("@pega/dx-component-builder-sdk/package.json");
|
|
544
|
+
|
|
545
|
+
console.log(chalk.green("DX Component Builder - SDK v" + pData.version));
|
|
546
|
+
}
|
|
547
|
+
|
|
386
548
|
export const getOOTBComponents = async () => {
|
|
387
549
|
return new Promise((resolve, reject) => {
|
|
388
550
|
fs.readFile(OOTB_COMPONENTS, 'utf-8', async (err, data) => {
|