@pega/custom-dx-components 0.242.47 → 0.242.48

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.47",
3
+ "version": "0.242.48",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
@@ -294,11 +294,8 @@ export const updateSavedFilePath = async(filePath) => {
294
294
  // same starting path, so we can save the relative
295
295
  const relativePath = filePath.replace(defaultPath.concat("/"), "");
296
296
 
297
- if (relativePath != configDef.importRelativePath) {
298
- await setConfigImportRelativePath(relativePath);
299
- await forceDefaultsUpdate();
300
- }
301
-
297
+ await setConfigImportRelativePath(relativePath);
298
+ await forceDefaultsUpdate();
302
299
 
303
300
  }
304
301
  }
@@ -5,6 +5,7 @@ import { join } from 'path';
5
5
  import inquirer from 'inquirer';
6
6
  import ncp from 'ncp';
7
7
  import chalk from 'chalk';
8
+ import { Listr } from 'listr2';
8
9
 
9
10
  import {
10
11
  sanitize,
@@ -19,10 +20,14 @@ import {
19
20
  zipVersionAndArchive,
20
21
  getLibraryArchiveDirectories,
21
22
  hasLibraryAndVersion,
22
- cleanUpTemp
23
+ cleanUpTemp,
24
+ hasArchives,
25
+ restoreFromArchive,
26
+ forceDefaultsUpdate
23
27
  } from '../../util.js';
24
28
  import { TASKS_CONFIG_JSON_FILENAME, ARCHIVES_PATH, TEMP_PATH } from '../../constants.js';
25
29
  import { getFilePathQuestions, getFileNameQuestions, updateTempArchive, updateSavedFilePath } from './helper.js';
30
+ import { showCurrentStatus } from '../show-status/index.js';
26
31
 
27
32
  export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
28
33
  const currentDirectory = process.cwd();
@@ -214,7 +219,7 @@ export const moveComp = async(componentKey, orgLibName, version, copyShared, opt
214
219
  fs.rmSync(tempDirectory, { recursive: true, force: true, maxRetries: 2 });
215
220
  }
216
221
 
217
- export const importArch = async(filePath, fileName) => {
222
+ export const importArch = async(filePath, fileName, hadArchive) => {
218
223
  addDebugLog("importArch", `filePath: ${filePath}, fileName: ${fileName}`, "");
219
224
 
220
225
  const currentDirectory = process.cwd();
@@ -326,8 +331,44 @@ addDebugLog("importArch", `filePath: ${filePath}, fileName: ${fileName}`, "");
326
331
  // delete temp directory
327
332
  fs.rmSync(tempDirectory, { recursive: true, force: true, maxRetries: 2 });
328
333
 
329
- console.log(`\n${chalk.green(`${fileName}`)} has been imported!`);
330
- console.log(`You can switch to ${chalk.green(`${orgLibName}/${version}`)} via npm run switchLib.\n`);
334
+
335
+ if (hadArchive) {
336
+ console.log(`\n${chalk.green(`${fileName}`)} has been imported!`);
337
+ console.log(`You can switch to ${chalk.green(`${orgLibName}/${version}`)} via npm run switchLib.\n`);
338
+ }
339
+ else {
340
+ const switchToFileName = `${orgLibName}_${version}.zip`;
341
+
342
+ const tasks = new Listr(
343
+ [
344
+ {
345
+ title: `Restoring ${orgLibName}/${version}`,
346
+ task: async () => {
347
+ await restoreFromArchive(switchToFileName, orgLibName, version);
348
+ }
349
+ }
350
+ ],
351
+ { concurrent: false, exitOnError: true }
352
+ );
353
+
354
+ console.log(`\n${chalk.green(`${fileName}`)} has been imported!`);
355
+
356
+ await tasks.run().catch(err => {
357
+ console.log(chalk.bold.red(err.toString()));
358
+ process.exit(1);
359
+ });
360
+
361
+ console.log(`${chalk.bold.green(`\nSwitched to ${orgLibName}/${version}!\n`)}`);
362
+
363
+ await forceDefaultsUpdate();
364
+ await showCurrentStatus();
365
+
366
+ console.log('\n***************************************************************');
367
+ console.log(chalk.bold.yellow('Dependencies have changed between versions, recommend updating.'));
368
+ console.log(`PLEASE run ${chalk.bold.yellow("'npm update'")}.`);
369
+ console.log('****************************************************************\n');
370
+ }
371
+
331
372
 
332
373
  }
333
374
 
@@ -349,7 +390,7 @@ export const getZipFileList = async(filePath) => {
349
390
 
350
391
  export default async options => {
351
392
  await showVersion();
352
- await checkLibraryAndArchives();
393
+ // await checkLibraryAndArchives();
353
394
 
354
395
  await checkPathAccess(pegaConfigJsonPath);
355
396
  const isLibraryBased = getLibraryBased();
@@ -358,6 +399,8 @@ export default async options => {
358
399
  process.exit();
359
400
  }
360
401
 
402
+ const hasArch = await hasArchives();
403
+
361
404
  await cleanUpTemp();
362
405
 
363
406
  addDebugLog("importArchive", "", "+");
@@ -366,7 +409,7 @@ export default async options => {
366
409
  if (options.params.length >= 5) {
367
410
  const filePath = options.params[3];
368
411
  const fileName = options.params[4];
369
- await importArch( filePath, fileName);
412
+ await importArch( filePath, fileName, hasArch);
370
413
 
371
414
  }
372
415
  else {
@@ -388,7 +431,13 @@ export default async options => {
388
431
  const {fileName} = fileNameAnswers;
389
432
 
390
433
 
391
- await importArch( filePath, fileName);
434
+ await importArch( filePath, fileName, hasArch);
435
+
436
+ // reapply to save if changed, because imported task.config may have overriden and we want
437
+ // to keep what was entered as the latest
438
+ await updateSavedFilePath(filePath);
439
+
440
+
392
441
 
393
442
  }
394
443
 
@@ -100,7 +100,7 @@
100
100
  },
101
101
  "devDependencies": {
102
102
  "@pega/configs": "^0.15.1",
103
- "@pega/custom-dx-components": "~0.242.47",
103
+ "@pega/custom-dx-components": "~0.242.48",
104
104
  "@pega/pcore-pconnect-typedefs": "~3.2.0-alpha.1",
105
105
  "@storybook/addon-actions": "^7.6.19",
106
106
  "@storybook/addon-essentials": "^7.6.19",
@@ -7,7 +7,7 @@ import { showVersion, getLibraryBased, addDebugLog, getConfigDefaults, getCompon
7
7
 
8
8
  export const showCurrentStatus = async () => {
9
9
 
10
- const configDefaults = await getConfigDefaults();
10
+ const configDefaults = getConfigDefaults();
11
11
  const componentList = await getComponents();
12
12
 
13
13
  console.log("");
@@ -94,8 +94,6 @@ addDebugLog("switchLibrary", "", "+");
94
94
  ({ version } = nextAnswers);
95
95
  }
96
96
 
97
-
98
-
99
97
  }
100
98
 
101
99
  // in this scenario, version contains "-dev", if appropriate
@@ -132,12 +130,6 @@ addDebugLog("switchLibrary", "", "+");
132
130
  process.exit(1);
133
131
  });
134
132
 
135
- // archive existing
136
- // await zipVersionAndArchive(existingOrgLib, oldVersion);
137
-
138
- // restore from archive
139
- // await restoreFromArchive(switchToFileName, newOrgLib, newVersion);
140
-
141
133
  console.log(`${chalk.bold.green(`\nSwitched to ${newOrgLib}/${newVersion}!\n`)}`);
142
134
 
143
135
  await forceDefaultsUpdate();
@@ -150,16 +142,6 @@ addDebugLog("switchLibrary", "", "+");
150
142
  console.log(`PLEASE run ${chalk.bold.yellow("'npm update'")}.`);
151
143
  console.log('****************************************************************\n');
152
144
 
153
- // const upateQuestions = await getRunNpmQuestions();
154
- // const answers = await inquirer.prompt(upateQuestions);
155
- // const { updateNpm } = answers;
156
-
157
- // if (updateNpm) {
158
- // await anotherTask.run().catch(err => {
159
- // console.log(chalk.bold.red(err.toString()));
160
- // process.exit(1);
161
- // });
162
- // }
163
145
  }
164
146
 
165
147
 
package/src/util.js CHANGED
@@ -134,6 +134,7 @@ export const setUpDefaults = async () => {
134
134
  retrievedConfigData.importRelativePath = data[IMPORT_RELATIVE_PATH];
135
135
  }
136
136
 
137
+
137
138
  if (data[EXPORT_RELATIVE_PATH]) {
138
139
  retrievedConfigData.exportRelativePath = data[EXPORT_RELATIVE_PATH];
139
140
  }
@@ -572,9 +573,9 @@ if (showDebug) addDebugLog("getComponentsObj", "END", "-");
572
573
  return compList;
573
574
  };
574
575
 
575
- export const getPegaConfig = async () => {
576
+ export const getPegaConfig = async (force = false) => {
576
577
  if (showDebug) { addDebugLog("getPegaConfig", "", "+"); }
577
- if (!pegaData) {
578
+ if (!pegaData || force) {
578
579
 
579
580
  if (showDebug) { addDebugLog("getPegaConfig", "retrieveData", ""); }
580
581
  const currentDirectory = process.cwd();
@@ -622,7 +623,7 @@ export const updateServerConfigRuleSetAndVersion = async (rulesetName, rulesetVe
622
623
  if (showDebug) addDebugLog("updateServerConfigRuleSetAndVersion", `rulesetName: ${rulesetName}, rulesetVersion: ${rulesetVersion}`, "");
623
624
  const currentDirectory = process.cwd();
624
625
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
625
- let configData = await getPegaConfig();
626
+ let configData = await getPegaConfig(true);
626
627
  let serverConfig = configData['server-config'];
627
628
 
628
629
  serverConfig.rulesetName = rulesetName;
@@ -641,7 +642,7 @@ if (showDebug) addDebugLog("updateComponentDefaultLibrary", `library: ${library}
641
642
 
642
643
  await checkPathAccess(pegaConfigJsonPath);
643
644
 
644
- let config = await getPegaConfig();
645
+ let config = await getPegaConfig(true);
645
646
  let componentsDefault = config.component;
646
647
  componentsDefault.library = library;
647
648
 
@@ -657,7 +658,7 @@ if (showDebug) addDebugLog("updateComponentDefaultVersion", `version: ${version}
657
658
 
658
659
  await checkPathAccess(pegaConfigJsonPath);
659
660
 
660
- let config = await getPegaConfig();
661
+ let config = await getPegaConfig(true);
661
662
  let componentsDefault = config.component;
662
663
  componentsDefault.version = version;
663
664
 
@@ -679,7 +680,7 @@ export const setConfigDevBuild = async (devBuild) => {
679
680
  if (showDebug) addDebugLog("setConfigDevBuild", `devBuild: ${devBuild}`, "");
680
681
  const currentDirectory = process.cwd();
681
682
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
682
- let configData = await getPegaConfig();
683
+ let configData = await getPegaConfig(true);
683
684
  let serverConfig = configData['server-config'];
684
685
  serverConfig.devBuild = devBuild;
685
686
 
@@ -692,7 +693,7 @@ export const setConfigImportRelativePath = async (importRelativePath) => {
692
693
  if (showDebug) addDebugLog("setConfigImportRelativePath", `importRelativePath: ${importRelativePath}`, "");
693
694
  const currentDirectory = process.cwd();
694
695
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
695
- let configData = await getPegaConfig();
696
+ let configData = await getPegaConfig(true);
696
697
  configData[IMPORT_RELATIVE_PATH] = importRelativePath;
697
698
 
698
699
  // update file
@@ -704,7 +705,7 @@ export const setConfigExportRelativePath = async (exportRelativePath) => {
704
705
  if (showDebug) addDebugLog("setConfigImportRelativePath", `exportRelativePath: ${exportRelativePath}`, "");
705
706
  const currentDirectory = process.cwd();
706
707
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
707
- let configData = await getPegaConfig();
708
+ let configData = await getPegaConfig(true);
708
709
  configData[EXPORT_RELATIVE_PATH] = exportRelativePath;
709
710
 
710
711
  // update file
@@ -813,7 +814,7 @@ export const setServerType = async(serverType) => {
813
814
  if (showDebug) addDebugLog("setServerType", `serverType: ${serverType}`, "");
814
815
  const currentDirectory = process.cwd();
815
816
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
816
- let configData = await getPegaConfig();
817
+ let configData = await getPegaConfig(true);
817
818
  let serverConfig = configData['server-config'];
818
819
  serverConfig.serverType = serverType;
819
820