@pega/custom-dx-components 0.242.43 → 0.242.45

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/custom-dx-components",
3
- "version": "0.242.43",
3
+ "version": "0.242.45",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/constants.js CHANGED
@@ -6,6 +6,8 @@ export const WEBPACK_CONFIG_JS_FILENAME = 'webpack.config.js';
6
6
  export const WEBPACK_PATHS_JS_FILENAME = 'paths.js';
7
7
  export const USE_PROMOTED_WEB_PACK = 'usePromotedWebPack';
8
8
  export const COMPONENTS_DIRECTORY_PATH = 'components-directory-path';
9
+ export const IMPORT_RELATIVE_PATH = 'import-relative-path';
10
+ export const EXPORT_RELATIVE_PATH = 'export-relative-path';
9
11
  export const COMPONENTS_PATH = 'component';
10
12
  export const TOKEN_PATH = 'node_modules/@pega/custom-dx-components/.access_token';
11
13
  export const OOTB_COMPONENTS = 'node_modules/@pega/custom-dx-components/.ootb_components';
@@ -1,7 +1,7 @@
1
1
  import chalk from 'chalk';
2
2
  import path from 'path';
3
3
  import { join } from 'path';
4
- import { addDebugLog, getConfigDefaults, getLibraryArchiveDirectories, getLibraryArchivesVersions } from '../../util.js';
4
+ import { addDebugLog, getConfigDefaults, getLibraryArchiveDirectories, getLibraryArchivesVersions, setConfigExportRelativePath, forceDefaultsUpdate } from '../../util.js';
5
5
 
6
6
  export const SOURCE_OF_COMPONENT_TYPES = {
7
7
  SERVER: 'Server',
@@ -20,9 +20,11 @@ addDebugLog("getFilePathQuestions", "", "");
20
20
  console.log("\tWindows:\tC:\\Users\\name\\...\n");
21
21
  }
22
22
 
23
+ const configDef = getConfigDefaults();
24
+
23
25
  const currentDirectory = process.cwd();
24
26
  const arPathParts = currentDirectory.split(path.sep);
25
- let defaultPath = join(arPathParts[0], arPathParts[1], arPathParts[2], "Downloads");
27
+ let defaultPath = join(arPathParts[0], arPathParts[1], arPathParts[2], configDef.exportRelativePath);
26
28
  if (path.sep === "/") {
27
29
  defaultPath = "/".concat(defaultPath);
28
30
  }
@@ -83,3 +85,23 @@ addDebugLog("getLibraryVersionQuestion", "", "");
83
85
  }
84
86
  ];
85
87
  };
88
+
89
+ export const updateSavedExportFilePath = async(filePath) => {
90
+ const currentDirectory = process.cwd();
91
+ const arPathParts = currentDirectory.split(path.sep);
92
+ const configDef = getConfigDefaults();
93
+
94
+ let defaultPath = join(path.sep, arPathParts[0], arPathParts[1], arPathParts[2]);
95
+
96
+ if (filePath.indexOf(defaultPath) === 0) {
97
+ // same starting path, so we can save the relative
98
+ const relativePath = filePath.replace(defaultPath.concat("/"), "");
99
+
100
+ if (relativePath != configDef.importRelativePath) {
101
+ await setConfigExportRelativePath(relativePath);
102
+ await forceDefaultsUpdate();
103
+ }
104
+
105
+
106
+ }
107
+ }
@@ -18,7 +18,7 @@ import {
18
18
  cleanUpTemp
19
19
  } from '../../util.js';
20
20
  import { TASKS_CONFIG_JSON_FILENAME, ARCHIVES_PATH } from '../../constants.js';
21
- import { getFilePathQuestions, getLibraryQuestion, getLibraryVersionQuestion } from './helper.js';
21
+ import { getFilePathQuestions, getLibraryQuestion, getLibraryVersionQuestion, updateSavedExportFilePath } from './helper.js';
22
22
 
23
23
  export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
24
24
  const currentDirectory = process.cwd();
@@ -129,6 +129,8 @@ addDebugLog("exportArch", `exportPath: ${exportPath}, orgLibName: ${orgLibName},
129
129
  const createNewPath = newPathAnswer.createNewPath;
130
130
  if (createNewPath) {
131
131
  fs.mkdirSync(exportPath, { recursive: true });
132
+
133
+ await updateSavedExportFilePath(exportPath);
132
134
  }
133
135
  else {
134
136
  console.log(chalk.green("Store not exported."));
@@ -211,6 +213,8 @@ export default async options => {
211
213
  const filePathAnswers = await inquirer.prompt(filePathQuestions);
212
214
  let { filePath } = filePathAnswers;
213
215
 
216
+ await updateSavedExportFilePath(filePath);
217
+
214
218
 
215
219
  // if (path.sep === "/") {
216
220
  // if (filePath.lastIndexOf(path.sep) != filePath.length - 1) {
@@ -3,7 +3,7 @@ import fs from 'fs';
3
3
  import path from 'path';
4
4
  import { join } from 'path';
5
5
  import { Listr } from 'listr2';
6
- import { addDebugLog, getConfigDefaults, convertIntoPascalCase, getComponents, getComponentDirectoryPath, getDirectoryFiles } from '../../util.js';
6
+ import { addDebugLog, getConfigDefaults, convertIntoPascalCase, getComponents, getComponentDirectoryPath, getDirectoryFiles, setConfigImportRelativePath, forceDefaultsUpdate } from '../../util.js';
7
7
  import { TASKS_CONFIG_JSON_FILENAME, TEMP_PATH, PACKAGE_JSON_FILENAME } from '../../constants.js';
8
8
 
9
9
 
@@ -251,9 +251,11 @@ addDebugLog("getFilePathQuestions", "", "");
251
251
  console.log("\tWindows:\tC:\\Users\\name\\...\n");
252
252
  }
253
253
 
254
+ const configDef = getConfigDefaults();
255
+
254
256
  const currentDirectory = process.cwd();
255
257
  const arPathParts = currentDirectory.split(path.sep);
256
- let defaultPath = join(arPathParts[0], arPathParts[1], arPathParts[2], "Downloads");
258
+ let defaultPath = join(arPathParts[0], arPathParts[1], arPathParts[2], configDef.importRelativePath);
257
259
  if (path.sep === "/") {
258
260
  defaultPath = "/".concat(defaultPath);
259
261
  }
@@ -280,3 +282,23 @@ addDebugLog("getFileNameQuestions", "", "");
280
282
  },
281
283
  ];
282
284
  };
285
+
286
+ export const updateSavedFilePath = async(filePath) => {
287
+ const currentDirectory = process.cwd();
288
+ const arPathParts = currentDirectory.split(path.sep);
289
+ const configDef = getConfigDefaults();
290
+
291
+ let defaultPath = join(path.sep, arPathParts[0], arPathParts[1], arPathParts[2]);
292
+
293
+ if (filePath.indexOf(defaultPath) === 0) {
294
+ // same starting path, so we can save the relative
295
+ const relativePath = filePath.replace(defaultPath.concat("/"), "");
296
+
297
+ if (relativePath != configDef.importRelativePath) {
298
+ await setConfigImportRelativePath(relativePath);
299
+ await forceDefaultsUpdate();
300
+ }
301
+
302
+
303
+ }
304
+ }
@@ -22,7 +22,7 @@ import {
22
22
  cleanUpTemp
23
23
  } from '../../util.js';
24
24
  import { TASKS_CONFIG_JSON_FILENAME, ARCHIVES_PATH, TEMP_PATH } from '../../constants.js';
25
- import { getFilePathQuestions, getFileNameQuestions, updateTempArchive } from './helper.js';
25
+ import { getFilePathQuestions, getFileNameQuestions, updateTempArchive, updateSavedFilePath } from './helper.js';
26
26
 
27
27
  export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
28
28
  const currentDirectory = process.cwd();
@@ -381,6 +381,8 @@ export default async options => {
381
381
  process.exit();
382
382
  }
383
383
 
384
+ await updateSavedFilePath(filePath);
385
+
384
386
  const fileNameQuestions = await getFileNameQuestions(zipFileList);
385
387
  const fileNameAnswers = await inquirer.prompt(fileNameQuestions);
386
388
  const {fileName} = fileNameAnswers;
@@ -2,8 +2,7 @@ import chalk from 'chalk';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
4
  import { join } from 'path';
5
- import { addDebugLog } from '../../util.js';
6
-
5
+ import { addDebugLog, getConfigDefaults, setConfigImportRelativePath, forceDefaultsUpdate } from '../../util.js';
7
6
 
8
7
  export const getFilePathQuestions = async () => {
9
8
  addDebugLog("getFilePathQuestions", "", "");
@@ -16,9 +15,11 @@ addDebugLog("getFilePathQuestions", "", "");
16
15
  console.log("\tWindows:\tC:\\Users\\name\\...\n");
17
16
  }
18
17
 
18
+ const configDef = getConfigDefaults();
19
+
19
20
  const currentDirectory = process.cwd();
20
21
  const arPathParts = currentDirectory.split(path.sep);
21
- let defaultPath = join(arPathParts[0], arPathParts[1], arPathParts[2], "Downloads");
22
+ let defaultPath = join(arPathParts[0], arPathParts[1], arPathParts[2], configDef.importRelativePath);
22
23
  if (path.sep === "/") {
23
24
  defaultPath = "/".concat(defaultPath);
24
25
  }
@@ -45,3 +46,23 @@ addDebugLog("getFileNameQuestions", "", "");
45
46
  },
46
47
  ];
47
48
  };
49
+
50
+ export const updateSavedFilePath = async(filePath) => {
51
+ const currentDirectory = process.cwd();
52
+ const arPathParts = currentDirectory.split(path.sep);
53
+ const configDef = getConfigDefaults();
54
+
55
+ let defaultPath = join(path.sep, arPathParts[0], arPathParts[1], arPathParts[2]);
56
+
57
+ if (filePath.indexOf(defaultPath) === 0) {
58
+ // same starting path, so we can save the relative
59
+ const relativePath = filePath.replace(defaultPath.concat("/"), "");
60
+
61
+ if (relativePath != configDef.importRelativePath) {
62
+ await setConfigImportRelativePath(relativePath);
63
+ await forceDefaultsUpdate();
64
+ }
65
+
66
+
67
+ }
68
+ }
@@ -17,7 +17,9 @@ import {
17
17
  getComponents
18
18
  } from '../../util.js';
19
19
  import { TASKS_CONFIG_JSON_FILENAME } from '../../constants.js';
20
- import { getFilePathQuestions, getFileNameQuestions } from './helper.js';
20
+ import { getFilePathQuestions, getFileNameQuestions, updateSavedFilePath } from './helper.js';
21
+
22
+ import buildComponent from '../build-comp/index.js';
21
23
 
22
24
  export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
23
25
  const currentDirectory = process.cwd();
@@ -155,90 +157,120 @@ export const importComp = async(filePath, fileName) => {
155
157
  addDebugLog("importComp", `filePath: ${filePath}, fileName: ${fileName}`, "");
156
158
 
157
159
  const currentDirectory = process.cwd();
158
- const compDirectory = join(currentDirectory, "src", "components");
160
+ // const compDirectory = join(currentDirectory, "src", "components");
161
+
159
162
  const copyFilePath = join(filePath, fileName);
160
163
 
161
164
  const configDef = getConfigDefaults();
162
- const copyDir = join(compDirectory, fileName);
165
+ const copyDir = await getComponentDirectoryPath(fileName);
166
+ let configData;
167
+ let newName = "";
168
+ let newLabel = "";
163
169
 
164
- if (fs.existsSync(copyFilePath)) {
165
- fs.cpSync(copyFilePath, copyDir, { recursive: true, force: true });
166
- }
170
+ if (fs.existsSync(copyDir)) {
171
+ configData = fs.readFileSync(join(copyDir, "/config.json"), { encoding: 'utf8' });
172
+ configData = configData && JSON.parse(configData);
167
173
 
168
- let configData = fs.readFileSync(join(copyDir, "/config.json"), { encoding: 'utf8' });
169
- configData = configData && JSON.parse(configData);
174
+ const compName = configData.componentKey.split("_")[2];
175
+ const potentialCompKey = `${configDef.currentOrgLib}_${compName}`;
176
+ const currentCompList = await getComponents();
170
177
 
171
- const compName = configData.componentKey.split("_")[2];
172
- const potentialCompKey = `${configDef.currentOrgLib}_${compName}`;
173
- const currentCompList = await getComponents();
174
- let newName = "";
175
- let newLabel = "";
176
178
 
177
- if (currentCompList && currentCompList.includes(potentialCompKey)) {
178
- console.log(`\nComponent ${chalk.yellow(`${potentialCompKey}`)} already exists.`);
179
- const proceedAnswers = await inquirer.prompt([
179
+ if (currentCompList && currentCompList.includes(potentialCompKey)) {
180
+ console.log(`\nComponent ${chalk.yellow(`${potentialCompKey}`)} already exists.`);
181
+ const proceedAnswers = await inquirer.prompt([
180
182
 
181
- {
182
- name: 'proceedAs',
183
- type: 'rawlist',
184
- message: `Proceed as ?`,
185
- default: 'No import',
186
- choices: ['No import', 'Overwrite', 'New name']
187
- },
188
- {
189
- name: 'componentName',
190
- message: 'Enter component name (required)',
191
- when(answers) {
192
- return answers.proceedAs === 'New name';
183
+ {
184
+ name: 'proceedAs',
185
+ type: 'rawlist',
186
+ message: `Proceed as ?`,
187
+ default: 'No import',
188
+ choices: ['No import', 'Overwrite', 'New name']
193
189
  },
194
- validate: value => {
195
- /* value should not be empty
196
- It should not have spaces
197
- It should not start with a number
198
- Only case-insensitive alphanumeric values are allowed
199
- */
200
- if (value && !/^\d/.test(value) && value === sanitize(value)) {
201
- return true;
190
+ {
191
+ name: 'componentName',
192
+ message: 'Enter component name (required)',
193
+ when(answers) {
194
+ return answers.proceedAs === 'New name';
195
+ },
196
+ validate: value => {
197
+ /* value should not be empty
198
+ It should not have spaces
199
+ It should not start with a number
200
+ Only case-insensitive alphanumeric values are allowed
201
+ */
202
+ if (value && !/^\d/.test(value) && value === sanitize(value)) {
203
+ return true;
204
+ }
205
+ return 'Only alphanumeric values are allowed, starting with alphabets, no spaces.';
202
206
  }
203
- return 'Only alphanumeric values are allowed, starting with alphabets, no spaces.';
204
- }
205
- },
206
- {
207
- name: 'componentLabel',
208
- message: 'Enter component label for display (required)',
209
- when(answers) {
210
- return answers.proceedAs === 'New name';
211
207
  },
212
- validate: value => {
213
- if (value) {
214
- return true;
208
+ {
209
+ name: 'componentLabel',
210
+ message: 'Enter component label for display (required)',
211
+ when(answers) {
212
+ return answers.proceedAs === 'New name';
213
+ },
214
+ validate: value => {
215
+ if (value) {
216
+ return true;
217
+ }
218
+ return 'Please provide value for label';
215
219
  }
216
- return 'Please provide value for label';
217
220
  }
221
+ ]);
222
+
223
+
224
+ switch (proceedAnswers.proceedAs) {
225
+ case 'No import':
226
+ // removed copied
227
+ // fs.rmSync(copyDir, { recursive: true, force: true, maxRetries: 2 });
228
+ process.exit();
229
+ break;
230
+ case 'Overwrite':
231
+ // remove existing
232
+ const existingComp = await getComponentDirectoryPath(potentialCompKey);
233
+ fs.rmSync(existingComp, { recursive: true, force: true, maxRetries: 2 });
234
+ break;
235
+ case 'New name':
236
+ newName = proceedAnswers.componentName;
237
+ newLabel = proceedAnswers.componentLabel;
238
+ break;
218
239
  }
219
- ]);
220
-
221
- switch (proceedAnswers.proceedAs) {
222
- case 'No import':
223
- // removed copied
224
- fs.rmSync(copyDir, { recursive: true, force: true, maxRetries: 2 });
225
- process.exit();
226
- break;
227
- case 'Overwrite':
228
- // remove existing
229
- const exitingComp = join(compDirectory, potentialCompKey);
230
- fs.rmSync(exitingComp, { recursive: true, force: true, maxRetries: 2 });
231
- break;
232
- case 'New name':
233
- newName = proceedAnswers.componentName;
234
- newLabel = proceedAnswers.componentLabel;
235
- break;
240
+
236
241
  }
242
+ }
243
+
244
+ if (fs.existsSync(copyFilePath)) {
245
+ fs.cpSync(copyFilePath, copyDir, { recursive: true, force: true });
246
+ configData = fs.readFileSync(join(copyDir, "/config.json"), { encoding: 'utf8' });
247
+
248
+ configData = configData && JSON.parse(configData);
249
+
250
+ const newCompKey = await renameComponent(configData.componentKey, configDef.currentOrgLib, configDef.buildVersion, newName, newLabel, null);
251
+ console.log(`\n${chalk.green(`${fileName}`)} has been imported as ${chalk.green(`${newCompKey}`)}\n`);
252
+
253
+ const validateAnswers = await inquirer.prompt([
254
+ {
255
+ name: 'doValidate',
256
+ type: 'confirm',
257
+ message: `Validate ${chalk.yellow(`${newCompKey}`)}`,
258
+ default: true
259
+ }]);
260
+
261
+ if (validateAnswers.doValidate) {
262
+ const args = [ '','', '', `${newCompKey}`];
263
+ let myOptions = {};
264
+ myOptions["params"] = args;
265
+
266
+ await buildComponent(myOptions);
267
+ }
268
+
269
+
237
270
 
238
271
  }
239
272
 
240
- const newCompKey = await renameComponent(configData.componentKey, configDef.currentOrgLib, configDef.buildVersion, newName, newLabel, null);
241
- console.log(`\n${chalk.green(`${fileName}`)} has been imported as ${chalk.green(`${newCompKey}`)}`);
273
+
242
274
 
243
275
 
244
276
  }
@@ -307,6 +339,8 @@ addDebugLog("importComponent", "", "+");
307
339
  process.exit();
308
340
  }
309
341
 
342
+ await updateSavedFilePath(filePath);
343
+
310
344
  const fileNameQuestions = await getFileNameQuestions(compFileList);
311
345
  const fileNameAnswers = await inquirer.prompt(fileNameQuestions);
312
346
  const {fileName} = fileNameAnswers;
@@ -100,7 +100,7 @@
100
100
  },
101
101
  "devDependencies": {
102
102
  "@pega/configs": "^0.6.0",
103
- "@pega/custom-dx-components": "0.242.43",
103
+ "@pega/custom-dx-components": "~0.242.45",
104
104
  "@pega/pcore-pconnect-typedefs": "~3.0.0",
105
105
  "@storybook/addon-actions": "^7.6.7",
106
106
  "@storybook/addon-essentials": "^7.6.19",
@@ -1,5 +1,7 @@
1
1
  {
2
2
  "components-directory-path": "src/components",
3
+ "import-relative-path": "Downloads",
4
+ "export-relative-path": "Downloads",
3
5
  "server-config": {
4
6
  "rulesetName": "CustomDXComponents",
5
7
  "rulesetVersion": "01-01-01",
package/src/util.js CHANGED
@@ -34,7 +34,9 @@ import {
34
34
  COMPONENTS_PATH,
35
35
  ARCHIVES_PATH,
36
36
  TEMP_PATH,
37
- JEST_TESTS_FUNCTIONAL_PATH
37
+ JEST_TESTS_FUNCTIONAL_PATH,
38
+ IMPORT_RELATIVE_PATH,
39
+ EXPORT_RELATIVE_PATH
38
40
  } from './constants.js';
39
41
 
40
42
 
@@ -57,7 +59,9 @@ let defaultConfigs = {
57
59
  version: "",
58
60
  buildVersion: "",
59
61
  displayLibVersion: "",
60
- showDebug: false
62
+ showDebug: false,
63
+ importRelativePath: "",
64
+ exportRelativePath: ""
61
65
  };
62
66
 
63
67
  let pegaConfig = null;
@@ -110,7 +114,9 @@ export const setUpDefaults = async () => {
110
114
  version: "",
111
115
  buildVersion: "",
112
116
  displayLibVersion: "",
113
- showDebug: false
117
+ showDebug: false,
118
+ importRelativePath: "",
119
+ exportRelativePath: ""
114
120
  };
115
121
 
116
122
  // retrievedConfigData
@@ -124,6 +130,14 @@ export const setUpDefaults = async () => {
124
130
  let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
125
131
  data = JSON.parse(data);
126
132
 
133
+ if (data[IMPORT_RELATIVE_PATH]) {
134
+ retrievedConfigData.importRelativePath = data[IMPORT_RELATIVE_PATH];
135
+ }
136
+
137
+ if (data[EXPORT_RELATIVE_PATH]) {
138
+ retrievedConfigData.exportRelativePath = data[EXPORT_RELATIVE_PATH];
139
+ }
140
+
127
141
  if (data[LIBRARY_BASED]) {
128
142
  retrievedConfigData.isLibraryBased = data[LIBRARY_BASED];
129
143
  }
@@ -674,6 +688,30 @@ if (showDebug) addDebugLog("setConfigDevBuild", `devBuild: ${devBuild}`, "");
674
688
  fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8' });
675
689
  }
676
690
 
691
+ export const setConfigImportRelativePath = async (importRelativePath) => {
692
+ if (showDebug) addDebugLog("setConfigImportRelativePath", `importRelativePath: ${importRelativePath}`, "");
693
+ const currentDirectory = process.cwd();
694
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
695
+ let configData = await getPegaConfig();
696
+ configData[IMPORT_RELATIVE_PATH] = importRelativePath;
697
+
698
+ // update file
699
+ // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
700
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8' });
701
+ }
702
+
703
+ export const setConfigExportRelativePath = async (exportRelativePath) => {
704
+ if (showDebug) addDebugLog("setConfigImportRelativePath", `exportRelativePath: ${exportRelativePath}`, "");
705
+ const currentDirectory = process.cwd();
706
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
707
+ let configData = await getPegaConfig();
708
+ configData[EXPORT_RELATIVE_PATH] = exportRelativePath;
709
+
710
+ // update file
711
+ // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
712
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8' });
713
+ }
714
+
677
715
  export const updateDefaultOrganization = async (organization) => {
678
716
  if (showDebug) addDebugLog("updateDefaultOrganization", `organization: ${organization}`, "");
679
717
  let packageData = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf-8'));
@@ -817,6 +855,7 @@ if (showDebug) addDebugLog("getComponentDirectoryPath", "END", "-");
817
855
  return overrideDir ? join(overrideDir, componentKey) : join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], componentKey);
818
856
  };
819
857
 
858
+
820
859
  export const compileMustacheTemplate = (file, data) => {
821
860
  if (showDebug) addDebugLog("compileMustacheTemplate", `file: ${file}`, "");
822
861
  const content = fs.readFileSync(file, 'utf8');