@pega/dx-component-builder-sdk 0.1.6 → 0.1.7
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/constants.js +8 -4
- package/src/tasks/build/helper.js +4 -22
- package/src/tasks/build/index.js +54 -7
- package/src/tasks/bundle/index.js +2 -2
- package/src/tasks/create/index.js +5 -4
- package/src/tasks/create/templates/SDK-React/Template/PAGE/demo.stories.jsx.mustache +79 -0
- package/src/tasks/create/templates/SDK-React/Template/PAGE/mock.stories.js.mustache +115 -0
- package/src/tasks/delete/helper.js +7 -25
- package/src/tasks/delete/index.js +2 -3
- package/src/tasks/delete-all/helper.js +7 -24
- package/src/tasks/delete-all/index.js +2 -3
- package/src/tasks/list/helper.js +3 -21
- package/src/tasks/list/index.js +2 -3
- package/src/tasks/map/map.js +4 -3
- package/src/tasks/override/index.js +13 -13
- package/src/tasks/publish/helper.js +77 -15
- package/src/tasks/publish/index.js +103 -15
- package/src/tasks/publish-all/helper.js +77 -13
- package/src/tasks/publish-all/index.js +109 -25
- package/src/tasks/validator/index.js +7 -5
- package/src/util.js +56 -10
|
@@ -3,23 +3,30 @@ import Listr from 'listr';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
|
|
5
5
|
import validate from '../validator/index.js';
|
|
6
|
-
|
|
6
|
+
import { getComponentDirectoryPath, showVersion, getOptionsCategory, getComponentsObj } from '../../util.js';
|
|
7
7
|
import bundleComponent from '../bundle/index.js';
|
|
8
|
-
import { updateComponentMap
|
|
9
|
-
|
|
10
|
-
import { getPublishComponentQuestions, publishComponentToServer, zipComponent } from './helper.js';
|
|
11
|
-
import {
|
|
12
|
-
getComponentsObj,
|
|
13
|
-
getComponentDirectoryPath,
|
|
14
|
-
showVersion
|
|
15
|
-
} from '../../util.js';
|
|
8
|
+
import { updateComponentMap } from '../map/map.js';
|
|
16
9
|
import { lintComponent } from '../linter/index.js';
|
|
10
|
+
import { CATEGORY_CONSTELLATION, CATEGORY_CUSTOM } from '../../constants.js';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
import { getPublishComponentQuestions, publishComponentToServer, zipComponent, getBuildCategory, mapConfigJsonToCompanion } from './helper.js';
|
|
14
|
+
|
|
15
|
+
|
|
17
16
|
|
|
18
17
|
export default async options => {
|
|
19
18
|
showVersion();
|
|
20
19
|
|
|
21
|
-
const
|
|
22
|
-
const
|
|
20
|
+
const catQuestion = await getBuildCategory(options);
|
|
21
|
+
const catAnwers = await inquirer.prompt(catQuestion);
|
|
22
|
+
|
|
23
|
+
let category = catAnwers.category;
|
|
24
|
+
if (category == null) {
|
|
25
|
+
category = getOptionsCategory(options);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const components = await getComponentsObj(false, category);
|
|
29
|
+
const questions = await getPublishComponentQuestions(category);
|
|
23
30
|
const answers = await inquirer.prompt(questions);
|
|
24
31
|
const {sourceMap, devBuild } = answers;
|
|
25
32
|
|
|
@@ -29,59 +36,136 @@ export default async options => {
|
|
|
29
36
|
|
|
30
37
|
var componentKey;
|
|
31
38
|
|
|
32
|
-
const
|
|
39
|
+
const customTasks = new Listr(
|
|
33
40
|
[
|
|
41
|
+
|
|
34
42
|
{
|
|
35
43
|
title: 'Validate config schema',
|
|
36
44
|
task: async () => {
|
|
37
|
-
await validate(componentKey);
|
|
45
|
+
await validate(componentKey, category);
|
|
38
46
|
}
|
|
39
47
|
},
|
|
40
48
|
{
|
|
41
49
|
title: 'Lint component',
|
|
42
50
|
task: async () => {
|
|
43
|
-
const targetDirectory = await getComponentDirectoryPath(componentKey);
|
|
51
|
+
const targetDirectory = await getComponentDirectoryPath(componentKey, category);
|
|
52
|
+
// console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
|
|
53
|
+
await lintComponent(targetDirectory);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
title: 'Update component map',
|
|
58
|
+
task: async () => {
|
|
59
|
+
await updateComponentMap(componentKey);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
title: 'Lint companion component',
|
|
64
|
+
task: async () => {
|
|
65
|
+
const targetDirectory = await getComponentDirectoryPath(componentKey, CATEGORY_CONSTELLATION);
|
|
66
|
+
// console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
|
|
67
|
+
await lintComponent(targetDirectory);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
title: 'Map config to companion component',
|
|
72
|
+
task: async () => {
|
|
73
|
+
mapConfigJsonToCompanion(componentKey);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
title: 'Bundle companion component',
|
|
78
|
+
task: async () => await bundleComponent(componentKey, sourceMap, devBuild, CATEGORY_CONSTELLATION),
|
|
79
|
+
skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
title: 'Zip companion component',
|
|
83
|
+
task: async () => {
|
|
84
|
+
const output = await zipComponent(componentKey, CATEGORY_CONSTELLATION);
|
|
85
|
+
content = { ...content, ...output };
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
title: 'Publish companion component',
|
|
90
|
+
task: async () => {
|
|
91
|
+
await publishComponentToServer(content);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
{
|
|
96
|
+
exitOnError: true
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const overrideTasks = new Listr(
|
|
101
|
+
[
|
|
102
|
+
{
|
|
103
|
+
title: 'Validate config schema',
|
|
104
|
+
task: async () => {
|
|
105
|
+
await validate(componentKey, category);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
title: 'Lint component',
|
|
110
|
+
task: async () => {
|
|
111
|
+
const targetDirectory = await getComponentDirectoryPath(componentKey, category);
|
|
44
112
|
// console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
|
|
45
113
|
await lintComponent(targetDirectory);
|
|
46
114
|
}
|
|
47
115
|
},
|
|
48
116
|
{
|
|
49
117
|
title: 'Bundle Component',
|
|
50
|
-
task: async () => await bundleComponent(componentKey, sourceMap, devBuild),
|
|
118
|
+
task: async () => await bundleComponent(componentKey, sourceMap, devBuild, category),
|
|
51
119
|
skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
|
|
52
120
|
},
|
|
53
121
|
{
|
|
54
122
|
title: 'Update Component Map',
|
|
55
123
|
task: async () => {
|
|
56
|
-
await updateComponentMap(componentKey);
|
|
124
|
+
await updateComponentMap(componentKey, category);
|
|
57
125
|
}
|
|
58
126
|
},
|
|
59
127
|
{
|
|
60
128
|
title: 'Zip Component',
|
|
61
129
|
task: async () => {
|
|
62
|
-
const output = await zipComponent(componentKey);
|
|
130
|
+
const output = await zipComponent(componentKey, category);
|
|
63
131
|
content = { ...content, ...output };
|
|
64
132
|
}
|
|
65
|
-
}
|
|
133
|
+
}
|
|
134
|
+
/*
|
|
66
135
|
{
|
|
67
|
-
title: 'Publish
|
|
136
|
+
title: 'Publish component',
|
|
68
137
|
task: async () => {
|
|
69
138
|
await publishComponentToServer(content);
|
|
70
139
|
}
|
|
71
140
|
}
|
|
141
|
+
*/
|
|
72
142
|
],
|
|
73
143
|
{
|
|
74
144
|
exitOnError: true
|
|
75
145
|
}
|
|
76
146
|
);
|
|
77
147
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
148
|
+
|
|
149
|
+
if (category === CATEGORY_CUSTOM) {
|
|
150
|
+
for (var index in components) {
|
|
151
|
+
componentKey = components[index].value;
|
|
152
|
+
console.log(chalk.bold.green("Publishing: " + components[index].name));
|
|
153
|
+
await customTasks.run().catch(err => {
|
|
154
|
+
console.log(chalk.bold.red(err.toString()));
|
|
155
|
+
});
|
|
156
|
+
}
|
|
84
157
|
}
|
|
158
|
+
else {
|
|
159
|
+
for (var index in components) {
|
|
160
|
+
componentKey = components[index].value;
|
|
161
|
+
console.log(chalk.bold.green("Publishing: " + components[index].name));
|
|
162
|
+
await overrideTasks.run().catch(err => {
|
|
163
|
+
console.log(chalk.bold.red(err.toString()));
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
85
169
|
|
|
86
170
|
return true;
|
|
87
171
|
};
|
|
@@ -9,7 +9,9 @@ import {
|
|
|
9
9
|
COMPONENT_SCHEMA,
|
|
10
10
|
COMPONENT_PREFIX_FIELD_PATH,
|
|
11
11
|
COMPONENT_PREFIX_TEMPLATE_PATH,
|
|
12
|
-
COMPONENT_PREFIX_WIDGET_PATH
|
|
12
|
+
COMPONENT_PREFIX_WIDGET_PATH,
|
|
13
|
+
CATEGORY_CUSTOM,
|
|
14
|
+
CATEGORY_OVERRIDE } from '../../constants.js';
|
|
13
15
|
import {
|
|
14
16
|
getComponentDirectoryPath,
|
|
15
17
|
getComponents,
|
|
@@ -169,7 +171,7 @@ const validateSchema = ajv.compile(schema);
|
|
|
169
171
|
|
|
170
172
|
|
|
171
173
|
|
|
172
|
-
export default async (option, category =
|
|
174
|
+
export default async (option, category = CATEGORY_CUSTOM) => {
|
|
173
175
|
let componentToValidate = null;
|
|
174
176
|
if (option.params && option.params[3]) {
|
|
175
177
|
componentToValidate = option.params[3];
|
|
@@ -196,10 +198,10 @@ export default async (option, category = "custom") => {
|
|
|
196
198
|
configData = fs.readFileSync(path.resolve(configFile), 'utf8');
|
|
197
199
|
}
|
|
198
200
|
catch (err) {
|
|
199
|
-
if (category
|
|
201
|
+
if (category === CATEGORY_CUSTOM) {
|
|
200
202
|
throw new Error(`Missing config file for: ${componentToValidate}`);
|
|
201
203
|
}
|
|
202
|
-
else if (category
|
|
204
|
+
else if (category === CATEGORY_OVERRIDE) {
|
|
203
205
|
// for now, if now file just end
|
|
204
206
|
console.log(`${chalk.bold.yellow('config file not availabe for: ' + componentToValidate)}`);
|
|
205
207
|
return;
|
|
@@ -222,7 +224,7 @@ export default async (option, category = "custom") => {
|
|
|
222
224
|
) {
|
|
223
225
|
const ootbComponents = await getOOTBComponents();
|
|
224
226
|
if (ootbComponents.includes(componentToValidate)) {
|
|
225
|
-
throw new Error(`Invalid: Error
|
|
227
|
+
throw new Error(`Invalid: Error occurred in validating ${componentToValidate}`);
|
|
226
228
|
}
|
|
227
229
|
}
|
|
228
230
|
|
package/src/util.js
CHANGED
|
@@ -34,7 +34,9 @@ import {
|
|
|
34
34
|
COMPONENT_PREFIX_TEMPLATES_PATH,
|
|
35
35
|
COMPONENT_PREFIX_WIDGETS_PATH,
|
|
36
36
|
COMPONENT_PREFIX_DSE_PATH,
|
|
37
|
-
COMPONENT_PREFIX_INFRA_PATH
|
|
37
|
+
COMPONENT_PREFIX_INFRA_PATH,
|
|
38
|
+
CATEGORY_CUSTOM,
|
|
39
|
+
CATEGORY_OVERRIDE
|
|
38
40
|
} from './constants.js';
|
|
39
41
|
|
|
40
42
|
|
|
@@ -54,7 +56,7 @@ export const checkPathAccess = async (path, options = {}) => {
|
|
|
54
56
|
}
|
|
55
57
|
};
|
|
56
58
|
|
|
57
|
-
export const deleteLocalComponent = async (componentKey, category =
|
|
59
|
+
export const deleteLocalComponent = async (componentKey, category = CATEGORY_CUSTOM) => {
|
|
58
60
|
const currentDirectory = process.cwd();
|
|
59
61
|
const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
|
|
60
62
|
const categoryDirectory = join("/", category.toLowerCase());
|
|
@@ -128,7 +130,26 @@ export const deleteServerComponent = async componentKey => {
|
|
|
128
130
|
}
|
|
129
131
|
};
|
|
130
132
|
|
|
131
|
-
export const
|
|
133
|
+
export const getOptionsCategory = (options) => {
|
|
134
|
+
let categoryType = null;
|
|
135
|
+
if (options.params[3]) {
|
|
136
|
+
let catType = options.params[3];
|
|
137
|
+
|
|
138
|
+
switch (catType.toLowerCase()) {
|
|
139
|
+
case "override" :
|
|
140
|
+
case "o" :
|
|
141
|
+
categoryType = "override";
|
|
142
|
+
break;
|
|
143
|
+
case "custom" :
|
|
144
|
+
case "c" :
|
|
145
|
+
categoryType = "custom";
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return categoryType;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const getComponents = async (showSeparator = false, category = CATEGORY_CUSTOM) => {
|
|
132
153
|
const currentDirectory = process.cwd();
|
|
133
154
|
const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
|
|
134
155
|
const categoryDirectory = join("/", category.toLowerCase());
|
|
@@ -150,7 +171,7 @@ export const getComponents = async (showSeparator = false, category = "custom")
|
|
|
150
171
|
let compList = new Array();
|
|
151
172
|
|
|
152
173
|
switch (category) {
|
|
153
|
-
case
|
|
174
|
+
case CATEGORY_CUSTOM:
|
|
154
175
|
const fieldComps = await getSubComponents(directory, FIELD_PATH);
|
|
155
176
|
const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
|
|
156
177
|
const widgetComps = await getSubComponents(directory, WIDGET_PATH);
|
|
@@ -172,7 +193,7 @@ export const getComponents = async (showSeparator = false, category = "custom")
|
|
|
172
193
|
compList.push(...widgetComps);
|
|
173
194
|
}
|
|
174
195
|
break;
|
|
175
|
-
case
|
|
196
|
+
case CATEGORY_OVERRIDE:
|
|
176
197
|
const formsComps = await getSubComponents(directory, FORMS_PATH);
|
|
177
198
|
const templatesComps = await getSubComponents(directory, TEMPLATES_PATH);
|
|
178
199
|
const widgetsComps = await getSubComponents(directory, WIDGETS_PATH);
|
|
@@ -223,7 +244,30 @@ export const getSubComponents = async (directory, type) => {
|
|
|
223
244
|
.map(dirent => dirent.name);
|
|
224
245
|
}
|
|
225
246
|
|
|
226
|
-
|
|
247
|
+
|
|
248
|
+
export const getDirectoryFiles = async (directory) => {
|
|
249
|
+
return fs
|
|
250
|
+
.readdirSync(directory, { withFileTypes: true })
|
|
251
|
+
.filter(dirent => !dirent.isDirectory())
|
|
252
|
+
.map(dirent => dirent.name);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/*
|
|
256
|
+
export const createBlankConfigExt = async (directory, name) => {
|
|
257
|
+
|
|
258
|
+
let fileData = "{";
|
|
259
|
+
fileData = fileData.concat("\n\t");
|
|
260
|
+
fileData = fileData.concat("\"name\" : \"");
|
|
261
|
+
fileData = fileData.concat(`${name}`);
|
|
262
|
+
fileData = fileData.concat("\", \n\t");
|
|
263
|
+
fileData = fileData.concat("\"properties\" : [ ] \n");
|
|
264
|
+
fileData = fileData.concat("}");
|
|
265
|
+
return fs.writeFileSync( join(directory, "/config-ext.json"), fileData, { encoding: 'utf8' });
|
|
266
|
+
}
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
export const getComponentsObj = async (showSeparator = false, category = CATEGORY_CUSTOM) => {
|
|
227
271
|
const currentDirectory = process.cwd();
|
|
228
272
|
const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
|
|
229
273
|
const categoryDirectory = join("/", category.toLowerCase());
|
|
@@ -244,7 +288,7 @@ export const getComponentsObj = async (showSeparator = false, category = "custom
|
|
|
244
288
|
let compList = new Array();
|
|
245
289
|
|
|
246
290
|
switch (category) {
|
|
247
|
-
case
|
|
291
|
+
case CATEGORY_CUSTOM:
|
|
248
292
|
const fieldComps = await getSubComponents(directory, FIELD_PATH);
|
|
249
293
|
const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
|
|
250
294
|
const widgetComps = await getSubComponents(directory, WIDGET_PATH);
|
|
@@ -289,7 +333,7 @@ export const getComponentsObj = async (showSeparator = false, category = "custom
|
|
|
289
333
|
));
|
|
290
334
|
}
|
|
291
335
|
break;
|
|
292
|
-
case
|
|
336
|
+
case CATEGORY_OVERRIDE:
|
|
293
337
|
const formsComps = await getSubComponents(directory, FORMS_PATH);
|
|
294
338
|
const templatesComps = await getSubComponents(directory, TEMPLATES_PATH);
|
|
295
339
|
const widgetsComps = await getSubComponents(directory, WIDGETS_PATH);
|
|
@@ -381,7 +425,9 @@ export const getSubComponentsAndDir = async (directory, type) => {
|
|
|
381
425
|
.map(dirent => prefix + dirent.name);
|
|
382
426
|
}
|
|
383
427
|
|
|
384
|
-
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
export const getComponentsAndSubDirectory = async (category = CATEGORY_CUSTOM) => {
|
|
385
431
|
const currentDirectory = process.cwd();
|
|
386
432
|
const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
|
|
387
433
|
const categoryDirectory = join("/", category.toLowerCase());
|
|
@@ -465,7 +511,7 @@ export const getComponentDefaults = async () => {
|
|
|
465
511
|
return config.component;
|
|
466
512
|
};
|
|
467
513
|
|
|
468
|
-
export const getComponentDirectoryPath = async (componentKey, category =
|
|
514
|
+
export const getComponentDirectoryPath = async (componentKey, category = CATEGORY_CUSTOM) => {
|
|
469
515
|
const currentDirectory = process.cwd();
|
|
470
516
|
const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
|
|
471
517
|
const categoryDirectory = join("/", category.toLowerCase());
|