@pega/dx-component-builder-sdk 0.1.11 → 0.1.12

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.11",
3
+ "version": "0.1.12",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/cli.js CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  createComponent,
8
8
  deleteComponent,
9
9
  deleteAllComponents,
10
+ generateMissingCompanions,
10
11
  listComponents,
11
12
  overrideComponent,
12
13
  publishComponent,
@@ -28,7 +29,8 @@ const TASKS = {
28
29
  DELETE: 'delete',
29
30
  DELETE_ALL: "deleteAll",
30
31
  AUTHENTICATE: 'authenticate',
31
- UPGRADE: 'upgrade'
32
+ UPGRADE: 'upgrade',
33
+ GENERATE_MISSING_COMPANIONS: 'generateMissingCompanions'
32
34
  };
33
35
 
34
36
  const parseArgumentsIntoOptions = rawArgs => {
@@ -102,6 +104,10 @@ export default async (args = []) => {
102
104
  upgrade(options);
103
105
  break;
104
106
  }
107
+ case TASKS.GENERATE_MISSING_COMPANIONS: {
108
+ generateMissingCompanions(options);
109
+ break;
110
+ }
105
111
  default: {
106
112
  console.log(chalk.red(`No task matched with ${task}`));
107
113
  break;
@@ -130,7 +130,7 @@ export const compileMustacheTemplates = async (
130
130
 
131
131
 
132
132
 
133
- const validateCompile = async (
133
+ export const validateCompile = async (
134
134
  {
135
135
  library,
136
136
  organization,
@@ -143,7 +143,8 @@ const validateCompile = async (
143
143
  description,
144
144
  allowedApplications
145
145
  },
146
- options
146
+ options,
147
+ onlyCompanion = false
147
148
  ) => {
148
149
 
149
150
  let sSubType = subtype;
@@ -177,41 +178,55 @@ const validateCompile = async (
177
178
  const targetDirectoryConstellation = await getComponentDirectoryPath(join(typeLC, "/",componentKey), CATEGORY_CONSTELLATION);
178
179
 
179
180
  const components = await getComponents(false);
180
- if (components.includes(componentKey)) {
181
- console.log(chalk.red(`${componentKey} component already exists in ${targetDirectory}`));
182
181
 
183
- let componentsConstellation = await getComponents(false, CATEGORY_CONSTELLATION);
182
+ if (!onlyCompanion) {
184
183
  if (components.includes(componentKey)) {
184
+ console.log(chalk.red(`${componentKey} component already exists in ${targetDirectory}`));
185
+
186
+ let componentsConstellation = await getComponents(false, CATEGORY_CONSTELLATION);
187
+ if (components.includes(componentKey)) {
188
+ console.log(chalk.red(`${componentKey} companion component already exists in ${targetDirectoryConstellation}`));
189
+ }
190
+
191
+ return;
192
+ }
193
+ // test for constellation
194
+ const componentsConstellation = await getComponents(false, CATEGORY_CONSTELLATION);
195
+ if (componentsConstellation.includes(componentKey)) {
185
196
  console.log(chalk.red(`${componentKey} companion component already exists in ${targetDirectoryConstellation}`));
197
+ return;
186
198
  }
187
-
188
- return;
189
199
  }
190
- // test for constellation
191
- const componentsConstellation = await getComponents(false, CATEGORY_CONSTELLATION);
192
- if (components.includes(componentKey)) {
193
- console.log(chalk.red(`${componentKey} companion component already exists in ${targetDirectoryConstellation}`));
194
- return;
200
+ else {
201
+ // test for constellation
202
+ const componentsConstellation = await getComponents(false, CATEGORY_CONSTELLATION);
203
+ if (componentsConstellation.includes(componentKey)) {
204
+ console.log(chalk.red(`${componentKey} companion component already exists in ${targetDirectoryConstellation}`));
205
+ return;
206
+ }
195
207
  }
196
208
 
197
- // component
198
- await copyComponentTemplate({
199
- ...options,
200
- targetDirectory,
201
- templateDirectory
202
- });
203
- await compileMustacheTemplates(targetDirectory, {
204
- componentKey,
205
- componentName,
206
- componentLabel,
207
- library,
208
- version,
209
- type,
210
- subtype,
211
- description,
212
- organization,
213
- allowedApplications
214
- });
209
+
210
+ if (!onlyCompanion) {
211
+ // component
212
+ await copyComponentTemplate({
213
+ ...options,
214
+ targetDirectory,
215
+ templateDirectory
216
+ });
217
+ await compileMustacheTemplates(targetDirectory, {
218
+ componentKey,
219
+ componentName,
220
+ componentLabel,
221
+ library,
222
+ version,
223
+ type,
224
+ subtype,
225
+ description,
226
+ organization,
227
+ allowedApplications
228
+ });
229
+ }
215
230
 
216
231
  // matching constellation
217
232
  await copyComponentTemplate({
@@ -232,7 +247,10 @@ const validateCompile = async (
232
247
  allowedApplications
233
248
  });
234
249
 
235
- console.log(chalk.green(`created ${componentKey} component in ${targetDirectory}`));
250
+ if (!onlyCompanion) {
251
+ console.log(chalk.green(`created ${componentKey} component in ${targetDirectory}`));
252
+ }
253
+
236
254
  console.log(chalk.green(`created ${componentKey} companion component in ${targetDirectoryConstellation}`));
237
255
 
238
256
  };
@@ -0,0 +1,77 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import chalk from 'chalk';
4
+
5
+ import { validateCompile } from '../create/index.js';
6
+ import {
7
+ showVersion,
8
+ getComponents,
9
+ getComponentsObj,
10
+ getComponentDirectoryPath,
11
+ getComponentsAndSubDirectory
12
+ } from '../../util.js';
13
+ import {CATEGORY_CONSTELLATION, CATEGORY_CUSTOM, CATEGORY_OVERRIDE } from '../..//constants.js';
14
+ import { or } from 'ajv/dist/compile/codegen/index.js';
15
+
16
+ export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
17
+ const pegaConfigInternalJsonPath = path.join(path.resolve(), DXCB_CONFIG_INTERNAL_JSON_FILENAME);
18
+
19
+
20
+ const getMissingList = async () => {
21
+ const customList = await getComponentsAndSubDirectory(CATEGORY_CUSTOM);
22
+ const constellationList = await getComponentsAndSubDirectory(CATEGORY_CONSTELLATION);
23
+ let missingList = [];
24
+
25
+ for (var el in customList) {
26
+ const found = constellationList.find(element => element === customList[el]);
27
+ if (found === undefined) {
28
+ missingList.push(customList[el]);
29
+ }
30
+ }
31
+
32
+ return missingList;
33
+ }
34
+
35
+ const generateMissingCompanion = async (componentKey) => {
36
+ const srcDirectory = await getComponentDirectoryPath(componentKey, CATEGORY_CUSTOM);
37
+ const configJson = `${srcDirectory}/config.json`;
38
+
39
+ if (fs.existsSync(configJson)) {
40
+ let data = fs.readFileSync(configJson, { encoding: 'utf8' });
41
+ data = JSON.parse(data);
42
+
43
+ const { name, label, description, organization, version, library, componentKey, type, subtype} = data;
44
+ let { allowedApplications } = data;
45
+
46
+ const componentName = componentKey.split("_")[2];
47
+
48
+ // look up the framework
49
+ let internalData = fs.readFileSync(pegaConfigInternalJsonPath, { encoding: 'utf8' });
50
+ internalData = internalData && JSON.parse(internalData);
51
+
52
+ const framework = internalData.sdkType;
53
+ allowedApplications = allowedApplications.toString();
54
+
55
+
56
+ validateCompile({library, organization, componentName, label, version, framework, type, subtype, description, allowedApplications}, null, true);
57
+ }
58
+
59
+ }
60
+
61
+ export default async options => {
62
+
63
+ showVersion();
64
+
65
+ const missingList = await getMissingList();
66
+
67
+ if (missingList.length === 0) {
68
+ console.log(chalk.bold.green("No missing companion components!"));
69
+ return;
70
+ }
71
+
72
+ for (var el in missingList) {
73
+ await generateMissingCompanion(missingList[el]);
74
+ }
75
+
76
+
77
+ }
@@ -10,3 +10,4 @@ export { default as validate } from './validator/index.js';
10
10
  export { default as authenticate } from './authenticate/index.js';
11
11
  export { default as upgrade } from './upgrade/index.js';
12
12
  export { default as buildComponent } from './build/index.js';
13
+ export { default as generateMissingCompanions } from './generate-missing-companions/index.js';
package/src/util.js CHANGED
@@ -36,7 +36,8 @@ import {
36
36
  COMPONENT_PREFIX_DSE_PATH,
37
37
  COMPONENT_PREFIX_INFRA_PATH,
38
38
  CATEGORY_CUSTOM,
39
- CATEGORY_OVERRIDE
39
+ CATEGORY_OVERRIDE,
40
+ CATEGORY_CONSTELLATION
40
41
  } from './constants.js';
41
42
 
42
43
 
@@ -172,6 +173,7 @@ export const getComponents = async (showSeparator = false, category = CATEGORY_C
172
173
 
173
174
  switch (category) {
174
175
  case CATEGORY_CUSTOM:
176
+ case CATEGORY_CONSTELLATION:
175
177
  const fieldComps = await getSubComponents(directory, FIELD_PATH);
176
178
  const templateComps = await getSubComponents(directory, TEMPLATE_PATH);
177
179
  const widgetComps = await getSubComponents(directory, WIDGET_PATH);