@pega/dx-component-builder-sdk 0.1.0 → 0.1.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/dx-component-builder-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/cli.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  deleteComponent,
9
9
  deleteAllComponents,
10
10
  listComponents,
11
+ overrideComponent,
11
12
  publishComponent,
12
13
  publishAllComponents,
13
14
  updateComponent,
@@ -17,6 +18,7 @@ import {
17
18
 
18
19
  const TASKS = {
19
20
  CREATE: 'create',
21
+ OVERRIDE: 'override',
20
22
  BUILD: 'buildComponent',
21
23
  PUBLISH: 'publish',
22
24
  PUBLISH_All: 'publishAll',
@@ -56,6 +58,10 @@ export default async (args = []) => {
56
58
  createComponent(options);
57
59
  break;
58
60
  }
61
+ case TASKS.OVERRIDE: {
62
+ overrideComponent(options);
63
+ break;
64
+ }
59
65
  case TASKS.PUBLISH: {
60
66
  publishComponent(options);
61
67
  break;
package/src/constants.js CHANGED
@@ -8,9 +8,19 @@ export const OOTB_COMPONENTS = '../.ootb_components';
8
8
  export const FIELD_PATH = '/field';
9
9
  export const TEMPLATE_PATH = '/template';
10
10
  export const WIDGET_PATH = '/widget';
11
+ export const FORMS_PATH = '/forms';
12
+ export const TEMPLATES_PATH = '/templates';
13
+ export const WIDGETS_PATH = '/widgets';
14
+ export const DSE_PATH = '/designSystemExtensions';
15
+ export const INFRA_PATH = '/infra';
11
16
  export const COMPONENT_PREFIX_FIELD_PATH = "field/";
12
17
  export const COMPONENT_PREFIX_TEMPLATE_PATH = "template/";
13
18
  export const COMPONENT_PREFIX_WIDGET_PATH = "widget/";
19
+ export const COMPONENT_PREFIX_FORMS_PATH = "forms/";
20
+ export const COMPONENT_PREFIX_TEMPLATES_PATH = "templates/";
21
+ export const COMPONENT_PREFIX_WIDGETS_PATH = "widgets/";
22
+ export const COMPONENT_PREFIX_DSE_PATH = "designSystemExtensions/";
23
+ export const COMPONENT_PREFIX_INFRA_PATH = "infra/";
14
24
 
15
25
  /* REST end points */
16
26
  export const PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/publish_component';
@@ -38,6 +48,16 @@ export const COMPONENT_SCHEMA = {
38
48
  value: 'SDK-WebComponents'
39
49
  }
40
50
  ],
51
+ category: [
52
+ {
53
+ name: 'Custom',
54
+ value: 'custom'
55
+ },
56
+ {
57
+ name: 'Override',
58
+ value: 'override'
59
+ }
60
+ ],
41
61
  type: [
42
62
  {
43
63
  name: 'Field',
@@ -130,5 +150,351 @@ export const COMPONENT_SCHEMA = {
130
150
  value: ['PAGE', 'CASE']
131
151
  }
132
152
  ]
153
+ },
154
+ overrideType: [
155
+ {
156
+ name: 'Form (Field)',
157
+ value: 'forms'
158
+ },
159
+ {
160
+ name: 'Template',
161
+ value: 'templates'
162
+ },
163
+ {
164
+ name: 'Widget',
165
+ value: 'widgets'
166
+ },
167
+ {
168
+ name: 'Design System Extension',
169
+ value: 'designSystemExtensions'
170
+ },
171
+ {
172
+ name: 'Infrastructure',
173
+ value: 'infra'
174
+ }
175
+ ],
176
+ overrideComponent: {
177
+ forms: [
178
+ {
179
+ name: 'Auto Complete',
180
+ value: 'AutoComplete'
181
+ },
182
+ {
183
+ name: 'Cancel Alert',
184
+ value: 'CancelAlert'
185
+ },
186
+ {
187
+ name: 'Checkbox',
188
+ value: 'Checkbox'
189
+ },
190
+ {
191
+ name: 'Currency',
192
+ value: 'Currency'
193
+ },
194
+ {
195
+ name: 'Date',
196
+ value: 'Date'
197
+ },
198
+ {
199
+ name: 'Date Time',
200
+ value: 'DateTime'
201
+ },
202
+ {
203
+ name: 'Decimal',
204
+ value: 'Decimal'
205
+ },
206
+ {
207
+ name: 'Dropdown',
208
+ value: 'Dropdown'
209
+ },
210
+ {
211
+ name: 'Email',
212
+ value: 'Email'
213
+ },
214
+ {
215
+ name: 'Integer',
216
+ value: 'Integer'
217
+ },
218
+ {
219
+ name: 'Percentage',
220
+ value: 'Percentage'
221
+ },
222
+ {
223
+ name: 'Phone',
224
+ value: 'Phopne'
225
+ },
226
+ {
227
+ name: 'Radio Buttons',
228
+ value: 'RadioButons'
229
+ },
230
+ {
231
+ name: 'Semantic Link',
232
+ value: 'SemanticLink'
233
+ },
234
+ {
235
+ name: 'Text Area',
236
+ value: 'TextArea'
237
+ },
238
+ {
239
+ name: 'Text Content',
240
+ value: 'TextContent'
241
+ },
242
+ {
243
+ name: 'Text Input',
244
+ value: 'TextInput'
245
+ },
246
+ {
247
+ name: 'Time',
248
+ value: 'Time'
249
+ },
250
+ {
251
+ name: 'URL',
252
+ value: 'URL'
253
+ },
254
+ {
255
+ name: 'User Referene',
256
+ value: 'UserRefernece'
257
+ }
258
+ ],
259
+ designSystemExtensions: [
260
+ {
261
+ name: 'Case Summary Fields',
262
+ value: 'CaseSummaryFields'
263
+ },
264
+ {
265
+ name: 'Details Fields',
266
+ value: 'DetailsFields'
267
+ },
268
+ {
269
+ name: 'Field Group',
270
+ value: 'FieldGroup'
271
+ },
272
+ {
273
+ name: 'Field Group List',
274
+ value: 'FieldGroupList'
275
+ },
276
+ {
277
+ name: 'Field Value List',
278
+ value: 'FieldValueList'
279
+ },
280
+ {
281
+ name: 'Operator',
282
+ value: 'Operator'
283
+ },
284
+ {
285
+ name: 'Pulse',
286
+ value: 'Pulse'
287
+ }
288
+ ],
289
+ infra: [
290
+ {
291
+ name: 'Action Buttons',
292
+ value: 'ActionButtons'
293
+ },
294
+ {
295
+ name: 'Assignment',
296
+ value: 'Assignment'
297
+ },
298
+ {
299
+ name: 'Assignment Card',
300
+ value: 'AssignmentCard'
301
+ },
302
+ {
303
+ name: 'Dashboard Filter',
304
+ value: 'DashboardFilter'
305
+ },
306
+ {
307
+ name: 'Defer Load',
308
+ value: 'DeferLoad'
309
+ },
310
+ {
311
+ name: 'Error Boundry',
312
+ value: 'ErroBoundry'
313
+ },
314
+ {
315
+ name: 'Multi Step',
316
+ value: 'MultiStep'
317
+ },
318
+ {
319
+ name: 'Nav Bar',
320
+ value: 'NavBar'
321
+ },
322
+ {
323
+ name: 'Reference',
324
+ value: 'Reference'
325
+ },
326
+ {
327
+ name: 'Region',
328
+ value: 'Region'
329
+ },
330
+ {
331
+ name: 'Stages',
332
+ value: 'Stages'
333
+ },
334
+ {
335
+ name: 'To Do',
336
+ value: 'ToDo'
337
+ },
338
+ {
339
+ name: 'Vertical Tabs',
340
+ value: 'VerticalTabs'
341
+ },
342
+ {
343
+ name: 'View',
344
+ value: 'View'
345
+ }
346
+ ],
347
+ templates: [
348
+ {
349
+ name: 'App Shell',
350
+ value: 'AppShell'
351
+ },
352
+ {
353
+ name: 'Case Summary',
354
+ value: 'CaseSummary'
355
+ },
356
+ {
357
+ name: 'Case View',
358
+ value: 'CaseView'
359
+ },
360
+ {
361
+ name: 'Data Reference',
362
+ value: 'DataReference'
363
+ },
364
+ {
365
+ name: 'Default Form',
366
+ value: 'DefaultForm'
367
+ },
368
+ {
369
+ name: 'Details',
370
+ value: 'Details/Details'
371
+ },
372
+ {
373
+ name: 'Details Sub Tabs',
374
+ value: 'Details/DetailsSubTabs'
375
+ },
376
+ {
377
+ name: 'Details Two Column',
378
+ value: 'Details/DetailsTwoColumn'
379
+ },
380
+ {
381
+ name: 'Details Three Column',
382
+ value: 'Details/DetailsThreeColumn'
383
+ },
384
+ {
385
+ name: 'Field Group',
386
+ value: 'FieldGroupTemplate'
387
+ },
388
+ {
389
+ name: 'Inline Dashboard',
390
+ value: 'InlineDashboard'
391
+ },
392
+ {
393
+ name: 'List Page',
394
+ value: 'List Page'
395
+ },
396
+ {
397
+ name: 'Multi Reference - ReadOnly',
398
+ value: 'MultiReferenceReadOnly'
399
+ },
400
+ {
401
+ name: 'Narrow Wide',
402
+ value: 'NarrowWide/NarrowWide'
403
+ },
404
+ {
405
+ name: 'Narrow Wide Details',
406
+ value: 'NarrowWide/NarrowWideDetails'
407
+ },
408
+ {
409
+ name: 'Narrow Wide Form',
410
+ value: 'NarrowWide/NarrowWideForm'
411
+ },
412
+ {
413
+ name: 'Narrow Wide Page',
414
+ value: 'NarrowWide/NarrowWidePage'
415
+ },
416
+ {
417
+ name: 'One Column',
418
+ value: 'OneColumn/OneColumn'
419
+ },
420
+ {
421
+ name: 'One Column Page',
422
+ value: 'OneColumn/OneColumnPage'
423
+ },
424
+ {
425
+ name: 'One Column Tab',
426
+ value: 'OneColumn/OneColumnTab'
427
+ },
428
+ {
429
+ name: 'Promoted Filters',
430
+ value: 'PromotedFilters'
431
+ },
432
+ {
433
+ name: 'Simple Table',
434
+ value: 'SimpleTable'
435
+ },
436
+ {
437
+ name: 'Single Reference - ReadOnly',
438
+ value: 'SingleReferenceReadOnly'
439
+ },
440
+ {
441
+ name: 'Sub Tabs',
442
+ value: 'SubTabs'
443
+ },
444
+ {
445
+ name: 'Two Column',
446
+ value: 'TwoColumn/TwoColumn'
447
+ },
448
+ {
449
+ name: 'Two Column Page',
450
+ value: 'TwoColumn/TwoColumnPage'
451
+ },
452
+ {
453
+ name: 'Two Column Tab',
454
+ value: 'TwoColumn/TwoColumnTab'
455
+ },
456
+ {
457
+ name: 'Wide Narrow',
458
+ value: 'WideNarrow/WideNarrow'
459
+ },
460
+ {
461
+ name: 'Wide Narrow Details',
462
+ value: 'WideNarrow/WideNarrowDetails'
463
+ },
464
+ {
465
+ name: 'Wide Narrow Form',
466
+ value: 'WideNarrow/WideNarrowForm'
467
+ },
468
+ {
469
+ name: 'Wide Narrow Page',
470
+ value: 'WideNarrow/WideNarrowPage'
471
+ }
472
+ ],
473
+ widgets: [
474
+ {
475
+ name: 'App Announcement',
476
+ value: 'AppAnnoucement'
477
+ },
478
+ {
479
+ name: 'Case History',
480
+ value: 'CaseHistory'
481
+ },
482
+ {
483
+ name: 'File Utility',
484
+ value: 'FileUtility'
485
+ },
486
+ {
487
+ name: 'Followers',
488
+ value: 'Followers'
489
+ },
490
+ {
491
+ name: 'Summary Item',
492
+ value: 'SummaryItem'
493
+ },
494
+ {
495
+ name: 'Summary List',
496
+ value: 'SummaryList'
497
+ }
498
+ ],
133
499
  }
134
500
  };
@@ -14,12 +14,53 @@ import {
14
14
  getPegaServerConfig,
15
15
  validateRulesetVersion
16
16
  } from '../../util.js';
17
- import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
17
+ import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH, COMPONENT_SCHEMA } from '../../constants.js';
18
18
 
19
- export const getPublishComponentQuestions = async () => {
20
- const components = await getComponentsObj(true);
19
+ export const getOptionsCategory = (options) => {
20
+ let categoryType = null;
21
+ if (options.params[3]) {
22
+ let catType = options.params[3];
23
+
24
+ switch (catType.toLowerCase()) {
25
+ case "override" :
26
+ case "o" :
27
+ categoryType = "override";
28
+ break;
29
+ case "custom" :
30
+ case "c" :
31
+ categoryType = "custom";
32
+ break;
33
+ }
34
+ }
35
+ return categoryType;
36
+ }
37
+
38
+ export const getBuildCategory = async (options) => {
39
+ const defaultPegaServerConfig = await getPegaServerConfig();
40
+ const categoryType = getOptionsCategory(options);
41
+
42
+ return [
43
+ {
44
+ name: 'category',
45
+ type: 'rawlist',
46
+ message: 'Category of components ?',
47
+ choices: COMPONENT_SCHEMA.category,
48
+ when() {
49
+ return !options.params[4] && categoryType == null;
50
+ }
51
+ }
52
+ ];
53
+ };
54
+
55
+ export const getBuildComponentQuestions = async (category) => {
56
+ const components = await getComponentsObj(true, category);
21
57
  const defaultPegaConfig = await getPegaServerConfig();
22
58
 
59
+ if (components.length == 0) {
60
+ console.log(chalk.bold.yellow(`No components to build`));
61
+ process.exit(1);
62
+ }
63
+
23
64
  return [
24
65
  {
25
66
  name: 'componentKey',
@@ -42,8 +83,8 @@ export const getPublishComponentQuestions = async () => {
42
83
  ];
43
84
  };
44
85
 
45
- export const zipComponent = async componentKey => {
46
- const srcDirectory = await getComponentDirectoryPath(componentKey);
86
+ export const zipComponent = async (componentKey, category = "custom") => {
87
+ const srcDirectory = await getComponentDirectoryPath(componentKey, category);
47
88
  const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
48
89
  const configJson = `${srcDirectory}/config.json`;
49
90
 
@@ -62,64 +103,3 @@ export const zipComponent = async componentKey => {
62
103
  });
63
104
  return { zipContent, configContent };
64
105
  };
65
-
66
- export const publishComponentToServer = async data => {
67
- const { configContent, zipContent, componentKey, rulesetName, rulesetVersion } = data;
68
-
69
- const apiBody = {
70
- configContent,
71
- zipContent,
72
- componentKey: JSON.parse(configContent).componentKey,
73
- publishFor: 'constellation',
74
- rulesetName,
75
- rulesetVersion,
76
- category: ''
77
- };
78
- const defaultPegaConfig = await getPegaServerConfig();
79
- const url = constructCompleteUrl(
80
- defaultPegaConfig.server,
81
- PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT
82
- );
83
- try {
84
- const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
85
- if (OauthData) {
86
- const {
87
- access_token: accessToken,
88
- token_type: tokenType,
89
- refresh_token: refreshToken
90
- } = JSON.parse(OauthData);
91
- let status = 500;
92
- fetch(url, {
93
- method: 'POST',
94
- agent: new https.Agent({ rejectUnauthorized: false }),
95
- headers: {
96
- Authorization: `${tokenType} ${accessToken}`
97
- },
98
- body: JSON.stringify(apiBody)
99
- })
100
- .then(response => {
101
- status = response.status;
102
- return response.text();
103
- })
104
- .then(resp => {
105
- const respData = JSON.parse(resp);
106
- if (status === 401) {
107
- throw new Error(
108
- 'Error occured in authentication. Please regenerate using authenticate'
109
- );
110
- // console.log(accessTokenUri, refreshToken);
111
- /* TODO - Handle refresh_token */
112
- } else if (status == 200) {
113
- console.log(chalk.bold.green(`Success : ${respData.message}`));
114
- } else {
115
- throw new Error(`${respData.message}`);
116
- }
117
- })
118
- .catch(e => Promise.reject(`${chalk.bold.red(e)}`));
119
- } else {
120
- throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
121
- }
122
- } catch (err) {
123
- throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
124
- }
125
- };
@@ -6,11 +6,19 @@ import validate from '../validator/index.js';
6
6
 
7
7
  import bundleComponent from '../bundle/index.js';
8
8
  import lintComponent from '../linter/index.js';
9
- import { getPublishComponentQuestions, publishComponentToServer, zipComponent } from './helper.js';
9
+ import { getBuildComponentQuestions, getBuildCategory, getOptionsCategory } from './helper.js';
10
10
  import { getComponentDirectoryPath } from '../../util.js';
11
11
 
12
12
  export default async options => {
13
- const questions = await getPublishComponentQuestions();
13
+ const catQuestion = await getBuildCategory(options);
14
+ const catAnwers = await inquirer.prompt(catQuestion);
15
+
16
+ let category = catAnwers.category;
17
+ if (category == null) {
18
+ category = getOptionsCategory(options);
19
+ }
20
+
21
+ const questions = await getBuildComponentQuestions(category);
14
22
  const answers = await inquirer.prompt(questions);
15
23
  const { componentKey, sourceMap, devBuild } = answers;
16
24
 
@@ -23,20 +31,20 @@ export default async options => {
23
31
  {
24
32
  title: 'Validate config schema',
25
33
  task: async () => {
26
- await validate(componentKey);
34
+ await validate(componentKey, category);
27
35
  }
28
36
  },
29
37
  {
30
38
  title: 'Lint component',
31
39
  task: async () => {
32
- const targetDirectory = await getComponentDirectoryPath(componentKey);
40
+ const targetDirectory = await getComponentDirectoryPath(componentKey, category);
33
41
  // console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`);
34
42
  await lintComponent(targetDirectory);
35
43
  }
36
44
  },
37
45
  {
38
46
  title: 'Bundle Component',
39
- task: async () => await bundleComponent(componentKey, sourceMap, devBuild),
47
+ task: async () => await bundleComponent(componentKey, sourceMap, devBuild, category),
40
48
  skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
41
49
  }
42
50
  ],
@@ -9,8 +9,8 @@ import buildComponent from './builder/index.js';
9
9
 
10
10
  const extensions = ['ts', 'tsx', 'js', 'jsx'];
11
11
 
12
- const bundleComponent = async (componentKey, sourceMap, devBuild) => {
13
- const componentDirectory = await getComponentDirectoryPath(componentKey);
12
+ const bundleComponent = async (componentKey, sourceMap, devBuild, category = "custom") => {
13
+ const componentDirectory = await getComponentDirectoryPath(componentKey, category);
14
14
 
15
15
  const idx = (
16
16
  await Promise.all(
@@ -3,7 +3,7 @@ import inquirer from 'inquirer';
3
3
  import ora from 'ora';
4
4
  //import { element } from 'prop-types';
5
5
 
6
- import { LIST_COMPONENT_SERVICE_REST_ENDPOINT } from '../../constants.js';
6
+ import { LIST_COMPONENT_SERVICE_REST_ENDPOINT, COMPONENT_SCHEMA } from '../../constants.js';
7
7
  import {
8
8
  constructCompleteUrl,
9
9
  deleteLocalComponent,
@@ -21,25 +21,55 @@ export const SOURCE_OF_COMPONENT_TYPES = {
21
21
  LOCAL: 'Local'
22
22
  };
23
23
 
24
+
25
+ export const getOptionsCategory = (options) => {
26
+ let categoryType = null;
27
+ if (options.params[3]) {
28
+ let catType = options.params[3];
29
+
30
+ switch (catType.toLowerCase()) {
31
+ case "override" :
32
+ case "o" :
33
+ categoryType = "override";
34
+ break;
35
+ case "custom" :
36
+ case "c" :
37
+ categoryType = "custom";
38
+ break;
39
+ }
40
+ }
41
+ return categoryType;
42
+ }
43
+
24
44
  export const getDeleteComponentsQuestions = async (options, sourceOfComponentsOption) => {
25
45
  const defaultPegaServerConfig = await getPegaServerConfig();
46
+ const categoryType = getOptionsCategory(options);
26
47
 
27
48
  return [
49
+ {
50
+ name: 'category',
51
+ type: 'rawlist',
52
+ message: 'Category of components ?',
53
+ choices: COMPONENT_SCHEMA.category,
54
+ when() {
55
+ return !options.params[4] && categoryType == null;
56
+ }
57
+ },
28
58
  {
29
59
  name: 'sourceOfComponents',
30
60
  type: 'rawlist',
31
61
  message: 'Delete components from Server or Local ?',
32
62
  choices: Object.values(SOURCE_OF_COMPONENT_TYPES),
33
63
  default: defaultPegaServerConfig.sourceOfComponents,
34
- when() {
35
- return !options.params[3];
64
+ when(answers) {
65
+ return !options.params[4] && answers.category != 'override' && categoryType != 'override';
36
66
  }
37
67
  }
38
68
  ];
39
69
  };
40
70
 
41
- export const deleteLocalComponents = async sourceOfComponents => {
42
- const localComponents = await getComponentsObj(true);
71
+ export const deleteLocalComponents = async (sourceOfComponents, category = "custom") => {
72
+ const localComponents = await getComponentsObj(true, category);
43
73
  //const localComponentsAndSub = await getComponentsAndSubDirectory();
44
74
 
45
75
  if (localComponents.length > 0) {
@@ -58,7 +88,18 @@ export const deleteLocalComponents = async sourceOfComponents => {
58
88
  }
59
89
  ]);
60
90
  if (answers.confirmDeletion) {
61
- await deleteLocalComponent(answers.componentKey);
91
+ await deleteLocalComponent(answers.componentKey, category);
92
+
93
+ if (category === "override") {
94
+ // need to remove the map as well
95
+ if (answers.componentKey != undefined) {
96
+ await deleteFromComponentMap(answers.componentKey, category);
97
+ }
98
+ else {
99
+ console.log(chalk.bold.redBright(`No component in map: ` + componnetName));
100
+ }
101
+
102
+ }
62
103
  }
63
104
  } else {
64
105
  console.log(chalk.bold.redBright(`No custom components in ${sourceOfComponents}`));