@pega/dx-component-builder-sdk 0.1.18 → 0.1.19

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.18",
3
+ "version": "0.1.19",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/constants.js CHANGED
@@ -1,7 +1,10 @@
1
1
  // cSpell:ignore words timeofday caseview casepreview objectview
2
- export const DXCB_CONFIG_JSON_FILENAME = 'dxcb.config.json';
2
+ export const SDK_CONFIG_JSON_FILENAME = 'sdk-config.json';
3
3
  export const BUILD_CONFIG_JSON_FILENAME = 'build.config.json';
4
4
  export const SDK_LOCAL_COMPONENT_MAP_FILENAME = "sdk-local-component-map.js";
5
+ export const DXCB_CONFIG = 'dxcbConfig';
6
+ export const DXCB_PUBLISH_ACCESS = 'publishAccess';
7
+ export const DXCB_COMPONENT_DEFAULTS = 'componentDefaults';
5
8
  export const COMPONENTS_DIRECTORY_PATH = 'components-directory-path';
6
9
  export const TOKEN_PATH = '../.access_token';
7
10
  export const OOTB_COMPONENTS = '../.ootb_components';
@@ -7,13 +7,12 @@ import inquirer from 'inquirer';
7
7
  import fetch from 'node-fetch';
8
8
 
9
9
  import { checkPathAccess, getTokenUrl, showVersion } from '../../util.js';
10
- import { TOKEN_PATH } from '../../constants.js';
10
+ import { TOKEN_PATH, SDK_CONFIG_JSON_FILENAME, DXCB_CONFIG, DXCB_PUBLISH_ACCESS } from '../../constants.js';
11
11
 
12
12
  import { getAuthQuestions } from './helper.js';
13
13
 
14
- export const DXCB_CONFIG_JSON_FILENAME = 'dxcb.config.json';
15
14
 
16
- const pegaConfigJsonPath = path.join(path.resolve(), DXCB_CONFIG_JSON_FILENAME);
15
+ const pegaConfigJsonPath = path.join(path.resolve(), SDK_CONFIG_JSON_FILENAME);
17
16
 
18
17
  const generateAccessToken = async config => {
19
18
  const formData = new URLSearchParams();
@@ -64,7 +63,14 @@ export default async options => {
64
63
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
65
64
  data = data && JSON.parse(data);
66
65
 
67
- const serverConfig = data['server-config'];
66
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][DXCB_PUBLISH_ACCESS]) {
67
+ console.error(
68
+ `${chalk.red.bold('ERROR')} Could not able find publish access path in config.json`
69
+ );
70
+ process.exit(1);
71
+ }
72
+
73
+ const serverConfig = data[DXCB_CONFIG][DXCB_PUBLISH_ACCESS];
68
74
  const params = options.params;
69
75
 
70
76
  const questions = await getAuthQuestions(params);
@@ -9,13 +9,13 @@ import ncp from 'ncp';
9
9
  import chalk from 'chalk';
10
10
 
11
11
  import { checkPathAccess, getTokenUrl, showVersion } from '../../util.js';
12
- import { CATEGORY_CONSTELLATION } from '../../constants.js';
12
+ import { CATEGORY_CONSTELLATION, SDK_CONFIG_JSON_FILENAME, DXCB_CONFIG, DXCB_COMPONENT_DEFAULTS } from '../../constants.js';
13
+
13
14
 
14
15
 
15
- export const DXCB_CONFIG_JSON_FILENAME = 'dxcb.config.json';
16
16
  export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
17
17
 
18
- const pegaConfigJsonPath = path.join(path.resolve(), DXCB_CONFIG_JSON_FILENAME);
18
+ const pegaConfigJsonPath = path.join(path.resolve(), SDK_CONFIG_JSON_FILENAME);
19
19
  const pegaConfigInternalJsonPath = path.join(path.resolve(), DXCB_CONFIG_INTERNAL_JSON_FILENAME);
20
20
 
21
21
  import {
@@ -288,7 +288,14 @@ export default async options => {
288
288
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
289
289
  data = data && JSON.parse(data);
290
290
 
291
- const componentData = data['component'];
291
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][DXCB_COMPONENT_DEFAULTS]) {
292
+ console.error(
293
+ `${chalk.red.bold('ERROR')} Could not able find component defaults in config.json`
294
+ );
295
+ process.exit(1);
296
+ }
297
+
298
+ const componentData = data[DXCB_CONFIG][DXCB_COMPONENT_DEFAULTS];
292
299
 
293
300
  const { organization, library} = componentData;
294
301
 
@@ -10,10 +10,11 @@ import {
10
10
 
11
11
  import {
12
12
  COMPONENTS_DIRECTORY_PATH,
13
- DXCB_CONFIG_JSON_FILENAME,
13
+ SDK_CONFIG_JSON_FILENAME,
14
14
  CATEGORY_CUSTOM,
15
15
  CATEGORY_CONSTELLATION,
16
- COMPONENT_DIRECTORY_PREFIX_CUSTOM
16
+ COMPONENT_DIRECTORY_PREFIX_CUSTOM,
17
+ DXCB_CONFIG
17
18
  } from '../../constants.js';
18
19
 
19
20
  export const SDK_LOCAL_COMPONENT_MAP_FILENAME = "sdk-local-component-map.js";
@@ -22,7 +23,7 @@ export const MAP_END_TAG = "/*map end";
22
23
 
23
24
  export const updateComponentMap = async (componentKey, category = CATEGORY_CUSTOM) => {
24
25
 
25
- const pegaConfigJsonPath = path.join(path.resolve(), DXCB_CONFIG_JSON_FILENAME);
26
+ const pegaConfigJsonPath = path.join(path.resolve(), SDK_CONFIG_JSON_FILENAME);
26
27
  const pegaLocalComponentMapPath = path.join(path.resolve(), SDK_LOCAL_COMPONENT_MAP_FILENAME);
27
28
  const categoryDirectory = (category === CATEGORY_CONSTELLATION) ? join("/", COMPONENT_DIRECTORY_PREFIX_CUSTOM + category.toLowerCase()) : join("/", category.toLowerCase());
28
29
 
@@ -34,14 +35,14 @@ export const updateComponentMap = async (componentKey, category = CATEGORY_CUSTO
34
35
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
35
36
  data = JSON.parse(data);
36
37
 
37
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
38
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH]) {
38
39
  console.error(
39
40
  `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
40
41
  );
41
42
  process.exit(1);
42
43
  }
43
44
 
44
- let importComponent = join(data[COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
45
+ let importComponent = join(data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
45
46
  importComponent = "./".concat(importComponent);
46
47
 
47
48
  let importFull = "import ".concat(componentName).concat(" from '").concat(importComponent).concat("/';");
@@ -75,7 +76,7 @@ export const updateComponentMap = async (componentKey, category = CATEGORY_CUSTO
75
76
  export const deleteFromComponentMap = async (componentKey, category = CATEGORY_CUSTOM) => {
76
77
  const pegaLocalComponentMapPath = path.join(path.resolve(), SDK_LOCAL_COMPONENT_MAP_FILENAME);
77
78
  const categoryDirectory = (category === CATEGORY_CONSTELLATION) ? join("/", COMPONENT_DIRECTORY_PREFIX_CUSTOM + category.toLowerCase()) : join("/", category.toLowerCase());
78
- const pegaConfigJsonPath = path.join(path.resolve(), DXCB_CONFIG_JSON_FILENAME);
79
+ const pegaConfigJsonPath = path.join(path.resolve(), SDK_CONFIG_JSON_FILENAME);
79
80
 
80
81
  const componentNameNoPrefix = removeComponentPrefix(componentKey);
81
82
  const componentName = convertIntoPascalCase(componentNameNoPrefix);
@@ -85,14 +86,14 @@ export const deleteFromComponentMap = async (componentKey, category = CATEGORY_C
85
86
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
86
87
  data = JSON.parse(data);
87
88
 
88
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
89
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH]) {
89
90
  console.error(
90
91
  `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
91
92
  );
92
93
  process.exit(1);
93
94
  }
94
95
 
95
- let importComponent = join(data[COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
96
+ let importComponent = join(data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
96
97
  importComponent = "./".concat(importComponent);
97
98
 
98
99
  let importFull = "import ".concat(componentName).concat(" from '").concat(importComponent).concat("/';");
@@ -19,16 +19,10 @@ import {
19
19
  getComponentDefaults,
20
20
  sanitize,
21
21
  validateSemver
22
- } from '@pega/dx-component-builder-sdk/src/util.js';
23
- import { COMPONENT_SCHEMA, CATEGORY_OVERRIDE } from '../../constants.js';
24
-
25
- export const DXCB_CONFIG_JSON_FILENAME = 'dxcb.config.json';
26
- export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
27
-
28
- const pegaConfigJsonPath = path.join(path.resolve(), DXCB_CONFIG_JSON_FILENAME);
29
- const pegaConfigInternalJsonPath = path.join(path.resolve(), DXCB_CONFIG_INTERNAL_JSON_FILENAME);
30
-
22
+ } from '../../util.js';
23
+ import { COMPONENT_SCHEMA, CATEGORY_OVERRIDE, SDK_CONFIG_JSON_FILENAME, DXCB_CONFIG, DXCB_COMPONENT_DEFAULTS } from '../../constants.js';
31
24
 
25
+ const pegaConfigJsonPath = path.join(path.resolve(), SDK_CONFIG_JSON_FILENAME);
32
26
 
33
27
  const copy = promisify(ncp);
34
28
 
@@ -190,7 +184,14 @@ export default async options => {
190
184
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
191
185
  data = data && JSON.parse(data);
192
186
 
193
- const componentData = data['component'];
187
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][DXCB_COMPONENT_DEFAULTS]) {
188
+ console.error(
189
+ `${chalk.red.bold('ERROR')} Could not able find components defaults path in config.json`
190
+ );
191
+ process.exit(1);
192
+ }
193
+
194
+ const componentData = data[DXCB_CONFIG][DXCB_COMPONENT_DEFAULTS];
194
195
 
195
196
  const { organization, library} = componentData;
196
197
 
package/src/util.js CHANGED
@@ -13,7 +13,9 @@ import fetch from 'node-fetch';
13
13
 
14
14
  import {
15
15
  COMPONENTS_DIRECTORY_PATH,
16
- DXCB_CONFIG_JSON_FILENAME,
16
+ SDK_CONFIG_JSON_FILENAME,
17
+ DXCB_CONFIG,
18
+ DXCB_PUBLISH_ACCESS,
17
19
  TOKEN_PATH,
18
20
  OOTB_COMPONENT_SERVICE_REST_ENDPOINT,
19
21
  DELETE_COMPONENT_SERVICE_REST_ENDPOINT,
@@ -32,7 +34,8 @@ import {
32
34
  CATEGORY_CUSTOM,
33
35
  CATEGORY_OVERRIDE,
34
36
  CATEGORY_CONSTELLATION,
35
- COMPONENT_DIRECTORY_PREFIX_CUSTOM
37
+ COMPONENT_DIRECTORY_PREFIX_CUSTOM,
38
+ DXCB_COMPONENT_DEFAULTS
36
39
  } from './constants.js';
37
40
 
38
41
 
@@ -54,7 +57,7 @@ export const checkPathAccess = async (path, options = {}) => {
54
57
 
55
58
  export const deleteLocalComponent = async (componentKey, category = CATEGORY_CUSTOM) => {
56
59
  const currentDirectory = process.cwd();
57
- const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
60
+ const pegaConfigJsonPath = join(currentDirectory, SDK_CONFIG_JSON_FILENAME);
58
61
  const categoryDirectory = (category === CATEGORY_CONSTELLATION) ? join("/", COMPONENT_DIRECTORY_PREFIX_CUSTOM + category.toLowerCase()) : join("/", category.toLowerCase());
59
62
 
60
63
  await checkPathAccess(pegaConfigJsonPath);
@@ -62,14 +65,14 @@ export const deleteLocalComponent = async (componentKey, category = CATEGORY_CUS
62
65
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
63
66
  data = JSON.parse(data);
64
67
 
65
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
68
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH]) {
66
69
  console.error(
67
70
  `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
68
71
  );
69
72
  process.exit(1);
70
73
  }
71
74
 
72
- const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
75
+ const directory = join(currentDirectory, data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
73
76
 
74
77
  // test for the directory
75
78
  if (fs.existsSync(directory)) {
@@ -166,7 +169,7 @@ export const getOptionsSource = (options) => {
166
169
 
167
170
  export const getComponents = async (showSeparator = false, category = CATEGORY_CUSTOM) => {
168
171
  const currentDirectory = process.cwd();
169
- const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
172
+ const pegaConfigJsonPath = join(currentDirectory, SDK_CONFIG_JSON_FILENAME);
170
173
  const categoryDirectory = (category === CATEGORY_CONSTELLATION) ? join("/", COMPONENT_DIRECTORY_PREFIX_CUSTOM + category.toLowerCase()) : join("/", category.toLowerCase());
171
174
 
172
175
  await checkPathAccess(pegaConfigJsonPath);
@@ -174,7 +177,7 @@ export const getComponents = async (showSeparator = false, category = CATEGORY_C
174
177
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
175
178
  data = JSON.parse(data);
176
179
 
177
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
180
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH]) {
178
181
  console.error(
179
182
  `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
180
183
  );
@@ -182,7 +185,7 @@ export const getComponents = async (showSeparator = false, category = CATEGORY_C
182
185
  }
183
186
 
184
187
 
185
- const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory);
188
+ const directory = join(currentDirectory, data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH], categoryDirectory);
186
189
  let compList = new Array();
187
190
 
188
191
  switch (category) {
@@ -285,7 +288,7 @@ export const createBlankConfigExt = async (directory, name) => {
285
288
 
286
289
  export const getComponentsObj = async (showSeparator = false, category = CATEGORY_CUSTOM) => {
287
290
  const currentDirectory = process.cwd();
288
- const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
291
+ const pegaConfigJsonPath = join(currentDirectory, SDK_CONFIG_JSON_FILENAME);
289
292
  const categoryDirectory = (category === CATEGORY_CONSTELLATION) ? join("/", COMPONENT_DIRECTORY_PREFIX_CUSTOM + category.toLowerCase()) : join("/", category.toLowerCase());
290
293
 
291
294
  await checkPathAccess(pegaConfigJsonPath);
@@ -293,14 +296,14 @@ export const getComponentsObj = async (showSeparator = false, category = CATEGOR
293
296
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
294
297
  data = JSON.parse(data);
295
298
 
296
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
299
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH]) {
297
300
  console.error(
298
301
  `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
299
302
  );
300
303
  process.exit(1);
301
304
  }
302
305
 
303
- const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory);
306
+ const directory = join(currentDirectory, data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH], categoryDirectory);
304
307
  let compList = new Array();
305
308
 
306
309
  switch (category) {
@@ -445,7 +448,7 @@ export const getSubComponentsAndDir = async (directory, type) => {
445
448
 
446
449
  export const getComponentsAndSubDirectory = async (category = CATEGORY_CUSTOM) => {
447
450
  const currentDirectory = process.cwd();
448
- const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
451
+ const pegaConfigJsonPath = join(currentDirectory, SDK_CONFIG_JSON_FILENAME);
449
452
  const categoryDirectory = (category === CATEGORY_CONSTELLATION) ? join("/", COMPONENT_DIRECTORY_PREFIX_CUSTOM + category.toLowerCase()) : join("/", category.toLowerCase());
450
453
 
451
454
  await checkPathAccess(pegaConfigJsonPath);
@@ -453,14 +456,14 @@ export const getComponentsAndSubDirectory = async (category = CATEGORY_CUSTOM) =
453
456
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
454
457
  data = JSON.parse(data);
455
458
 
456
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
459
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH]) {
457
460
  console.error(
458
461
  `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
459
462
  );
460
463
  process.exit(1);
461
464
  }
462
465
 
463
- const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory);
466
+ const directory = join(currentDirectory, data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH], categoryDirectory);
464
467
 
465
468
  const fieldComps = await getSubComponentsAndDir(directory, FIELD_PATH);
466
469
  const templateComps = await getSubComponentsAndDir(directory, TEMPLATE_PATH);
@@ -498,7 +501,7 @@ export const removeComponentPrefix = (componentName) => {
498
501
 
499
502
  export const getPegaConfig = async () => {
500
503
  const currentDirectory = process.cwd();
501
- const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
504
+ const pegaConfigJsonPath = join(currentDirectory, SDK_CONFIG_JSON_FILENAME);
502
505
 
503
506
  await checkPathAccess(pegaConfigJsonPath);
504
507
 
@@ -510,17 +513,17 @@ export const getPegaConfig = async () => {
510
513
 
511
514
  export const getPegaServerConfig = async () => {
512
515
  const config = await getPegaConfig();
513
- return config['server-config'];
516
+ return config[DXCB_CONFIG][DXCB_PUBLISH_ACCESS];
514
517
  };
515
518
 
516
519
  export const getComponentDefaults = async () => {
517
520
  const config = await getPegaConfig();
518
- return config.component;
521
+ return config[DXCB_CONFIG][DXCB_COMPONENT_DEFAULTS];
519
522
  };
520
523
 
521
524
  export const getComponentDirectoryPath = async (componentKey, category = CATEGORY_CUSTOM) => {
522
525
  const currentDirectory = process.cwd();
523
- const pegaConfigJsonPath = join(currentDirectory, DXCB_CONFIG_JSON_FILENAME);
526
+ const pegaConfigJsonPath = join(currentDirectory, SDK_CONFIG_JSON_FILENAME);
524
527
  const categoryDirectory = (category === CATEGORY_CONSTELLATION) ? join("/", COMPONENT_DIRECTORY_PREFIX_CUSTOM + category.toLowerCase()) : join("/", category.toLowerCase());
525
528
 
526
529
  await checkPathAccess(pegaConfigJsonPath);
@@ -528,14 +531,14 @@ export const getComponentDirectoryPath = async (componentKey, category = CATEGOR
528
531
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
529
532
  data = JSON.parse(data);
530
533
 
531
- if (!data[COMPONENTS_DIRECTORY_PATH]) {
534
+ if (!data[DXCB_CONFIG] || !data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH]) {
532
535
  console.error(
533
536
  `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
534
537
  );
535
538
  process.exit(1);
536
539
  }
537
540
 
538
- return join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
541
+ return join(currentDirectory, data[DXCB_CONFIG][COMPONENTS_DIRECTORY_PATH], categoryDirectory, componentKey);
539
542
  };
540
543
 
541
544