@pega/custom-dx-components 0.25.43 → 0.25.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/src/util.js CHANGED
@@ -5,9 +5,9 @@ import { promisify } from 'util';
5
5
  import https from 'https';
6
6
  import crypto from 'node:crypto';
7
7
  import { createRequire } from 'module';
8
- import {jwtDecode} from 'jwt-decode';
8
+ import { jwtDecode } from 'jwt-decode';
9
9
  import archiver from 'archiver';
10
- import {unarchive} from 'unarchive';
10
+ import { unarchive } from 'unarchive';
11
11
  import ora from 'ora';
12
12
 
13
13
  import chalk from 'chalk';
@@ -83,32 +83,32 @@ let sPegaServerConfig;
83
83
  export const modAddAboutData = (addInAboutData) => {
84
84
  // used by jest to not put in to match assets without aboutData
85
85
  addAboutData = addInAboutData;
86
- }
86
+ };
87
87
 
88
88
  export const addDebugLog = (sFunctionName, sLogData, sIncDec) => {
89
89
 
90
90
  let sLog;
91
91
  if (showDebug) {
92
- if (sIncDec === "-") {
93
- debugLevel--;
94
- }
92
+ if (sIncDec === "-") {
93
+ debugLevel--;
94
+ }
95
95
 
96
- sLog = `>> log ${debugLevel} `;
96
+ sLog = `>> log ${debugLevel} `;
97
97
 
98
- for (let i =0; i < debugLevel; i++) {
99
- sLog = sLog.concat("-");
100
- }
98
+ for (let i = 0; i < debugLevel; i++) {
99
+ sLog = sLog.concat("-");
100
+ }
101
101
 
102
- sLog = sLog.concat(sFunctionName).concat(": ").concat(sLogData);
102
+ sLog = sLog.concat(sFunctionName).concat(": ").concat(sLogData);
103
103
 
104
- console.log(`${chalk.hex('#A0522D')(sLog)}`);
104
+ console.log(`${chalk.hex('#A0522D')(sLog)}`);
105
105
 
106
- if (sIncDec === "+") {
107
- debugLevel++;
108
- }
106
+ if (sIncDec === "+") {
107
+ debugLevel++;
108
+ }
109
109
 
110
110
  }
111
- }
111
+ };
112
112
 
113
113
  export const setUpDefaults = async () => {
114
114
 
@@ -183,11 +183,11 @@ export const setUpDefaults = async () => {
183
183
 
184
184
  retrievedConfigData.serverType = data["server-config"].serverType;
185
185
  retrievedConfigData.devBuild = data["server-config"].devBuild;
186
- retrievedConfigData.devServerPort = data["server-config"].devServerPort;
186
+ retrievedConfigData.devServerPort = data["server-config"].devServerPort;
187
187
 
188
188
  retrievedConfigData.buildVersion = retrievedConfigData.devBuild ? `${retrievedConfigData.version}-dev` : retrievedConfigData.version;
189
189
  retrievedConfigData.currentOrgLib = `${retrievedConfigData.organization}_${retrievedConfigData.library}`;
190
- retrievedConfigData.displayLibVersion = `${retrievedConfigData.currentOrgLib }/${retrievedConfigData.buildVersion}`;
190
+ retrievedConfigData.displayLibVersion = `${retrievedConfigData.currentOrgLib}/${retrievedConfigData.buildVersion}`;
191
191
 
192
192
  }
193
193
  catch (ex) {
@@ -197,7 +197,7 @@ export const setUpDefaults = async () => {
197
197
  }
198
198
 
199
199
  return JSON.parse(JSON.stringify(retrievedConfigData));
200
- }
200
+ };
201
201
 
202
202
  export const convertYNToBoolean = (inputYN) => {
203
203
  switch (inputYN) {
@@ -213,7 +213,7 @@ export const convertYNToBoolean = (inputYN) => {
213
213
  }
214
214
 
215
215
  return false;
216
- }
216
+ };
217
217
 
218
218
  export const getInputConfigForCommand = async (commandName) => {
219
219
  // retrievedConfigData
@@ -254,7 +254,7 @@ export const getInputConfigForCommand = async (commandName) => {
254
254
 
255
255
  return {};
256
256
 
257
- }
257
+ };
258
258
 
259
259
  // initialize
260
260
  // await setUpDefaults();
@@ -268,18 +268,18 @@ export const checkPathAccess = async (path, options = {}, throwError = false) =>
268
268
  await access(path, fs.constants.R_OK);
269
269
  } catch (err) {
270
270
  if (throwError) {
271
- if (showDebug) addDebugLog("checkPathAccess", "path: ".concat(path), "+");
272
- if (showDebug) addDebugLog("checkPathAccess", "Error: ".concat(err), "");
273
- if (showDebug) addDebugLog("checkPathAccess", "END", "-");
271
+ if (showDebug) addDebugLog("checkPathAccess", "path: ".concat(path), "+");
272
+ if (showDebug) addDebugLog("checkPathAccess", "Error: ".concat(err), "");
273
+ if (showDebug) addDebugLog("checkPathAccess", "END", "-");
274
274
  throw new Error(err);
275
275
 
276
276
  }
277
277
  else {
278
- if (showDebug) addDebugLog("checkPathAccess", "path: ".concat(path), "+");
278
+ if (showDebug) addDebugLog("checkPathAccess", "path: ".concat(path), "+");
279
279
  const message =
280
280
  errorMessage || `${chalk.red.bold('ERROR')} Could not able to access path - ${path}`;
281
281
  console.error(message);
282
- if (showDebug) addDebugLog("checkPathAccess", "END", "-");
282
+ if (showDebug) addDebugLog("checkPathAccess", "END", "-");
283
283
  process.exit(1);
284
284
  }
285
285
 
@@ -287,7 +287,7 @@ if (showDebug) addDebugLog("checkPathAccess", "END", "-");
287
287
  };
288
288
 
289
289
  export const getUseWebPackPromotion = async () => {
290
- if (showDebug) addDebugLog("getUseWebPackPromotion", "", "");
290
+ if (showDebug) addDebugLog("getUseWebPackPromotion", "", "");
291
291
  const currentDirectory = process.cwd();
292
292
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
293
293
 
@@ -319,10 +319,10 @@ if (showDebug) addDebugLog("getUseWebPackPromotion", "", "");
319
319
 
320
320
  return data[USE_PROMOTED_WEB_PACK];
321
321
 
322
- }
322
+ };
323
323
 
324
- export const updateUseWebPackPromotion = async ( useValue = false ) => {
325
- if (showDebug) addDebugLog("updateUseWebPackPromotion", "", "");
324
+ export const updateUseWebPackPromotion = async (useValue = false) => {
325
+ if (showDebug) addDebugLog("updateUseWebPackPromotion", "", "");
326
326
 
327
327
  const currentDirectory = process.cwd();
328
328
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
@@ -341,12 +341,12 @@ if (showDebug) addDebugLog("updateUseWebPackPromotion", "", "");
341
341
 
342
342
  data["usePromotedWebPack"] = useValue;
343
343
 
344
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(data, null, 4), { encoding: 'utf8',flag:'w' });
344
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(data, null, 4), { encoding: 'utf8', flag: 'w' });
345
345
 
346
- }
346
+ };
347
347
 
348
348
  export const getAboutData = async (currentOrgLib, buildVersion, dateStamp) => {
349
- if (showDebug) addDebugLog("getAboutData", `currentOrgLib: ${currentOrgLib}, buildVersion: ${buildVersion}, dateStamp: ${dateStamp}`,"");
349
+ if (showDebug) addDebugLog("getAboutData", `currentOrgLib: ${currentOrgLib}, buildVersion: ${buildVersion}, dateStamp: ${dateStamp}`, "");
350
350
  const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
351
351
 
352
352
  if (tokenAndStaticServer.C11NB2S === undefined) {
@@ -355,16 +355,16 @@ if (showDebug) addDebugLog("getAboutData", `currentOrgLib: ${currentOrgLib}, bui
355
355
  }
356
356
 
357
357
  const jwt = jwtDecode(tokenAndStaticServer.C11NB2S);
358
- let infinityVersion= jwt.infinity_version;
358
+ let infinityVersion = jwt.infinity_version;
359
359
  infinityVersion = infinityVersion.replace("8.", "");
360
360
 
361
361
  return `${currentOrgLib} ${buildVersion}, ${dateStamp}, ${infinityVersion}`;
362
- }
362
+ };
363
363
 
364
364
  export const applyPegaData = async (configJson) => {
365
- if (showDebug) addDebugLog("applyPegaData", "", "");
365
+ if (showDebug) addDebugLog("applyPegaData", "", "");
366
366
  const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
367
- const currentDirectory = process.cwd()
367
+ const currentDirectory = process.cwd();
368
368
  // const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
369
369
  const currentPackageLockPath = join(currentDirectory, PACKAGE_LOCK_JSON_FILENAME);
370
370
  // let currentPackageData;
@@ -391,7 +391,7 @@ if (showDebug) addDebugLog("applyPegaData", "", "");
391
391
  }
392
392
  else {
393
393
  const jwt = jwtDecode(tokenAndStaticServer.C11NB2S);
394
- infinityVersion= jwt.infinity_version;
394
+ infinityVersion = jwt.infinity_version;
395
395
  // don't remove "8." from infinity version so can do a comparison
396
396
  }
397
397
 
@@ -400,7 +400,7 @@ if (showDebug) addDebugLog("applyPegaData", "", "");
400
400
  configJson.packageCosmosVersion = cosmosVersion;
401
401
 
402
402
 
403
- }
403
+ };
404
404
 
405
405
  export const checkJWTExpiration = async () => {
406
406
  const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
@@ -413,7 +413,7 @@ export const checkJWTExpiration = async () => {
413
413
  }
414
414
 
415
415
  const jwt = jwtDecode(tokenAndStaticServer.C11NB2S);
416
- const { exp, customer_org } = jwt;
416
+ const { exp, customer_org } = jwt;
417
417
  if (exp < (new Date().getTime() + 1) / 1000) {
418
418
  console.log(chalk.redBright("JWT token has expired, please reauthenticate."));
419
419
  process.exit(1);
@@ -432,9 +432,9 @@ export const checkJWTExpiration = async () => {
432
432
  }
433
433
 
434
434
 
435
- }
435
+ };
436
436
 
437
- export const checkAccessTokenExpiration = async() => {
437
+ export const checkAccessTokenExpiration = async () => {
438
438
 
439
439
  const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
440
440
 
@@ -444,16 +444,16 @@ export const checkAccessTokenExpiration = async() => {
444
444
  }
445
445
 
446
446
  const jwt = jwtDecode(tokenAndStaticServer.access_token);
447
- const { exp, customer_org } = jwt;
447
+ const { exp, customer_org } = jwt;
448
448
  if (exp < (new Date().getTime() + 1) / 1000) {
449
449
  console.log(chalk.redBright("Authentication token has expired, please reauthenticate."));
450
450
  process.exit(1);
451
451
  }
452
452
 
453
453
 
454
- }
454
+ };
455
455
 
456
- export const getApplicationAndVersionFromToken = async() => {
456
+ export const getApplicationAndVersionFromToken = async () => {
457
457
  const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
458
458
 
459
459
  if (tokenAndStaticServer.access_token === undefined) {
@@ -465,27 +465,27 @@ export const getApplicationAndVersionFromToken = async() => {
465
465
  const { app_name, app_version } = jwt;
466
466
  return { app_name, app_version };
467
467
 
468
- }
468
+ };
469
469
 
470
470
  export const getLibraryBased = () => {
471
- if (showDebug) addDebugLog("getLibraryBased", "", "");
471
+ if (showDebug) addDebugLog("getLibraryBased", "", "");
472
472
  return defaultConfigs.isLibraryBased;
473
- }
473
+ };
474
474
 
475
475
  export const getLibraryBasedCL = () => {
476
- if (showDebug) addDebugLog("getLibraryBasedCL", "", "");
476
+ if (showDebug) addDebugLog("getLibraryBasedCL", "", "");
477
477
  return defaultConfigs.isLibraryBasedCL;
478
- }
478
+ };
479
479
 
480
480
  export const getUseInputConfig = () => {
481
- if (showDebug) addDebugLog("getUseInputConfig", "", "");
481
+ if (showDebug) addDebugLog("getUseInputConfig", "", "");
482
482
 
483
483
 
484
484
  return defaultConfigs.useInputConfig;
485
- }
485
+ };
486
486
 
487
487
  export const setLibraryBased = async (isLibraryBased) => {
488
- if (showDebug) addDebugLog("setLibraryBased", "", "");
488
+ if (showDebug) addDebugLog("setLibraryBased", "", "");
489
489
  const currentDirectory = process.cwd();
490
490
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
491
491
 
@@ -508,7 +508,7 @@ if (showDebug) addDebugLog("setLibraryBased", "", "");
508
508
  // update file
509
509
  // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
510
510
  try {
511
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(data, null, 4), { encoding: 'utf8',flag:'w' });
511
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(data, null, 4), { encoding: 'utf8', flag: 'w' });
512
512
  }
513
513
  catch (err) {
514
514
  console.error(err);
@@ -522,66 +522,66 @@ if (showDebug) addDebugLog("setLibraryBased", "", "");
522
522
 
523
523
  }
524
524
 
525
- }
525
+ };
526
526
 
527
527
  export const setLibraryBasedCL = async (isLibraryBasedCL) => {
528
528
  if (showDebug) addDebugLog("setLibraryBased", "", "");
529
- const currentDirectory = process.cwd();
530
- const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
531
-
532
- try {
533
- // force to throw error and not console log
534
- await checkPathAccess(pegaConfigJsonPath, {}, true);
535
- }
536
- catch (ex) {
537
- // when can't find it, always be false, assume no library based.
538
- // This is IMPORTANT for init (npx install)
539
- return false;
540
- }
529
+ const currentDirectory = process.cwd();
530
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
541
531
 
542
- let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
543
- data = JSON.parse(data);
532
+ try {
533
+ // force to throw error and not console log
534
+ await checkPathAccess(pegaConfigJsonPath, {}, true);
535
+ }
536
+ catch (ex) {
537
+ // when can't find it, always be false, assume no library based.
538
+ // This is IMPORTANT for init (npx install)
539
+ return false;
540
+ }
544
541
 
545
- if (data[LIBRARY_BASED_CL] != undefined) {
546
- data[LIBRARY_BASED_CL] = isLibraryBasedCL;
542
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
543
+ data = JSON.parse(data);
547
544
 
548
- // if not undefined, force this as well
549
- if (data[LIBRARY_BASED] != undefined) {
550
- data[LIBRARY_BASED] = isLibraryBasedCL;
551
- }
545
+ if (data[LIBRARY_BASED_CL] != undefined) {
546
+ data[LIBRARY_BASED_CL] = isLibraryBasedCL;
552
547
 
553
- // update file
554
- // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
555
- try {
556
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(data, null, 4), { encoding: 'utf8',flag:'w' });
557
- }
558
- catch (err) {
559
- console.error(err);
560
- }
561
- //await forceDefaultsUpdate();
562
- defaultConfigs.isLibraryBasedCL = isLibraryBasedCL;
548
+ // if not undefined, force this as well
549
+ if (data[LIBRARY_BASED] != undefined) {
550
+ data[LIBRARY_BASED] = isLibraryBasedCL;
551
+ }
563
552
 
564
- // force libraryBased if isLibraryBasedCL is true
565
- defaultConfigs.isLibraryBased = isLibraryBasedCL;
553
+ // update file
554
+ // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
555
+ try {
556
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(data, null, 4), { encoding: 'utf8', flag: 'w' });
557
+ }
558
+ catch (err) {
559
+ console.error(err);
560
+ }
561
+ //await forceDefaultsUpdate();
562
+ defaultConfigs.isLibraryBasedCL = isLibraryBasedCL;
566
563
 
564
+ // force libraryBased if isLibraryBasedCL is true
565
+ defaultConfigs.isLibraryBased = isLibraryBasedCL;
567
566
 
568
- // reset
569
- pegaData = null;
570
- pegaConfig = null;
571
567
 
572
- }
568
+ // reset
569
+ pegaData = null;
570
+ pegaConfig = null;
573
571
 
574
572
  }
575
573
 
574
+ };
575
+
576
576
  export const getShowDebug = () => {
577
577
 
578
578
  return defaultConfigs.showDebug;
579
579
 
580
- }
580
+ };
581
581
 
582
582
 
583
583
  export const deleteLocalComponent = async componentKey => {
584
- if (showDebug) addDebugLog("deleteLocalComponent", `componentKey: ${componentKey}`, "");
584
+ if (showDebug) addDebugLog("deleteLocalComponent", `componentKey: ${componentKey}`, "");
585
585
  const currentDirectory = process.cwd();
586
586
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
587
587
 
@@ -617,7 +617,7 @@ export const getHttpsAgent = serverConfig => {
617
617
  };
618
618
 
619
619
  export const deleteServerComponent = async componentKey => {
620
- if (showDebug) addDebugLog("deleteServerComponent", `componentKey: ${componentKey}`, "");
620
+ if (showDebug) addDebugLog("deleteServerComponent", `componentKey: ${componentKey}`, "");
621
621
  const serverConfig = await getPegaServerConfig();
622
622
  const { server, user, password } = serverConfig;
623
623
  const url = constructCompleteUrl(server, DELETE_COMPONENT_SERVICE_REST_ENDPOINT);
@@ -662,8 +662,8 @@ if (showDebug) addDebugLog("deleteServerComponent", `componentKey: ${componentKe
662
662
  }
663
663
  };
664
664
 
665
- export const copyFileToShared = async ( fileName, fileContents) => {
666
- if (showDebug) addDebugLog("copyFileToShared", `fileName: ${fileName}`, "");
665
+ export const copyFileToShared = async (fileName, fileContents) => {
666
+ if (showDebug) addDebugLog("copyFileToShared", `fileName: ${fileName}`, "");
667
667
  const currentDirectory = process.cwd();
668
668
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
669
669
 
@@ -697,7 +697,7 @@ if (showDebug) addDebugLog("copyFileToShared", `fileName: ${fileName}`, "");
697
697
  };
698
698
 
699
699
  export const getComponents = async (overrideDirectory = null) => {
700
- if (showDebug) addDebugLog("getComponents", "", "");
700
+ if (showDebug) addDebugLog("getComponents", "", "");
701
701
  const currentDirectory = process.cwd();
702
702
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
703
703
 
@@ -723,43 +723,48 @@ if (showDebug) addDebugLog("getComponents", "", "");
723
723
  };
724
724
 
725
725
  export const getTopLevelConfigFiles = async (directory) => {
726
- if (showDebug) addDebugLog("getTopLevelConfigFiles", `directory: ${directory}`, "");
726
+ if (showDebug) addDebugLog("getTopLevelConfigFiles", `directory: ${directory}`, "");
727
727
  if (fs.existsSync(directory)) {
728
728
  return fs
729
- .readdirSync(directory, { withFileTypes: true })
730
- .filter(dirent => !dirent.isDirectory())
731
- .map(dirent => dirent.name);
729
+ .readdirSync(directory, { withFileTypes: true })
730
+ .filter(dirent => !dirent.isDirectory())
731
+ .map(dirent => dirent.name);
732
732
  }
733
733
  else {
734
734
  return [];
735
735
  }
736
- }
736
+ };
737
737
 
738
738
  export const removeTopLevelConfigFiles = async (directory) => {
739
- if (showDebug) addDebugLog("removeTopLevelConfigFiles", `directory: ${directory}`, "");
739
+ if (showDebug) addDebugLog("removeTopLevelConfigFiles", `directory: ${directory}`, "");
740
740
  const configFiles = await getTopLevelConfigFiles(directory);
741
741
 
742
742
  if (configFiles && configFiles.length > 0) {
743
743
  for (const configF of configFiles) {
744
744
  // don't remove these files, otherwise, remove it
745
745
  if (configF !== "package-lock.json" &&
746
- configF !== "package.json" &&
747
- configF !== "tasks.config.json" &&
748
- configF !== ".gitignore" &&
749
- configF !== ".npmrc" &&
750
- configF !== ".prettierignore") {
751
- fs.rmSync( join(directory, configF), { recursive: true, force: true, maxRetries: 2 });
746
+ configF !== "package.json" &&
747
+ configF !== "tasks.config.json" &&
748
+ configF !== ".gitignore" &&
749
+ configF !== ".npmrc" &&
750
+ configF !== ".prettierignore") {
751
+ fs.rmSync(join(directory, configF), { recursive: true, force: true, maxRetries: 2 });
752
752
  }
753
753
  }
754
754
  }
755
- }
755
+ };
756
756
 
757
- export const restoreTopLevelConfigFiles = async(directory) => {
758
- if (showDebug) addDebugLog("restoreTopLevelConfigFiles", `directory: ${directory}`, "");
757
+ export const restoreTopLevelConfigFiles = async (directory) => {
758
+ if (showDebug) addDebugLog("restoreTopLevelConfigFiles", `directory: ${directory}`, "");
759
759
  const currentDirectory = process.cwd();
760
760
  const tempDirectory = join(currentDirectory, TEMP_PATH);
761
761
  const configFiles = await getTopLevelConfigFiles(tempDirectory);
762
762
 
763
+ // we force to get the tasks.config.json and store it locally
764
+ // when we call updateComponentTaskConfig we will use this stored version to bring back server-config (except ruleset/version)
765
+ // and component objects
766
+ await getPegaConfig(true);
767
+
763
768
  if (configFiles && configFiles.length > 0) {
764
769
  for (const configF of configFiles) {
765
770
  if (configF !== "package-lock.json" && configF !== "package.json") {
@@ -767,28 +772,28 @@ if (showDebug) addDebugLog("restoreTopLevelConfigFiles", `directory: ${directory
767
772
  }
768
773
  }
769
774
  }
770
- }
775
+ };
771
776
 
772
777
  export const getTemplateConfigFiles = async () => {
773
- if (showDebug) addDebugLog("getTemplateConfigFiles", ``, "");
778
+ if (showDebug) addDebugLog("getTemplateConfigFiles", ``, "");
774
779
  const currentDirectory = process.cwd();
775
780
  const initDir = join(currentDirectory, "node_modules", "@pega", "custom-dx-components", "src", "tasks", "init");
776
781
  const templateDir = join(initDir, "template");
777
782
 
778
783
  if (fs.existsSync(templateDir)) {
779
784
  return fs
780
- .readdirSync(templateDir, { withFileTypes: true })
781
- .filter(dirent => !dirent.isDirectory())
782
- .map(dirent => dirent.name);
785
+ .readdirSync(templateDir, { withFileTypes: true })
786
+ .filter(dirent => !dirent.isDirectory())
787
+ .map(dirent => dirent.name);
783
788
  }
784
789
  else {
785
790
  return [];
786
791
  }
787
792
 
788
- }
793
+ };
789
794
 
790
- export const restoreTopLevelConfigFilesFromTemplate = async(clearDep = true) => {
791
- if (showDebug) addDebugLog("restoreTopLevelConfigFilesFromTemplate", ``, "");
795
+ export const restoreTopLevelConfigFilesFromTemplate = async (clearDep = true) => {
796
+ if (showDebug) addDebugLog("restoreTopLevelConfigFilesFromTemplate", ``, "");
792
797
  // we can't loose devDep that is part of install, so go get the template mustache and push
793
798
  // those in, replacing any changes there, but allowing additional, an keeping it updated
794
799
  // so won't loose new function if an old archive
@@ -807,7 +812,7 @@ if (showDebug) addDebugLog("restoreTopLevelConfigFilesFromTemplate", ``, "");
807
812
  currentPackageData = fs.readFileSync(currentPackagePath);
808
813
  }
809
814
  catch (ex) {
810
- console.log($chalk.red(`\nUnable to retrieve current package.json.`))
815
+ console.log($chalk.red(`\nUnable to retrieve current package.json.`));
811
816
  process.exit(1);
812
817
  }
813
818
  let cData = JSON.parse(currentPackageData);
@@ -817,7 +822,7 @@ if (showDebug) addDebugLog("restoreTopLevelConfigFilesFromTemplate", ``, "");
817
822
  retrievedTemplateData = fs.readFileSync(packageTemplateJsonPath);
818
823
  }
819
824
  catch (ex) {
820
- console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`))
825
+ console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`));
821
826
  process.exit(1);
822
827
  }
823
828
 
@@ -860,7 +865,7 @@ if (showDebug) addDebugLog("restoreTopLevelConfigFilesFromTemplate", ``, "");
860
865
  }
861
866
 
862
867
  // update current package json file
863
- fs.writeFileSync(currentPackagePath, JSON.stringify(cData, null, 4), { encoding: 'utf8',flag:'w' });
868
+ fs.writeFileSync(currentPackagePath, JSON.stringify(cData, null, 4), { encoding: 'utf8', flag: 'w' });
864
869
 
865
870
  // restore from template
866
871
  const templateFiles = await getTemplateConfigFiles();
@@ -872,10 +877,10 @@ if (showDebug) addDebugLog("restoreTopLevelConfigFilesFromTemplate", ``, "");
872
877
  }
873
878
  }
874
879
 
875
- }
880
+ };
876
881
 
877
882
  export const getSubComponents = async (directory, type) => {
878
- if (showDebug) addDebugLog("getDirectoryFiles", `directory: ${directory}, type: ${type}`, "");
883
+ if (showDebug) addDebugLog("getDirectoryFiles", `directory: ${directory}, type: ${type}`, "");
879
884
  const subDirectory = join(directory, type);
880
885
  return fs
881
886
  .readdirSync(subDirectory, { withFileTypes: true })
@@ -884,7 +889,7 @@ if (showDebug) addDebugLog("getDirectoryFiles", `directory: ${directory}, type:
884
889
  };
885
890
 
886
891
  export const getDirectoryFiles = async directory => {
887
- if (showDebug) addDebugLog("getDirectoryFiles", `directory: ${directory}`, "");
892
+ if (showDebug) addDebugLog("getDirectoryFiles", `directory: ${directory}`, "");
888
893
  return fs
889
894
  .readdirSync(directory, { withFileTypes: true })
890
895
  .filter(dirent => !dirent.isDirectory())
@@ -892,7 +897,7 @@ if (showDebug) addDebugLog("getDirectoryFiles", `directory: ${directory}`, "");
892
897
  };
893
898
 
894
899
  export const getComponentsObj = async () => {
895
- if (showDebug) addDebugLog("getComponentsObj", "", "+");
900
+ if (showDebug) addDebugLog("getComponentsObj", "", "+");
896
901
  const compList = [];
897
902
 
898
903
  // const componentList = await getDirectoryFiles(directory);
@@ -905,21 +910,21 @@ if (showDebug) addDebugLog("getComponentsObj", "", "+");
905
910
  container.name = name;
906
911
  container.value = name;
907
912
 
908
- if (showDebug) addDebugLog("getComponentsObj", "container: " + JSON.stringify(container), "");
913
+ if (showDebug) addDebugLog("getComponentsObj", "container: " + JSON.stringify(container), "");
909
914
  return container;
910
915
  })
911
916
  );
912
917
  }
913
918
 
914
- if (showDebug) addDebugLog("getComponentsObj", "END", "-");
919
+ if (showDebug) addDebugLog("getComponentsObj", "END", "-");
915
920
  return compList;
916
921
  };
917
922
 
918
923
  export const getPegaConfig = async (force = false) => {
919
- if (showDebug) { addDebugLog("getPegaConfig", "", "+"); }
924
+ if (showDebug) { addDebugLog("getPegaConfig", "", "+"); }
920
925
  if (!pegaData || force) {
921
926
 
922
- if (showDebug) { addDebugLog("getPegaConfig", "retrieveData", ""); }
927
+ if (showDebug) { addDebugLog("getPegaConfig", "retrieveData", ""); }
923
928
  const currentDirectory = process.cwd();
924
929
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
925
930
 
@@ -930,15 +935,15 @@ if (showDebug) { addDebugLog("getPegaConfig", "retrieveData", ""); }
930
935
  }
931
936
 
932
937
 
933
- if (showDebug) { addDebugLog("getPegaConfig", "pegaData: " + sPegaData, ""); }
934
- if (showDebug) { addDebugLog("getPegaConfig", "END", "-"); }
938
+ if (showDebug) { addDebugLog("getPegaConfig", "pegaData: " + sPegaData, ""); }
939
+ if (showDebug) { addDebugLog("getPegaConfig", "END", "-"); }
935
940
 
936
941
  return pegaData;
937
942
  };
938
943
 
939
- export const getPegaServerConfig = async () => {
940
- if (showDebug) addDebugLog("getPegaServerConfig", "", "+");
941
- if (!pegaConfig) {
944
+ export const getPegaServerConfig = async (force = false) => {
945
+ if (showDebug) addDebugLog("getPegaServerConfig", "", "+");
946
+ if (!pegaConfig || force) {
942
947
  pegaConfig = await getPegaConfig();
943
948
 
944
949
  if (getServerType() === "launchpad") {
@@ -966,26 +971,26 @@ if (showDebug) addDebugLog("getPegaServerConfig", "", "+");
966
971
  sPegaServerConfig = JSON.stringify(pegaConfig['server-config']);
967
972
  }
968
973
 
969
- if (showDebug) addDebugLog("getPegaServerConfig", "server config:" + sPegaServerConfig, "");
970
- if (showDebug) addDebugLog("getPegaServerConfig", "END", "-");
974
+ if (showDebug) addDebugLog("getPegaServerConfig", "server config:" + sPegaServerConfig, "");
975
+ if (showDebug) addDebugLog("getPegaServerConfig", "END", "-");
971
976
  return pegaConfig['server-config'];
972
977
  };
973
978
 
974
979
 
975
980
  // contains all the config, task config, etc. created upon start
976
981
  export const getConfigDefaults = () => {
977
- if (showDebug) addDebugLog("getConfigDefaults", `defaults: ${JSON.stringify(defaultConfigs)}`, "");
982
+ if (showDebug) addDebugLog("getConfigDefaults", `defaults: ${JSON.stringify(defaultConfigs)}`, "");
978
983
 
979
984
  return defaultConfigs;
980
985
 
981
- }
986
+ };
982
987
 
983
988
  export const forceDefaultsUpdate = async () => {
984
989
  defaultConfigs = await setUpDefaults();
985
- }
990
+ };
986
991
 
987
992
  export const updateServerConfigRuleSetAndVersion = async (rulesetName, rulesetVersion) => {
988
- if (showDebug) addDebugLog("updateServerConfigRuleSetAndVersion", `rulesetName: ${rulesetName}, rulesetVersion: ${rulesetVersion}`, "");
993
+ if (showDebug) addDebugLog("updateServerConfigRuleSetAndVersion", `rulesetName: ${rulesetName}, rulesetVersion: ${rulesetVersion}`, "");
989
994
  const currentDirectory = process.cwd();
990
995
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
991
996
  let configData = await getPegaConfig(true);
@@ -996,12 +1001,12 @@ if (showDebug) addDebugLog("updateServerConfigRuleSetAndVersion", `rulesetName:
996
1001
 
997
1002
  // update file
998
1003
  // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
999
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8',flag:'w' });
1004
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8', flag: 'w' });
1000
1005
 
1001
- }
1006
+ };
1002
1007
 
1003
1008
  export const updateComponentDefaultLibrary = async (library) => {
1004
- if (showDebug) addDebugLog("updateComponentDefaultLibrary", `library: ${library}`, "");
1009
+ if (showDebug) addDebugLog("updateComponentDefaultLibrary", `library: ${library}`, "");
1005
1010
  const currentDirectory = process.cwd();
1006
1011
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
1007
1012
 
@@ -1012,12 +1017,12 @@ if (showDebug) addDebugLog("updateComponentDefaultLibrary", `library: ${library}
1012
1017
  componentsDefault.library = library;
1013
1018
 
1014
1019
 
1015
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(config, null, 4), { encoding: 'utf8',flag:'w' });
1020
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(config, null, 4), { encoding: 'utf8', flag: 'w' });
1016
1021
 
1017
- }
1022
+ };
1018
1023
 
1019
1024
  export const updateComponentDefaultVersion = async (version) => {
1020
- if (showDebug) addDebugLog("updateComponentDefaultVersion", `version: ${version}`, "");
1025
+ if (showDebug) addDebugLog("updateComponentDefaultVersion", `version: ${version}`, "");
1021
1026
  const currentDirectory = process.cwd();
1022
1027
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
1023
1028
 
@@ -1028,21 +1033,21 @@ if (showDebug) addDebugLog("updateComponentDefaultVersion", `version: ${version}
1028
1033
  componentsDefault.version = version;
1029
1034
 
1030
1035
 
1031
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(config, null, 4), { encoding: 'utf8',flag:'w' });
1036
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(config, null, 4), { encoding: 'utf8', flag: 'w' });
1032
1037
 
1033
- }
1038
+ };
1034
1039
 
1035
- export const getConfigDevBuild = async() => {
1036
- if (showDebug) addDebugLog("getConfigDevBuild", "", "");
1040
+ export const getConfigDevBuild = async () => {
1041
+ if (showDebug) addDebugLog("getConfigDevBuild", "", "");
1037
1042
  // const serverConfig = await getPegaServerConfig();
1038
1043
 
1039
1044
  // return serverConfig.devBuild;
1040
1045
  return defaultConfigs.devBuild;
1041
1046
 
1042
- }
1047
+ };
1043
1048
 
1044
1049
  export const setConfigDevBuild = async (devBuild) => {
1045
- if (showDebug) addDebugLog("setConfigDevBuild", `devBuild: ${devBuild}`, "");
1050
+ if (showDebug) addDebugLog("setConfigDevBuild", `devBuild: ${devBuild}`, "");
1046
1051
  const currentDirectory = process.cwd();
1047
1052
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
1048
1053
  let configData = await getPegaConfig(true);
@@ -1051,19 +1056,19 @@ if (showDebug) addDebugLog("setConfigDevBuild", `devBuild: ${devBuild}`, "");
1051
1056
 
1052
1057
  // update file
1053
1058
  // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
1054
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8',flag:'w' });
1055
- }
1059
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8', flag: 'w' });
1060
+ };
1056
1061
 
1057
- export const getConfigDevServerPort = async() => {
1058
- if (showDebug) addDebugLog("getConfigDevServerPort", "", "");
1062
+ export const getConfigDevServerPort = async () => {
1063
+ if (showDebug) addDebugLog("getConfigDevServerPort", "", "");
1059
1064
  // const serverConfig = await getPegaServerConfig();
1060
1065
 
1061
1066
  return defaultConfigs.devServerPort;
1062
1067
 
1063
- }
1068
+ };
1064
1069
 
1065
1070
  export const setConfigImportRelativePath = async (importRelativePath) => {
1066
- if (showDebug) addDebugLog("setConfigImportRelativePath", `importRelativePath: ${importRelativePath}`, "");
1071
+ if (showDebug) addDebugLog("setConfigImportRelativePath", `importRelativePath: ${importRelativePath}`, "");
1067
1072
  const currentDirectory = process.cwd();
1068
1073
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
1069
1074
  let configData = await getPegaConfig(true);
@@ -1071,11 +1076,11 @@ if (showDebug) addDebugLog("setConfigImportRelativePath", `importRelativePath: $
1071
1076
 
1072
1077
  // update file
1073
1078
  // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
1074
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8',flag:'w' });
1075
- }
1079
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8', flag: 'w' });
1080
+ };
1076
1081
 
1077
1082
  export const setConfigExportRelativePath = async (exportRelativePath) => {
1078
- if (showDebug) addDebugLog("setConfigExportRelativePath", `exportRelativePath: ${exportRelativePath}`, "");
1083
+ if (showDebug) addDebugLog("setConfigExportRelativePath", `exportRelativePath: ${exportRelativePath}`, "");
1079
1084
  const currentDirectory = process.cwd();
1080
1085
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
1081
1086
  let configData = await getPegaConfig(true);
@@ -1083,21 +1088,21 @@ if (showDebug) addDebugLog("setConfigExportRelativePath", `exportRelativePath: $
1083
1088
 
1084
1089
  // update file
1085
1090
  // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
1086
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8',flag:'w' });
1087
- }
1091
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8', flag: 'w' });
1092
+ };
1088
1093
 
1089
1094
  export const updateDefaultOrganization = async (organization) => {
1090
- if (showDebug) addDebugLog("updateDefaultOrganization", `organization: ${organization}`, "");
1095
+ if (showDebug) addDebugLog("updateDefaultOrganization", `organization: ${organization}`, "");
1091
1096
  let packageData = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf-8'));
1092
1097
 
1093
1098
  packageData.organization = organization;
1094
1099
 
1095
- fs.writeFileSync(path.resolve('package.json'), JSON.stringify(packageData, null, 4), { encoding: 'utf8',flag:'w' });
1100
+ fs.writeFileSync(path.resolve('package.json'), JSON.stringify(packageData, null, 4), { encoding: 'utf8', flag: 'w' });
1096
1101
 
1097
- }
1102
+ };
1098
1103
 
1099
1104
  export const updateConfigVersion = async (componentKey, buildVersion, currentOrgLib) => {
1100
- if (showDebug) addDebugLog("updateConfigVersion", `componentKey: ${componentKey}, buildVersion: ${buildVersion}, currentOrgLib: ${currentOrgLib}`, "");
1105
+ if (showDebug) addDebugLog("updateConfigVersion", `componentKey: ${componentKey}, buildVersion: ${buildVersion}, currentOrgLib: ${currentOrgLib}`, "");
1101
1106
  const componentDirectory = await getComponentDirectoryPath(componentKey);
1102
1107
  const configFileName = 'config.json';
1103
1108
 
@@ -1139,7 +1144,7 @@ if (showDebug) addDebugLog("updateConfigVersion", `componentKey: ${componentKey}
1139
1144
  }
1140
1145
  else {
1141
1146
  // don't have "About"
1142
- const aboutLabelJSON = {
1147
+ const aboutLabelJSON = {
1143
1148
  "format": "LABEL",
1144
1149
  "label": "About",
1145
1150
  "name": "PegaAboutLabel",
@@ -1150,7 +1155,7 @@ if (showDebug) addDebugLog("updateConfigVersion", `componentKey: ${componentKey}
1150
1155
  "label": aboutData,
1151
1156
  "name": "PegaAboutData",
1152
1157
  "variant": "primary"
1153
- }
1158
+ };
1154
1159
  properties.push(aboutLabelJSON);
1155
1160
  properties.push(aboutDataJSON);
1156
1161
  }
@@ -1172,20 +1177,20 @@ if (showDebug) addDebugLog("updateConfigVersion", `componentKey: ${componentKey}
1172
1177
 
1173
1178
 
1174
1179
  // write back file
1175
- fs.writeFileSync(configFile, JSON.stringify(data, null, 4), { encoding: 'utf8',flag:'w' });
1180
+ fs.writeFileSync(configFile, JSON.stringify(data, null, 4), { encoding: 'utf8', flag: 'w' });
1176
1181
  };
1177
1182
 
1178
- export const getServerType = () => {
1179
- if (showDebug) addDebugLog("getServerType", "", "+");
1180
- // const defaultPegaServerConfig = await getPegaServerConfig();
1181
- // if (showDebug) addDebugLog("getServerType", "serverType:" + defaultPegaServerConfig.serverType, "");
1182
- if (showDebug) addDebugLog("getServerType", "END", "-");
1183
+ export const getServerType = () => {
1184
+ if (showDebug) addDebugLog("getServerType", "", "+");
1185
+ // const defaultPegaServerConfig = await getPegaServerConfig();
1186
+ // if (showDebug) addDebugLog("getServerType", "serverType:" + defaultPegaServerConfig.serverType, "");
1187
+ if (showDebug) addDebugLog("getServerType", "END", "-");
1183
1188
  // return defaultPegaServerConfig.serverType;
1184
1189
  return defaultConfigs.serverType;
1185
- }
1190
+ };
1186
1191
 
1187
- export const setServerType = async(serverType) => {
1188
- if (showDebug) addDebugLog("setServerType", `serverType: ${serverType}`, "");
1192
+ export const setServerType = async (serverType) => {
1193
+ if (showDebug) addDebugLog("setServerType", `serverType: ${serverType}`, "");
1189
1194
  const currentDirectory = process.cwd();
1190
1195
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
1191
1196
  let configData = await getPegaConfig(true);
@@ -1194,23 +1199,23 @@ if (showDebug) addDebugLog("setServerType", `serverType: ${serverType}`, "");
1194
1199
 
1195
1200
  // update file
1196
1201
  // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
1197
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8',flag:'w' });
1202
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8', flag: 'w' });
1198
1203
 
1199
1204
  // reset
1200
1205
  pegaData = null;
1201
1206
  pegaConfig = null;
1202
1207
 
1203
1208
  await forceDefaultsUpdate();
1204
- }
1209
+ };
1205
1210
 
1206
1211
  export const getSrcDirectoryPath = async () => {
1207
1212
  const currentDirectory = process.cwd();
1208
1213
 
1209
1214
  return join(currentDirectory, "src");
1210
- }
1215
+ };
1211
1216
 
1212
1217
  export const getComponentDirectoryPath = async (componentKey, overrideDir = null) => {
1213
- if (showDebug) addDebugLog("getComponentDirectoryPath", "", "+");
1218
+ if (showDebug) addDebugLog("getComponentDirectoryPath", "", "+");
1214
1219
  const currentDirectory = process.cwd();
1215
1220
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
1216
1221
 
@@ -1225,14 +1230,14 @@ if (showDebug) addDebugLog("getComponentDirectoryPath", "", "+");
1225
1230
  );
1226
1231
  process.exit(1);
1227
1232
  }
1228
- if (showDebug) addDebugLog("getComponentDirectoryPath", "path: " + join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], componentKey), "");
1229
- if (showDebug) addDebugLog("getComponentDirectoryPath", "END", "-");
1233
+ if (showDebug) addDebugLog("getComponentDirectoryPath", "path: " + join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], componentKey), "");
1234
+ if (showDebug) addDebugLog("getComponentDirectoryPath", "END", "-");
1230
1235
  return overrideDir ? join(overrideDir, componentKey) : join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH], componentKey);
1231
1236
  };
1232
1237
 
1233
1238
 
1234
1239
  export const compileMustacheTemplate = (file, data) => {
1235
- if (showDebug) addDebugLog("compileMustacheTemplate", `file: ${file}`, "");
1240
+ if (showDebug) addDebugLog("compileMustacheTemplate", `file: ${file}`, "");
1236
1241
  const content = fs.readFileSync(file, 'utf8');
1237
1242
  return mustache.render(content, data);
1238
1243
  };
@@ -1246,7 +1251,7 @@ export const convertIntoPascalCase = string => {
1246
1251
  };
1247
1252
 
1248
1253
  export const constructCompleteUrl = (baseServer, endPoint) => {
1249
- if (showDebug) addDebugLog("constructCompleteUrl", "url: " + baseServer.endsWith('/') ? `${baseServer}${endPoint}` : `${baseServer}/${endPoint}`, "");
1254
+ if (showDebug) addDebugLog("constructCompleteUrl", "url: " + baseServer.endsWith('/') ? `${baseServer}${endPoint}` : `${baseServer}/${endPoint}`, "");
1250
1255
  return baseServer.endsWith('/') ? `${baseServer}${endPoint}` : `${baseServer}/${endPoint}`;
1251
1256
  };
1252
1257
 
@@ -1301,7 +1306,7 @@ export const showVersion = async () => {
1301
1306
  const nodeMajorVersion = parseInt(arNodeVersion[0]);
1302
1307
  const nodeMinorVersion = parseInt(arNodeVersion[1]);
1303
1308
 
1304
- if (nodeMajorVersion < 22 && nodeMinorVersion < 15 ) {
1309
+ if (nodeMajorVersion < 22 && nodeMinorVersion < 15) {
1305
1310
  console.log(
1306
1311
  chalk.redBright(
1307
1312
  `DX Component Builder - SDK requires node v20.15.0 or greater, current version: ${process.version}`
@@ -1316,24 +1321,24 @@ export const showVersion = async () => {
1316
1321
 
1317
1322
  };
1318
1323
 
1319
- export const checkForBranch = async(rulesetName) => {
1324
+ export const checkForBranch = async (rulesetName) => {
1320
1325
  if (rulesetName === "") {
1321
1326
  const serverConfig = await getPegaServerConfig();
1322
1327
  rulesetName = serverConfig.rulesetName;
1323
1328
  }
1324
1329
 
1325
1330
  if (rulesetName.toLowerCase().indexOf("_branch") >= 0) {
1326
- console.log(
1331
+ console.log(
1327
1332
  chalk.redBright(
1328
1333
  `Ruleset ${chalk.bold(`${rulesetName}`)} cannot be a branch ruleset.`
1329
1334
  )
1330
1335
  );
1331
1336
  process.exit(1);
1332
1337
  }
1333
- }
1338
+ };
1334
1339
 
1335
1340
  export const getOOTBComponents = async () => {
1336
- if (showDebug) addDebugLog("getOOTBComponents", "", "");
1341
+ if (showDebug) addDebugLog("getOOTBComponents", "", "");
1337
1342
  return new Promise(resolve => {
1338
1343
  fs.readFile(OOTB_COMPONENTS, 'utf-8', async (error, ootbComponentsData) => {
1339
1344
  if (error) {
@@ -1386,7 +1391,7 @@ if (showDebug) addDebugLog("getOOTBComponents", "", "");
1386
1391
  };
1387
1392
 
1388
1393
  export const deleteInfinityServerComponent = async componentKey => {
1389
- if (showDebug) addDebugLog("deleteInfinityServerComponent", `componentKey: ${componentKey}`, "");
1394
+ if (showDebug) addDebugLog("deleteInfinityServerComponent", `componentKey: ${componentKey}`, "");
1390
1395
  const serverConfig = await getPegaServerConfig();
1391
1396
  const { server } = serverConfig;
1392
1397
  const url = constructCompleteUrl(server, DELETE_COMPONENT_SERVICE_REST_ENDPOINT);
@@ -1417,13 +1422,13 @@ if (showDebug) addDebugLog("deleteInfinityServerComponent", `componentKey: ${com
1417
1422
  // console.log(accessTokenUri, refreshToken);
1418
1423
  /* TODO - Handle refresh_token */
1419
1424
  }
1420
- else if (status === 404){
1425
+ else if (status === 404) {
1421
1426
  throw new Error('404: Server resource not found');
1422
1427
  }
1423
- else if (status === 405){
1428
+ else if (status === 405) {
1424
1429
  throw new Error('405: Server method not allowed');
1425
1430
  }
1426
- else if (status === 408){
1431
+ else if (status === 408) {
1427
1432
  throw new Error('408: Server timed out');
1428
1433
  }
1429
1434
  else if (response.status === 403) {
@@ -1438,7 +1443,7 @@ if (showDebug) addDebugLog("deleteInfinityServerComponent", `componentKey: ${com
1438
1443
  try {
1439
1444
  const respData = await response.json();
1440
1445
  console.log(
1441
- chalk.bold.green(`Success : ${respData.message}`)
1446
+ chalk.bold.green(`Success : ${respData.message}`)
1442
1447
  );
1443
1448
 
1444
1449
  if (status === 500) {
@@ -1448,12 +1453,12 @@ if (showDebug) addDebugLog("deleteInfinityServerComponent", `componentKey: ${com
1448
1453
  }
1449
1454
  catch (err) {
1450
1455
  if (status === 500) {
1451
- throw new Error(
1452
- `Error occurred in authentication. Please regenerate using authenticate`
1453
- );
1456
+ throw new Error(
1457
+ `Error occurred in authentication. Please regenerate using authenticate`
1458
+ );
1454
1459
  }
1455
1460
  else if (status === 999) {
1456
- throw new Error (err);
1461
+ throw new Error(err);
1457
1462
  }
1458
1463
  }
1459
1464
 
@@ -1465,7 +1470,7 @@ if (showDebug) addDebugLog("deleteInfinityServerComponent", `componentKey: ${com
1465
1470
  };
1466
1471
 
1467
1472
  export const deleteInfinityServerComponentLibrary = async (libraryName, rulesetName, rulesetVersion) => {
1468
- if (showDebug) addDebugLog("deleteInfinityServerComponentLibrary", `componentKey: ${componentKey}, rulesetName: ${rulesetName}, rulesetVersion: ${rulesetVersion}`, "");
1473
+ if (showDebug) addDebugLog("deleteInfinityServerComponentLibrary", `componentKey: ${componentKey}, rulesetName: ${rulesetName}, rulesetVersion: ${rulesetVersion}`, "");
1469
1474
  const serverConfig = await getPegaServerConfig();
1470
1475
  const { server } = serverConfig;
1471
1476
  const url = constructCompleteUrl(server, DELETE_COMPONENT_LIBRARY_SERVICE_REST_ENDPOINT);
@@ -1502,13 +1507,13 @@ if (showDebug) addDebugLog("deleteInfinityServerComponentLibrary", `componentKey
1502
1507
  // console.log(accessTokenUri, refreshToken);
1503
1508
  /* TODO - Handle refresh_token */
1504
1509
  }
1505
- else if (status === 404){
1510
+ else if (status === 404) {
1506
1511
  throw new Error('404: Server resource not found');
1507
1512
  }
1508
- else if (status === 405){
1513
+ else if (status === 405) {
1509
1514
  throw new Error('405: Server method not allowed');
1510
1515
  }
1511
- else if (status === 408){
1516
+ else if (status === 408) {
1512
1517
  throw new Error('408: Server timed out');
1513
1518
  }
1514
1519
  else if (response.status === 403) {
@@ -1537,12 +1542,12 @@ if (showDebug) addDebugLog("deleteInfinityServerComponentLibrary", `componentKey
1537
1542
  }
1538
1543
  catch (err) {
1539
1544
  if (status === 500) {
1540
- throw new Error(
1541
- `Error occurred in authentication. Please regenerate using authenticate`
1542
- );
1545
+ throw new Error(
1546
+ `Error occurred in authentication. Please regenerate using authenticate`
1547
+ );
1543
1548
  }
1544
1549
  else if (status === 999) {
1545
- throw new Error (err);
1550
+ throw new Error(err);
1546
1551
  }
1547
1552
  }
1548
1553
 
@@ -1555,7 +1560,7 @@ if (showDebug) addDebugLog("deleteInfinityServerComponentLibrary", `componentKey
1555
1560
 
1556
1561
 
1557
1562
  export const deleteLaunchpadServerComponent = async componentKey => {
1558
- if (showDebug) addDebugLog("deleteLaunchpadServerComponent", `componentKey: ${componentKey}`, "");
1563
+ if (showDebug) addDebugLog("deleteLaunchpadServerComponent", `componentKey: ${componentKey}`, "");
1559
1564
  const { server, isolationId } = await getPegaServerConfig();
1560
1565
  const deleteUrl = constructCompleteUrl(
1561
1566
  server,
@@ -1599,13 +1604,13 @@ if (showDebug) addDebugLog("deleteLaunchpadServerComponent", `componentKey: ${co
1599
1604
  // console.log(accessTokenUri, refreshToken);
1600
1605
  /* TODO - Handle refresh_token */
1601
1606
  }
1602
- else if (status === 404){
1607
+ else if (status === 404) {
1603
1608
  throw new Error('404: Server resource not found');
1604
1609
  }
1605
- else if (status === 405){
1610
+ else if (status === 405) {
1606
1611
  throw new Error('405: Server method not allowed');
1607
1612
  }
1608
- else if (status === 408){
1613
+ else if (status === 408) {
1609
1614
  throw new Error('408: Server timed out');
1610
1615
  }
1611
1616
  else if (response.status === 403) {
@@ -1618,7 +1623,7 @@ if (showDebug) addDebugLog("deleteLaunchpadServerComponent", `componentKey: ${co
1618
1623
  try {
1619
1624
  const respData = await response.text();
1620
1625
  console.log(
1621
- chalk.bold.green(`Success : ${respData}`)
1626
+ chalk.bold.green(`Success : ${respData}`)
1622
1627
  );
1623
1628
 
1624
1629
  if (status === 500) {
@@ -1628,12 +1633,12 @@ if (showDebug) addDebugLog("deleteLaunchpadServerComponent", `componentKey: ${co
1628
1633
  }
1629
1634
  catch (err) {
1630
1635
  if (status === 500) {
1631
- throw new Error(
1632
- `Error occurred in authentication. Please regenerate using authenticate`
1633
- );
1636
+ throw new Error(
1637
+ `Error occurred in authentication. Please regenerate using authenticate`
1638
+ );
1634
1639
  }
1635
1640
  else if (status === 999) {
1636
- throw new Error (err);
1641
+ throw new Error(err);
1637
1642
  }
1638
1643
  }
1639
1644
  }
@@ -1643,7 +1648,7 @@ if (showDebug) addDebugLog("deleteLaunchpadServerComponent", `componentKey: ${co
1643
1648
  };
1644
1649
 
1645
1650
  export const getBootstrapConfig = async (restServerUrl, authorizationHeader) => {
1646
- if (showDebug) addDebugLog("getBootstrapConfig", `restServerUrl: ${restServerUrl}`, "");
1651
+ if (showDebug) addDebugLog("getBootstrapConfig", `restServerUrl: ${restServerUrl}`, "");
1647
1652
  const serverConfig = await getPegaServerConfig();
1648
1653
 
1649
1654
  return fetch(`${restServerUrl}/${BOOTSTRAP_CONFIG}`, {
@@ -1661,7 +1666,7 @@ if (showDebug) addDebugLog("getBootstrapConfig", `restServerUrl: ${restServerUrl
1661
1666
  };
1662
1667
 
1663
1668
  export const updateC11NB2SForInfinity = async () => {
1664
- if (showDebug) addDebugLog("updateC11NB2SForInfinity", "", "");
1669
+ if (showDebug) addDebugLog("updateC11NB2SForInfinity", "", "");
1665
1670
  const serverConfig = await getPegaServerConfig();
1666
1671
  const { server } = serverConfig;
1667
1672
  const OAuthData = fs.readFileSync(TOKEN_PATH, 'utf8');
@@ -1680,7 +1685,7 @@ if (showDebug) addDebugLog("updateC11NB2SForInfinity", "", "");
1680
1685
  objOauthData["appStaticContentServer"] = (bootstrap.serviceConfig.appStaticContentServer != "no-cdn" && bootstrap.serviceConfig.appStaticContentServer != "") ? bootstrap.serviceConfig.appStaticContentServer : bootstrap.serviceConfig.staticContentServer;
1681
1686
 
1682
1687
  // write out file
1683
- fs.writeFileSync(TOKEN_PATH, JSON.stringify(objOauthData), { encoding: 'utf8',flag:'w' });
1688
+ fs.writeFileSync(TOKEN_PATH, JSON.stringify(objOauthData), { encoding: 'utf8', flag: 'w' });
1684
1689
  }
1685
1690
 
1686
1691
  }
@@ -1693,7 +1698,7 @@ export const updateC11NB2SForLaunchpad = async () => {
1693
1698
  };
1694
1699
 
1695
1700
  export const getC11NB2STokenAndStaticServer = async () => {
1696
- if (showDebug) addDebugLog("getC11NB2STokenAndStaticServer", "", "");
1701
+ if (showDebug) addDebugLog("getC11NB2STokenAndStaticServer", "", "");
1697
1702
  const serverConfig = await getPegaServerConfig();
1698
1703
  const { server } = serverConfig;
1699
1704
  let OAuthData;
@@ -1705,28 +1710,28 @@ if (showDebug) addDebugLog("getC11NB2STokenAndStaticServer", "", "");
1705
1710
  }
1706
1711
 
1707
1712
  if (OAuthData) {
1708
- const { C11NB2S, appStaticContentServer, access_token } = JSON.parse(OAuthData)
1713
+ const { C11NB2S, appStaticContentServer, access_token } = JSON.parse(OAuthData);
1709
1714
 
1710
- return ({ C11NB2S, appStaticContentServer, access_token});
1715
+ return ({ C11NB2S, appStaticContentServer, access_token });
1711
1716
 
1712
1717
  }
1713
1718
  return ({});
1714
1719
  };
1715
1720
 
1716
1721
  export const getLocalLibraries = async () => {
1717
- if (showDebug) addDebugLog("getLocalLibraries", "" , "");
1722
+ if (showDebug) addDebugLog("getLocalLibraries", "", "");
1718
1723
  const currentDirectory = process.cwd();
1719
1724
  const configDef = getConfigDefaults();
1720
1725
  const libFilter = configDef.organization.concat("_");
1721
1726
 
1722
1727
  return fs
1723
- .readdirSync(currentDirectory, { withFileTypes: true })
1724
- .filter(dirent => dirent.isDirectory() && dirent.name.startsWith(libFilter))
1725
- .map(dirent => dirent.name);
1726
- }
1728
+ .readdirSync(currentDirectory, { withFileTypes: true })
1729
+ .filter(dirent => dirent.isDirectory() && dirent.name.startsWith(libFilter))
1730
+ .map(dirent => dirent.name);
1731
+ };
1727
1732
 
1728
1733
  export const getLocalLibraryVersions = async (libraryName, currentVersion = "0.0.0") => {
1729
- if (showDebug) addDebugLog("getLocalLibraryVersions", `libraryName: ${libraryName}` , "");
1734
+ if (showDebug) addDebugLog("getLocalLibraryVersions", `libraryName: ${libraryName}`, "");
1730
1735
  const currentDirectory = process.cwd();
1731
1736
 
1732
1737
  const directory = join(currentDirectory, libraryName);
@@ -1737,9 +1742,9 @@ if (showDebug) addDebugLog("getLocalLibraryVersions", `libraryName: ${libraryNam
1737
1742
  };
1738
1743
 
1739
1744
  export const getLocalArchivedLibraryVersions = async (libraryName, currentVersion = "0.0.0") => {
1740
- if (showDebug) addDebugLog("getLocalArchivedLibraryVersions", `libraryName: ${libraryName}` , "");
1745
+ if (showDebug) addDebugLog("getLocalArchivedLibraryVersions", `libraryName: ${libraryName}`, "");
1741
1746
  const currentDirectory = process.cwd();
1742
- const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, `${libraryName}`);
1747
+ const archiveDirectory = join(currentDirectory, ARCHIVES_PATH, `${libraryName}`);
1743
1748
 
1744
1749
  return fs
1745
1750
  .readdirSync(archiveDirectory, { withFileTypes: true })
@@ -1747,31 +1752,31 @@ if (showDebug) addDebugLog("getLocalArchivedLibraryVersions", `libraryName: ${li
1747
1752
  .map(dirent => dirent.name);
1748
1753
  };
1749
1754
 
1750
- export const getLocalArchivedLibrraryVersionData = async(libraryName, libraryVersion) => {
1751
- if (showDebug) addDebugLog("getLocalArchivedLibrraryVersionData", `libraryName: ${libraryName}, libraryVersion: ${libraryVersion}`, "");
1755
+ export const getLocalArchivedLibrraryVersionData = async (libraryName, libraryVersion) => {
1756
+ if (showDebug) addDebugLog("getLocalArchivedLibrraryVersionData", `libraryName: ${libraryName}, libraryVersion: ${libraryVersion}`, "");
1752
1757
  const currentDirectory = process.cwd();
1753
- const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, `${libraryName}`, `${libraryVersion}`);
1758
+ const archiveDirectory = join(currentDirectory, ARCHIVES_PATH, `${libraryName}`, `${libraryVersion}`);
1754
1759
 
1755
- const componentConfigFile = join (archiveDirectory, COMPONENTS_CONFIG_FILE_NAME);
1760
+ const componentConfigFile = join(archiveDirectory, COMPONENTS_CONFIG_FILE_NAME);
1756
1761
 
1757
- let data = fs.readFileSync(componentConfigFile, { encoding: 'utf8' })
1762
+ let data = fs.readFileSync(componentConfigFile, { encoding: 'utf8' });
1758
1763
 
1759
1764
  return data;
1760
- }
1765
+ };
1761
1766
 
1762
1767
  export const getLocalLibraryVersionData = async (libraryName, libraryVersion) => {
1763
- if (showDebug) addDebugLog("getLocalLibraryVersionDate", `libraryName: ${libraryName}, libraryVersion: ${libraryVersion}` , "");
1764
- const currentDirectory = process.cwd();
1765
- const libDir = join(currentDirectory, libraryName, libraryVersion);
1766
- const libDataFile = join(libDir, COMPONENTS_CONFIG_FILE_NAME);
1768
+ if (showDebug) addDebugLog("getLocalLibraryVersionDate", `libraryName: ${libraryName}, libraryVersion: ${libraryVersion}`, "");
1769
+ const currentDirectory = process.cwd();
1770
+ const libDir = join(currentDirectory, libraryName, libraryVersion);
1771
+ const libDataFile = join(libDir, COMPONENTS_CONFIG_FILE_NAME);
1767
1772
 
1768
- let data = fs.readFileSync(libDataFile, { encoding: 'utf8' })
1773
+ let data = fs.readFileSync(libDataFile, { encoding: 'utf8' });
1769
1774
 
1770
- return data;
1775
+ return data;
1771
1776
  };
1772
1777
 
1773
1778
  export const deleteLocalLibrary = async (libraryName) => {
1774
- if (showDebug) addDebugLog("deleteLocalLibrary", `libraryName: ${libraryName}` , "");
1779
+ if (showDebug) addDebugLog("deleteLocalLibrary", `libraryName: ${libraryName}`, "");
1775
1780
  const currentDirectory = process.cwd();
1776
1781
 
1777
1782
  const directory = join(currentDirectory, libraryName);
@@ -1800,7 +1805,7 @@ if (showDebug) addDebugLog("deleteLocalLibrary", `libraryName: ${libraryName}` ,
1800
1805
  };
1801
1806
 
1802
1807
  export const deleteLocalLibraryVersion = async (libraryName, libraryVersion) => {
1803
- if (showDebug) addDebugLog("getLocalLibraryVersions", `libraryName: ${libraryName}, libraryVersion: ${libraryVersion}` , "");
1808
+ if (showDebug) addDebugLog("getLocalLibraryVersions", `libraryName: ${libraryName}, libraryVersion: ${libraryVersion}`, "");
1804
1809
  const currentDirectory = process.cwd();
1805
1810
 
1806
1811
  const directory = join(currentDirectory, libraryName, libraryVersion);
@@ -1808,7 +1813,7 @@ if (showDebug) addDebugLog("getLocalLibraryVersions", `libraryName: ${libraryNam
1808
1813
  try {
1809
1814
  if (fs.existsSync(directory)) {
1810
1815
  console.log(`Deleting library version: ${chalk.green.bold(libraryName)}:${chalk.green.bold(libraryVersion)}`);
1811
- fs.rmSync(directory, { recursive: true, force: true, maxRetries: 2 });
1816
+ fs.rmSync(directory, { recursive: true, force: true, maxRetries: 2 });
1812
1817
  console.log(`Library version: ${chalk.green.bold(libraryName)}:${chalk.green.bold(libraryVersion)} is deleted from Local`);
1813
1818
  }
1814
1819
  else {
@@ -1823,7 +1828,7 @@ if (showDebug) addDebugLog("getLocalLibraryVersions", `libraryName: ${libraryNam
1823
1828
  };
1824
1829
 
1825
1830
  export const deletePublishExtras = async (libraryName, libraryVersion) => {
1826
- if (showDebug) addDebugLog("deletePublishExtras", `libraryName: ${libraryName}, libraryVersion: ${libraryVersion}` , "");
1831
+ if (showDebug) addDebugLog("deletePublishExtras", `libraryName: ${libraryName}, libraryVersion: ${libraryVersion}`, "");
1827
1832
  // this function will delete LibraryName.zip file, so new one created by publish
1828
1833
  // check if .DS_store file exists in Library, if so delete it because causes issue with services
1829
1834
 
@@ -1847,7 +1852,7 @@ if (showDebug) addDebugLog("deletePublishExtras", `libraryName: ${libraryName},
1847
1852
 
1848
1853
 
1849
1854
  export const cleanUp = async () => {
1850
- if (showDebug) addDebugLog("cleanUp", "", "");
1855
+ if (showDebug) addDebugLog("cleanUp", "", "");
1851
1856
  if (fs.existsSync('dist/components')) {
1852
1857
  fs.rm('dist/components', { recursive: true }, err => {
1853
1858
  if (err) {
@@ -1867,7 +1872,7 @@ if (showDebug) addDebugLog("cleanUp", "", "");
1867
1872
  };
1868
1873
 
1869
1874
  export const getComponentsConfigs = async (compDir = null) => {
1870
- if (showDebug) addDebugLog("getComponentsConfigs", "", "");
1875
+ if (showDebug) addDebugLog("getComponentsConfigs", "", "");
1871
1876
  const componentsList = await getComponents(compDir);
1872
1877
 
1873
1878
  let componentsConfigJSON = [];
@@ -1889,22 +1894,22 @@ if (showDebug) addDebugLog("getComponentsConfigs", "", "");
1889
1894
  }
1890
1895
  }
1891
1896
  return componentsConfigJSON;
1892
- }
1897
+ };
1893
1898
 
1894
1899
 
1895
1900
  export const createComponentsConfigFile = async (filePath, compDir) => {
1896
- if (showDebug) addDebugLog("createComponentsConfigFile", `filePath: ${filePath}`, "");
1901
+ if (showDebug) addDebugLog("createComponentsConfigFile", `filePath: ${filePath}`, "");
1897
1902
  const componentsConfigJSON = await getComponentsConfigs(compDir);
1898
1903
  const compConfgFile = join(filePath, COMPONENTS_CONFIG_FILE_NAME);
1899
1904
 
1900
1905
  // write out file
1901
- fs.writeFileSync(compConfgFile, JSON.stringify(componentsConfigJSON), { encoding: 'utf8',flag:'w' });
1906
+ fs.writeFileSync(compConfgFile, JSON.stringify(componentsConfigJSON), { encoding: 'utf8', flag: 'w' });
1902
1907
 
1903
1908
  };
1904
1909
 
1905
1910
 
1906
1911
  export const zipVersionAndArchive = async (orgLibName, version, currentDirectory = "") => {
1907
- if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, version: ${version}`, "");
1912
+ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, version: ${version}`, "");
1908
1913
  // const srcDirectoryPath = await getSrcDirectoryPath();
1909
1914
  if (currentDirectory === "") {
1910
1915
  currentDirectory = process.cwd();
@@ -1917,7 +1922,7 @@ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, v
1917
1922
 
1918
1923
  // const configContent = Buffer.from(fs.readFileSync(configJson)).toString();
1919
1924
  const mainDirectory = process.cwd();
1920
- const archiveDirectory = join (mainDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
1925
+ const archiveDirectory = join(mainDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
1921
1926
  if (!fs.existsSync(archiveDirectory)) {
1922
1927
  fs.mkdirSync(archiveDirectory, { recursive: true });
1923
1928
  }
@@ -1956,13 +1961,13 @@ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, v
1956
1961
  // pipe archive data to the file
1957
1962
  archive.pipe(output);
1958
1963
 
1959
- output.on('end', function() {
1964
+ output.on('end', function () {
1960
1965
  console.log('Data has been drained');
1961
1966
  });
1962
1967
 
1963
1968
 
1964
1969
  // good practice to catch warnings (ie stat failures and other non-blocking errors)
1965
- archive.on('warning', function(err) {
1970
+ archive.on('warning', function (err) {
1966
1971
  if (err.code === 'ENOENT') {
1967
1972
  // log warning
1968
1973
  } else {
@@ -1972,7 +1977,7 @@ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, v
1972
1977
  });
1973
1978
 
1974
1979
  // good practice to catch this error explicitly
1975
- archive.on('error', function(err) {
1980
+ archive.on('error', function (err) {
1976
1981
  throw err;
1977
1982
  });
1978
1983
 
@@ -1986,7 +1991,7 @@ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, v
1986
1991
 
1987
1992
 
1988
1993
  export const zipVersionAndArchiveAndReturnBuffer = async (orgLibName, version, currentDirectory = "") => {
1989
- if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, version: ${version}`, "");
1994
+ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, version: ${version}`, "");
1990
1995
  // const srcDirectoryPath = await getSrcDirectoryPath();
1991
1996
  if (currentDirectory === "") {
1992
1997
  currentDirectory = process.cwd();
@@ -1999,7 +2004,7 @@ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, v
1999
2004
 
2000
2005
  // const configContent = Buffer.from(fs.readFileSync(configJson)).toString();
2001
2006
  const mainDirectory = process.cwd();
2002
- const archiveDirectory = join (mainDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
2007
+ const archiveDirectory = join(mainDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
2003
2008
  if (!fs.existsSync(archiveDirectory)) {
2004
2009
  fs.mkdirSync(archiveDirectory, { recursive: true });
2005
2010
  }
@@ -2039,13 +2044,13 @@ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, v
2039
2044
  // pipe archive data to the file
2040
2045
  archive.pipe(output);
2041
2046
 
2042
- output.on('end', function() {
2047
+ output.on('end', function () {
2043
2048
  console.log('Data has been drained');
2044
2049
  });
2045
2050
 
2046
2051
 
2047
2052
  // good practice to catch warnings (ie stat failures and other non-blocking errors)
2048
- archive.on('warning', function(err) {
2053
+ archive.on('warning', function (err) {
2049
2054
  if (err.code === 'ENOENT') {
2050
2055
  // log warning
2051
2056
  } else {
@@ -2055,7 +2060,7 @@ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, v
2055
2060
  });
2056
2061
 
2057
2062
  // good practice to catch this error explicitly
2058
- archive.on('error', function(err) {
2063
+ archive.on('error', function (err) {
2059
2064
  throw err;
2060
2065
  });
2061
2066
 
@@ -2064,19 +2069,19 @@ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, v
2064
2069
  const zipBuffer = Buffer.concat(zipChunks);
2065
2070
  const zipContent = zipBuffer.toString('base64');
2066
2071
 
2067
- return { output, zipContent};
2072
+ return { output, zipContent };
2068
2073
 
2069
2074
  };
2070
2075
 
2071
- export const zipUnArchiveToTempAndReturnBuffer = async(orgLibName, version) => {
2076
+ export const zipUnArchiveToTempAndReturnBuffer = async (orgLibName, version) => {
2072
2077
 
2073
2078
  // unarchive to temp
2074
2079
  const currentDirectory = process.cwd();
2075
- const tempDirectory = join (currentDirectory, TEMP_PATH);
2080
+ const tempDirectory = join(currentDirectory, TEMP_PATH);
2076
2081
  const srcDirectoryPath = join(tempDirectory, "src");
2077
2082
 
2078
2083
  const archiveFileName = `${orgLibName}_${version}.arch.zip`;
2079
- const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
2084
+ const archiveDirectory = join(currentDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
2080
2085
  const archFileName = join(archiveDirectory, archiveFileName);
2081
2086
 
2082
2087
  await unZipFromArchive(archFileName);
@@ -2110,13 +2115,13 @@ export const zipUnArchiveToTempAndReturnBuffer = async(orgLibName, version) => {
2110
2115
  // pipe archive data to the file
2111
2116
  archive.pipe(output);
2112
2117
 
2113
- output.on('end', function() {
2118
+ output.on('end', function () {
2114
2119
  console.log('Data has been drained');
2115
2120
  });
2116
2121
 
2117
2122
 
2118
2123
  // good practice to catch warnings (ie stat failures and other non-blocking errors)
2119
- archive.on('warning', function(err) {
2124
+ archive.on('warning', function (err) {
2120
2125
  if (err.code === 'ENOENT') {
2121
2126
  // log warning
2122
2127
  } else {
@@ -2126,7 +2131,7 @@ export const zipUnArchiveToTempAndReturnBuffer = async(orgLibName, version) => {
2126
2131
  });
2127
2132
 
2128
2133
  // good practice to catch this error explicitly
2129
- archive.on('error', function(err) {
2134
+ archive.on('error', function (err) {
2130
2135
  throw err;
2131
2136
  });
2132
2137
 
@@ -2135,13 +2140,13 @@ export const zipUnArchiveToTempAndReturnBuffer = async(orgLibName, version) => {
2135
2140
  const zipBuffer = Buffer.concat(zipChunks);
2136
2141
  const zipContent = zipBuffer.toString('base64');
2137
2142
 
2138
- return { output, zipContent};
2143
+ return { output, zipContent };
2139
2144
 
2140
2145
 
2141
- }
2146
+ };
2142
2147
 
2143
2148
  export const zipVersionAndArchiveCL = async (orgLibName, version, currentDirectory = "") => {
2144
- if (showDebug) addDebugLog("zipVersionAndArchiveCL", `orgLibName: ${orgLibName}, version: ${version}, currentDirectory: ${currentDirectory}`, "");
2149
+ if (showDebug) addDebugLog("zipVersionAndArchiveCL", `orgLibName: ${orgLibName}, version: ${version}, currentDirectory: ${currentDirectory}`, "");
2145
2150
  // const srcDirectoryPath = await getSrcDirectoryPath();
2146
2151
  if (currentDirectory === "") {
2147
2152
  currentDirectory = process.cwd();
@@ -2154,7 +2159,7 @@ if (showDebug) addDebugLog("zipVersionAndArchiveCL", `orgLibName: ${orgLibName},
2154
2159
 
2155
2160
  // const configContent = Buffer.from(fs.readFileSync(configJson)).toString();
2156
2161
  const mainDirectory = process.cwd();
2157
- const archiveDirectory = join (mainDirectory, BIN_ARCHIVES_PATH);
2162
+ const archiveDirectory = join(mainDirectory, BIN_ARCHIVES_PATH);
2158
2163
  if (!fs.existsSync(archiveDirectory)) {
2159
2164
  fs.mkdirSync(archiveDirectory, { recursive: true });
2160
2165
  }
@@ -2180,13 +2185,13 @@ if (showDebug) addDebugLog("zipVersionAndArchiveCL", `orgLibName: ${orgLibName},
2180
2185
  // pipe archive data to the file
2181
2186
  archive.pipe(output);
2182
2187
 
2183
- output.on('end', function() {
2188
+ output.on('end', function () {
2184
2189
  console.log('Data has been drained');
2185
2190
  });
2186
2191
 
2187
2192
 
2188
2193
  // good practice to catch warnings (ie stat failures and other non-blocking errors)
2189
- archive.on('warning', function(err) {
2194
+ archive.on('warning', function (err) {
2190
2195
  if (err.code === 'ENOENT') {
2191
2196
  // log warning
2192
2197
  } else {
@@ -2196,7 +2201,7 @@ if (showDebug) addDebugLog("zipVersionAndArchiveCL", `orgLibName: ${orgLibName},
2196
2201
  });
2197
2202
 
2198
2203
  // good practice to catch this error explicitly
2199
- archive.on('error', function(err) {
2204
+ archive.on('error', function (err) {
2200
2205
  throw err;
2201
2206
  });
2202
2207
 
@@ -2207,45 +2212,49 @@ if (showDebug) addDebugLog("zipVersionAndArchiveCL", `orgLibName: ${orgLibName},
2207
2212
  };
2208
2213
 
2209
2214
  export const unZipFromArchive = async (fileName) => {
2210
- if (showDebug) addDebugLog("unZipFromArchive", `fileName: ${fileName}`, "");
2215
+ if (showDebug) addDebugLog("unZipFromArchive", `fileName: ${fileName}`, "");
2211
2216
  await unarchive(fileName, TEMP_PATH);
2212
2217
  };
2213
2218
 
2214
2219
 
2215
2220
 
2216
2221
  export const updateComponentTaskConfig = async () => {
2217
- if (showDebug) addDebugLog("updateComponentTaskConfig", "", "");
2222
+ if (showDebug) addDebugLog("updateComponentTaskConfig", "", "");
2218
2223
  const currentDirectory = process.cwd();
2219
2224
  const tempDirectory = join(currentDirectory, TEMP_PATH);
2220
2225
 
2221
- const tempConfigPath = join(tempDirectory, TASKS_CONFIG_JSON_FILENAME);
2222
2226
  const currentConfigPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
2223
-
2224
- const contents = fs.readFileSync(tempConfigPath);
2225
2227
  const originalContents = fs.readFileSync(currentConfigPath);
2226
2228
 
2227
- let contentsData = JSON.parse(contents);
2229
+ // was previously stored in
2230
+ let contentsData = await getPegaConfig();
2231
+
2228
2232
  let originalContentsData = JSON.parse(originalContents);
2233
+ const orgRuleset = originalContentsData["server-config"].rulesetName;
2234
+ const orgRulesetVersion = originalContentsData["server-config"].rulesetVersion;
2235
+
2236
+ // we keep server-config but we will restore from archive the
2237
+ // rulset/version. Other stuff in task.config will come from archive
2238
+ originalContentsData["server-config"] = contentsData["server-config"];
2239
+ // restore ruleset and verion
2240
+ originalContentsData["server-config"].rulesetName = orgRuleset;
2241
+ originalContentsData["server-config"].rulesetVersion = orgRulesetVersion;
2229
2242
 
2230
- // only copy "components" from archived task.config and "devBuild"
2231
- // that way, your current tasks.config isn't messed up
2232
- originalContentsData["server-config"].devBuild = contentsData["server-config"].devBuild;
2233
- originalContentsData["component"] = contentsData["component"];
2234
2243
 
2235
2244
  // if we don't have a devServerPort, add the default
2236
2245
  if (originalContentsData["server-config"].devServerPort === undefined) {
2237
- originalContentsData["server-config"].devServerPort = "3030"
2246
+ originalContentsData["server-config"].devServerPort = "3030";
2238
2247
  }
2239
2248
 
2240
- fs.writeFileSync(currentConfigPath, JSON.stringify(originalContentsData, null, 4), { encoding: 'utf8',flag:'w' });
2249
+ fs.writeFileSync(currentConfigPath, JSON.stringify(originalContentsData, null, 4), { encoding: 'utf8', flag: 'w' });
2241
2250
 
2242
- }
2251
+ };
2243
2252
 
2244
2253
  export const restoreDependenciesFromPackage = async () => {
2245
- if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
2254
+ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
2246
2255
  const currentDirectory = process.cwd();
2247
2256
  const tempDirectory = join(currentDirectory, TEMP_PATH);
2248
- const tempPackagePath = join (tempDirectory, PACKAGE_JSON_FILENAME);
2257
+ const tempPackagePath = join(tempDirectory, PACKAGE_JSON_FILENAME);
2249
2258
  const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
2250
2259
 
2251
2260
  let retrievedPackageData;
@@ -2258,7 +2267,7 @@ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
2258
2267
  retrievedPackageData = fs.readFileSync(tempPackagePath);
2259
2268
  }
2260
2269
  catch (ex) {
2261
- console.log(chalk.red(`\nUnable to retrieve package.json from store.`))
2270
+ console.log(chalk.red(`\nUnable to retrieve package.json from store.`));
2262
2271
  process.exit(1);
2263
2272
  }
2264
2273
 
@@ -2266,7 +2275,7 @@ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
2266
2275
  currentPackageData = fs.readFileSync(currentPackagePath);
2267
2276
  }
2268
2277
  catch (ex) {
2269
- console.log(chalk.red(`\nUnable to retrieve current package.json.`))
2278
+ console.log(chalk.red(`\nUnable to retrieve current package.json.`));
2270
2279
  process.exit(1);
2271
2280
  }
2272
2281
 
@@ -2304,7 +2313,7 @@ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
2304
2313
  retrievedTemplateData = fs.readFileSync(packageTemplateJsonPath);
2305
2314
  }
2306
2315
  catch (ex) {
2307
- console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`))
2316
+ console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`));
2308
2317
  process.exit(1);
2309
2318
  }
2310
2319
  const tData = JSON.parse(retrievedTemplateData);
@@ -2326,167 +2335,167 @@ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
2326
2335
 
2327
2336
 
2328
2337
  // update current package json file
2329
- fs.writeFileSync(currentPackagePath, JSON.stringify(rData, null, 4), { encoding: 'utf8',flag:'w' });
2338
+ fs.writeFileSync(currentPackagePath, JSON.stringify(rData, null, 4), { encoding: 'utf8', flag: 'w' });
2330
2339
 
2331
2340
 
2332
- }
2341
+ };
2333
2342
 
2334
2343
 
2335
2344
  export const restoreDependenciesFromTemplate = async () => {
2336
2345
  if (showDebug) addDebugLog("restoreDependenciesFromTemplate", "", "");
2337
- const currentDirectory = process.cwd();
2338
- const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
2346
+ const currentDirectory = process.cwd();
2347
+ const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
2339
2348
 
2340
- let currentPackageData;
2349
+ let currentPackageData;
2341
2350
 
2342
- // reset
2343
- haveDependencyDifference = true;
2351
+ // reset
2352
+ haveDependencyDifference = true;
2344
2353
 
2345
- try {
2346
- currentPackageData = fs.readFileSync(currentPackagePath);
2347
- }
2348
- catch (ex) {
2349
- console.log(chalk.red(`\nUnable to retrieve current package.json.`))
2350
- process.exit(1);
2351
- }
2354
+ try {
2355
+ currentPackageData = fs.readFileSync(currentPackagePath);
2356
+ }
2357
+ catch (ex) {
2358
+ console.log(chalk.red(`\nUnable to retrieve current package.json.`));
2359
+ process.exit(1);
2360
+ }
2352
2361
 
2353
2362
 
2354
- let cData = JSON.parse(currentPackageData);
2363
+ let cData = JSON.parse(currentPackageData);
2355
2364
 
2356
2365
 
2357
- // we can't loose devDep that is part of install, so go get the template mustache and push
2358
- // those in, replacing any changes there, but allowing additional, an keeping it updated
2359
- // so won't loose new function if an old archive
2360
- const initDir = join(currentDirectory, "node_modules", "@pega", "custom-dx-components", "src", "tasks", "init");
2361
- const templateDir = join(initDir, "template");
2362
- const packageTemplateJsonPath = path.join(templateDir, 'package.json.mustache');
2363
- let retrievedTemplateData;
2364
- try {
2365
- retrievedTemplateData = fs.readFileSync(packageTemplateJsonPath);
2366
- }
2367
- catch (ex) {
2368
- console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`))
2369
- process.exit(1);
2370
- }
2371
- const tData = JSON.parse(retrievedTemplateData);
2372
- const tDevDep = tData.devDependencies;
2373
- const tDep = tData.dependencies;
2366
+ // we can't loose devDep that is part of install, so go get the template mustache and push
2367
+ // those in, replacing any changes there, but allowing additional, an keeping it updated
2368
+ // so won't loose new function if an old archive
2369
+ const initDir = join(currentDirectory, "node_modules", "@pega", "custom-dx-components", "src", "tasks", "init");
2370
+ const templateDir = join(initDir, "template");
2371
+ const packageTemplateJsonPath = path.join(templateDir, 'package.json.mustache');
2372
+ let retrievedTemplateData;
2373
+ try {
2374
+ retrievedTemplateData = fs.readFileSync(packageTemplateJsonPath);
2375
+ }
2376
+ catch (ex) {
2377
+ console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`));
2378
+ process.exit(1);
2379
+ }
2380
+ const tData = JSON.parse(retrievedTemplateData);
2381
+ const tDevDep = tData.devDependencies;
2382
+ const tDep = tData.dependencies;
2374
2383
 
2375
- for (const [key, value] of Object.entries(tDevDep)) {
2376
- cData.devDependencies[key] = value;
2377
- }
2384
+ for (const [key, value] of Object.entries(tDevDep)) {
2385
+ cData.devDependencies[key] = value;
2386
+ }
2378
2387
 
2379
- for (const [key, value] of Object.entries(tDep)) {
2380
- cData.dependencies[key] = value;
2381
- }
2388
+ for (const [key, value] of Object.entries(tDep)) {
2389
+ cData.dependencies[key] = value;
2390
+ }
2382
2391
 
2383
2392
 
2384
- // update current package json file
2385
- fs.writeFileSync(currentPackagePath, JSON.stringify(cData, null, 4), { encoding: 'utf8',flag:'w' });
2393
+ // update current package json file
2394
+ fs.writeFileSync(currentPackagePath, JSON.stringify(cData, null, 4), { encoding: 'utf8', flag: 'w' });
2386
2395
 
2387
2396
 
2388
- }
2397
+ };
2389
2398
 
2390
2399
 
2391
2400
  export const restoreDependenciesFromPackage_old = async () => {
2392
2401
  if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
2393
- const currentDirectory = process.cwd();
2394
- const tempDirectory = join(currentDirectory, TEMP_PATH);
2395
- const tempPackagePath = join (tempDirectory, PACKAGE_JSON_FILENAME);
2396
- const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
2402
+ const currentDirectory = process.cwd();
2403
+ const tempDirectory = join(currentDirectory, TEMP_PATH);
2404
+ const tempPackagePath = join(tempDirectory, PACKAGE_JSON_FILENAME);
2405
+ const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
2397
2406
 
2398
- let retrievedPackageData;
2399
- let currentPackageData;
2407
+ let retrievedPackageData;
2408
+ let currentPackageData;
2400
2409
 
2401
- // reset
2402
- haveDependencyDifference = false;
2410
+ // reset
2411
+ haveDependencyDifference = false;
2403
2412
 
2404
- try {
2405
- retrievedPackageData = fs.readFileSync(tempPackagePath);
2406
- }
2407
- catch (ex) {
2408
- console.log($chalk.red(`\nUnable to retrieve package.json from store.`))
2409
- process.exit(1);
2410
- }
2413
+ try {
2414
+ retrievedPackageData = fs.readFileSync(tempPackagePath);
2415
+ }
2416
+ catch (ex) {
2417
+ console.log($chalk.red(`\nUnable to retrieve package.json from store.`));
2418
+ process.exit(1);
2419
+ }
2411
2420
 
2412
- try {
2413
- currentPackageData = fs.readFileSync(currentPackagePath);
2414
- }
2415
- catch (ex) {
2416
- console.log($chalk.red(`\nUnable to retrieve current package.json.`))
2417
- process.exit(1);
2418
- }
2421
+ try {
2422
+ currentPackageData = fs.readFileSync(currentPackagePath);
2423
+ }
2424
+ catch (ex) {
2425
+ console.log($chalk.red(`\nUnable to retrieve current package.json.`));
2426
+ process.exit(1);
2427
+ }
2419
2428
 
2420
2429
 
2421
- const rData = JSON.parse(retrievedPackageData);
2422
- let cData = JSON.parse(currentPackageData);
2430
+ const rData = JSON.parse(retrievedPackageData);
2431
+ let cData = JSON.parse(currentPackageData);
2423
2432
 
2424
- // now keep current package.json, but replace devDependencies and dependencies.
2425
- const sDep = JSON.stringify(rData.dependencies);
2426
- const sDevDep = JSON.stringify(rData.devDependencies);
2433
+ // now keep current package.json, but replace devDependencies and dependencies.
2434
+ const sDep = JSON.stringify(rData.dependencies);
2435
+ const sDevDep = JSON.stringify(rData.devDependencies);
2427
2436
 
2428
- const sCurDep = JSON.stringify(cData.dependencies);
2429
- const sCurDevDep = JSON.stringify(cData.devDependencies);
2437
+ const sCurDep = JSON.stringify(cData.dependencies);
2438
+ const sCurDevDep = JSON.stringify(cData.devDependencies);
2430
2439
 
2431
- // any changes, update haveDependencyDifference variable
2432
- if (sDep != sCurDep) {
2433
- haveDependencyDifference = true;
2434
- }
2435
- else if (sDevDep != sCurDevDep) {
2436
- haveDependencyDifference = true;
2437
- }
2440
+ // any changes, update haveDependencyDifference variable
2441
+ if (sDep != sCurDep) {
2442
+ haveDependencyDifference = true;
2443
+ }
2444
+ else if (sDevDep != sCurDevDep) {
2445
+ haveDependencyDifference = true;
2446
+ }
2438
2447
 
2439
2448
 
2440
- cData.dependencies = JSON.parse(sDep);
2441
- cData.devDependencies = JSON.parse(sDevDep);
2449
+ cData.dependencies = JSON.parse(sDep);
2450
+ cData.devDependencies = JSON.parse(sDevDep);
2442
2451
 
2443
- // we can't loose devDep that is part of install, so go get the template mustache and push
2444
- // those in, replacing any changes there, but allowing additional, an keeping it updated
2445
- // so won't loose new function if an old archive
2446
- const initDir = join(currentDirectory, "node_modules", "@pega", "custom-dx-components", "src", "tasks", "init");
2447
- const templateDir = join(initDir, "template");
2448
- const packageTemplateJsonPath = path.join(templateDir, 'package.json.mustache');
2449
- let retrievedTemplateData;
2450
- try {
2451
- retrievedTemplateData = fs.readFileSync(packageTemplateJsonPath);
2452
- }
2453
- catch (ex) {
2454
- console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`))
2455
- process.exit(1);
2456
- }
2457
- const tData = JSON.parse(retrievedTemplateData);
2458
- const tDevDep = tData.devDependencies;
2459
- for (const [key, value] of Object.entries(tDevDep)) {
2460
- cData.devDependencies[key] = value;
2461
- }
2452
+ // we can't loose devDep that is part of install, so go get the template mustache and push
2453
+ // those in, replacing any changes there, but allowing additional, an keeping it updated
2454
+ // so won't loose new function if an old archive
2455
+ const initDir = join(currentDirectory, "node_modules", "@pega", "custom-dx-components", "src", "tasks", "init");
2456
+ const templateDir = join(initDir, "template");
2457
+ const packageTemplateJsonPath = path.join(templateDir, 'package.json.mustache');
2458
+ let retrievedTemplateData;
2459
+ try {
2460
+ retrievedTemplateData = fs.readFileSync(packageTemplateJsonPath);
2461
+ }
2462
+ catch (ex) {
2463
+ console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`));
2464
+ process.exit(1);
2465
+ }
2466
+ const tData = JSON.parse(retrievedTemplateData);
2467
+ const tDevDep = tData.devDependencies;
2468
+ for (const [key, value] of Object.entries(tDevDep)) {
2469
+ cData.devDependencies[key] = value;
2470
+ }
2462
2471
 
2463
2472
 
2464
- // update current package json file
2465
- fs.writeFileSync(currentPackagePath, JSON.stringify(cData, null, 4), { encoding: 'utf8',flag:'w' });
2473
+ // update current package json file
2474
+ fs.writeFileSync(currentPackagePath, JSON.stringify(cData, null, 4), { encoding: 'utf8', flag: 'w' });
2466
2475
 
2467
2476
 
2468
- }
2477
+ };
2469
2478
 
2470
2479
  export const getHaveDependencyDifference = () => {
2471
- if (showDebug) addDebugLog("getHaveDependencyDifference", ``, "");
2480
+ if (showDebug) addDebugLog("getHaveDependencyDifference", ``, "");
2472
2481
  return haveDependencyDifference;
2473
- }
2482
+ };
2474
2483
 
2475
2484
  export const restoreFromArchive = async (fileName, orgLibName, version) => {
2476
- if (showDebug) addDebugLog("restoreFromArchive", `fileName: ${fileName}, orgLibName: ${orgLibName}, version: ${version}`, "");
2485
+ if (showDebug) addDebugLog("restoreFromArchive", `fileName: ${fileName}, orgLibName: ${orgLibName}, version: ${version}`, "");
2477
2486
  const currentDirectory = process.cwd();
2478
2487
  const tempDirectory = join(currentDirectory, TEMP_PATH);
2479
- const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
2488
+ const archiveDirectory = join(currentDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
2480
2489
  const archFileName = join(archiveDirectory, fileName);
2481
2490
 
2482
2491
 
2483
2492
  if (!fs.existsSync(archiveDirectory)) {
2484
- throw new Error (`Archive ${orgLibName}/${version} does NOT exist.`);
2493
+ throw new Error(`Archive ${orgLibName}/${version} does NOT exist.`);
2485
2494
  }
2486
2495
 
2487
2496
  await unZipFromArchive(archFileName);
2488
2497
 
2489
- const tempPackagePath = join (tempDirectory, PACKAGE_JSON_FILENAME);
2498
+ const tempPackagePath = join(tempDirectory, PACKAGE_JSON_FILENAME);
2490
2499
  const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
2491
2500
  const tempDirectoryComponents = join(tempDirectory, "src");
2492
2501
  const currentComponentsPath = join(currentDirectory, "src");
@@ -2503,11 +2512,11 @@ if (showDebug) addDebugLog("restoreFromArchive", `fileName: ${fileName}, orgLibN
2503
2512
  await restoreDependenciesFromPackage();
2504
2513
 
2505
2514
  // remove current components
2506
- fs.rmSync(currentComponentsPath, { recursive: true, force: true, maxRetries: 2 });
2515
+ fs.rmSync(currentComponentsPath, { recursive: true, force: true, maxRetries: 2 });
2507
2516
 
2508
2517
  if (fs.existsSync(currentComponentsPath)) {
2509
2518
  // try another round of rm
2510
- fs.rmSync(currentComponentsPath, { recursive: true, force: true, maxRetries: 2 });
2519
+ fs.rmSync(currentComponentsPath, { recursive: true, force: true, maxRetries: 2 });
2511
2520
 
2512
2521
  if (fs.existsSync(currentComponentsPath)) {
2513
2522
  // still an issue
@@ -2523,29 +2532,29 @@ if (showDebug) addDebugLog("restoreFromArchive", `fileName: ${fileName}, orgLibN
2523
2532
  // copy temp src/components
2524
2533
  if (fs.existsSync(tempDirectoryComponents)) {
2525
2534
 
2526
- fs.cpSync(tempDirectoryComponents, currentComponentsPath, { recursive: true, force: true });
2527
- }
2528
- else {
2529
- // nothing was archived (no src/components)
2530
- // so make a src/components if doesn't exist
2531
- if (!fs.existsSync(currentComponentsPath)) {
2532
- fs.mkdirSync(currentComponentsPath, { "recursive" : true});
2533
- }
2534
- }
2535
+ fs.cpSync(tempDirectoryComponents, currentComponentsPath, { recursive: true, force: true });
2536
+ }
2537
+ else {
2538
+ // nothing was archived (no src/components)
2539
+ // so make a src/components if doesn't exist
2540
+ if (!fs.existsSync(currentComponentsPath)) {
2541
+ fs.mkdirSync(currentComponentsPath, { "recursive": true });
2542
+ }
2543
+ }
2535
2544
 
2536
2545
 
2537
- // remove temp (windows not working well with "sync", can be async, since as long as deleted, fine)
2538
- fs.rmSync(tempDirectory, { recursive: true, force: true, maxRetries: 5 }, () => {});
2546
+ // remove temp (windows not working well with "sync", can be async, since as long as deleted, fine)
2547
+ fs.rmSync(tempDirectory, { recursive: true, force: true, maxRetries: 5 }, () => { });
2539
2548
 
2540
2549
  };
2541
2550
 
2542
2551
  export const clearSrcComponentsDirectory = async () => {
2543
- if (showDebug) addDebugLog("clearSrcComponentsDirectory", ``, "");
2552
+ if (showDebug) addDebugLog("clearSrcComponentsDirectory", ``, "");
2544
2553
  const currentDirectory = process.cwd();
2545
2554
  const currentComponentsPath = join(currentDirectory, "src", "components");
2546
2555
 
2547
2556
  // remove current components
2548
- fs.rmSync(currentComponentsPath, { recursive: true, force: true, maxRetries: 2 });
2557
+ fs.rmSync(currentComponentsPath, { recursive: true, force: true, maxRetries: 2 });
2549
2558
 
2550
2559
  // create blank src
2551
2560
  fs.mkdirSync(currentComponentsPath, { recursive: true });
@@ -2559,23 +2568,23 @@ export const isHiddenFile = (fileName) => {
2559
2568
  return false;
2560
2569
  };
2561
2570
 
2562
- export const getCurrentOrgLib = () =>{
2571
+ export const getCurrentOrgLib = () => {
2563
2572
  return defaultConfigs.currentOrgLib;
2564
2573
  };
2565
2574
 
2566
2575
  export const hasArchives = async () => {
2567
- if (showDebug) addDebugLog("hasArchives", "call", "");
2576
+ if (showDebug) addDebugLog("hasArchives", "call", "");
2568
2577
  const currentDirectory = process.cwd();
2569
- const archiveDirectory = join (currentDirectory, ARCHIVES_PATH);
2578
+ const archiveDirectory = join(currentDirectory, ARCHIVES_PATH);
2570
2579
  const hasArc = fs.existsSync(archiveDirectory);
2571
- if (showDebug) addDebugLog("hasArchives", `${hasArc}`, "");
2580
+ if (showDebug) addDebugLog("hasArchives", `${hasArc}`, "");
2572
2581
  return hasArc;
2573
2582
  };
2574
2583
 
2575
2584
  export const deleteArchives = async () => {
2576
- if (showDebug) addDebugLog("deleteArchives", ``, "");
2585
+ if (showDebug) addDebugLog("deleteArchives", ``, "");
2577
2586
  const currentDirectory = process.cwd();
2578
- const archiveDirectory = join (currentDirectory, ARCHIVES_PATH);
2587
+ const archiveDirectory = join(currentDirectory, ARCHIVES_PATH);
2579
2588
  const hasArc = fs.existsSync(archiveDirectory);
2580
2589
 
2581
2590
  if (hasArc) {
@@ -2584,11 +2593,11 @@ if (showDebug) addDebugLog("deleteArchives", ``, "");
2584
2593
  } catch (err) {
2585
2594
  }
2586
2595
  }
2587
- }
2596
+ };
2588
2597
 
2589
2598
  export const checkLibraryAndArchives = async () => {
2590
- if (showDebug) addDebugLog("checkLibraryAndArchives", ``, "");
2591
- const isLibraryBased = getLibraryBased();
2599
+ if (showDebug) addDebugLog("checkLibraryAndArchives", ``, "");
2600
+ const isLibraryBased = getLibraryBased();
2592
2601
  const hasArch = await hasArchives();
2593
2602
 
2594
2603
  if (isLibraryBased && !hasArch) {
@@ -2599,7 +2608,7 @@ if (showDebug) addDebugLog("checkLibraryAndArchives", ``, "");
2599
2608
  };
2600
2609
 
2601
2610
  export const hasLibraryAndVersion = async (libraryName, version, devBuild) => {
2602
- if (showDebug) addDebugLog("hasLibraryAndVersion", `libraryName: ${libraryName}, version: ${version}, devBuild: ${devBuild}`, "");
2611
+ if (showDebug) addDebugLog("hasLibraryAndVersion", `libraryName: ${libraryName}, version: ${version}, devBuild: ${devBuild}`, "");
2603
2612
 
2604
2613
  const orgLib = getConfigDefaults();
2605
2614
  const currentOrgLib = `${orgLib.organization}_${libraryName}`;
@@ -2619,9 +2628,9 @@ if (showDebug) addDebugLog("hasLibraryAndVersion", `libraryName: ${libraryName},
2619
2628
  };
2620
2629
 
2621
2630
  export const getLibraryArchiveDirectories = async (currentOrgLib = "") => {
2622
- if (showDebug) addDebugLog("getLibraryArchiveDirectories", "", "");
2631
+ if (showDebug) addDebugLog("getLibraryArchiveDirectories", "", "");
2623
2632
  const currentDirectory = process.cwd();
2624
- const archiveDirectory = join (currentDirectory, ARCHIVES_PATH);
2633
+ const archiveDirectory = join(currentDirectory, ARCHIVES_PATH);
2625
2634
 
2626
2635
 
2627
2636
  if (!fs.existsSync(archiveDirectory)) {
@@ -2629,18 +2638,18 @@ if (showDebug) addDebugLog("getLibraryArchiveDirectories", "", "");
2629
2638
  }
2630
2639
 
2631
2640
  return fs
2632
- .readdirSync(archiveDirectory, { withFileTypes: true })
2633
- .filter(dirent => dirent.isDirectory() && (dirent.name != currentOrgLib) )
2634
- .map(dirent => dirent.name);
2641
+ .readdirSync(archiveDirectory, { withFileTypes: true })
2642
+ .filter(dirent => dirent.isDirectory() && (dirent.name != currentOrgLib))
2643
+ .map(dirent => dirent.name);
2635
2644
  };
2636
2645
 
2637
2646
 
2638
2647
 
2639
2648
  export const getLibraryArchivesVersions = async (orgLibName, currentVersion) => {
2640
- if (showDebug) addDebugLog("getLibraryArchivesVersions", `orgLibName: ${orgLibName}`, "");
2649
+ if (showDebug) addDebugLog("getLibraryArchivesVersions", `orgLibName: ${orgLibName}`, "");
2641
2650
 
2642
2651
  const currentDirectory = process.cwd();
2643
- const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, `${orgLibName}`);
2652
+ const archiveDirectory = join(currentDirectory, ARCHIVES_PATH, `${orgLibName}`);
2644
2653
 
2645
2654
  if (!fs.existsSync(archiveDirectory)) {
2646
2655
  return [];
@@ -2648,17 +2657,17 @@ if (showDebug) addDebugLog("getLibraryArchivesVersions", `orgLibName: ${orgLibNa
2648
2657
 
2649
2658
  return fs
2650
2659
  .readdirSync(archiveDirectory, { withFileTypes: true })
2651
- .filter(dirent => dirent.isDirectory() && dirent.name != currentVersion )
2660
+ .filter(dirent => dirent.isDirectory() && dirent.name != currentVersion)
2652
2661
  .map(dirent => dirent.name);
2653
2662
 
2654
2663
 
2655
2664
 
2656
2665
  };
2657
2666
 
2658
- export const deleteLocalArchiveLibrary = async(libraryName) => {
2659
- if (showDebug) addDebugLog("deleteLocalArchiveLibrary", `libraryName: ${libraryName}`, "");
2667
+ export const deleteLocalArchiveLibrary = async (libraryName) => {
2668
+ if (showDebug) addDebugLog("deleteLocalArchiveLibrary", `libraryName: ${libraryName}`, "");
2660
2669
  const currentDirectory = process.cwd();
2661
- const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, libraryName);
2670
+ const archiveDirectory = join(currentDirectory, ARCHIVES_PATH, libraryName);
2662
2671
 
2663
2672
  try {
2664
2673
  fs.rmSync(archiveDirectory, { recursive: true });
@@ -2671,17 +2680,17 @@ if (showDebug) addDebugLog("deleteLocalArchiveLibrary", `libraryName: ${libraryN
2671
2680
  // check if no other libraries, the remove /store
2672
2681
  const archList = getLibraryArchiveDirectories();
2673
2682
  if (archList.length === 0) {
2674
- const archPath = join (currentDirectory, ARCHIVES_PATH);
2683
+ const archPath = join(currentDirectory, ARCHIVES_PATH);
2675
2684
 
2676
- fs.rmSync(archPath, { recursive : true});
2685
+ fs.rmSync(archPath, { recursive: true });
2677
2686
  }
2678
2687
 
2679
- }
2688
+ };
2680
2689
 
2681
- export const deleteLocalArchiveLibraryVersion = async(libraryName, version) => {
2682
- if (showDebug) addDebugLog("deleteLocalArchiveLibraryVersion", `libraryName: ${libraryName}, version: ${version}`, "");
2690
+ export const deleteLocalArchiveLibraryVersion = async (libraryName, version) => {
2691
+ if (showDebug) addDebugLog("deleteLocalArchiveLibraryVersion", `libraryName: ${libraryName}, version: ${version}`, "");
2683
2692
  const currentDirectory = process.cwd();
2684
- const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, libraryName, version);
2693
+ const archiveDirectory = join(currentDirectory, ARCHIVES_PATH, libraryName, version);
2685
2694
 
2686
2695
  try {
2687
2696
  fs.rmSync(archiveDirectory, { recursive: true });
@@ -2694,45 +2703,45 @@ if (showDebug) addDebugLog("deleteLocalArchiveLibraryVersion", `libraryName: ${l
2694
2703
  // throw new Error(`No such file ${libraryName}/${version}`);
2695
2704
  }
2696
2705
 
2697
- }
2706
+ };
2698
2707
 
2699
- export const cleanUpTemp = async() => {
2700
- if (showDebug) addDebugLog("cleanUpTemp", ``, "");
2708
+ export const cleanUpTemp = async () => {
2709
+ if (showDebug) addDebugLog("cleanUpTemp", ``, "");
2701
2710
  const currentDirectory = process.cwd();
2702
- const tempDirectory = join (currentDirectory, TEMP_PATH);
2711
+ const tempDirectory = join(currentDirectory, TEMP_PATH);
2703
2712
 
2704
2713
  if (fs.existsSync(tempDirectory)) {
2705
2714
  fs.rmSync(tempDirectory, { recursive: true });
2706
2715
  }
2707
2716
 
2708
- }
2717
+ };
2709
2718
 
2710
2719
 
2711
- export const getJestFunctionalTestList = async(whichTests) => {
2712
- if (showDebug) addDebugLog("getJestFunctionalTestList", ``, "");
2720
+ export const getJestFunctionalTestList = async (whichTests) => {
2721
+ if (showDebug) addDebugLog("getJestFunctionalTestList", ``, "");
2713
2722
  const functionalDir = path.join(path.resolve(), JEST_TESTS_FUNCTIONAL_PATH);
2714
2723
  const libFilter = "localLib";
2715
2724
 
2716
2725
  switch (whichTests) {
2717
- case "ALL" :
2726
+ case "ALL":
2718
2727
  return fs
2719
- .readdirSync(functionalDir, { withFileTypes: true })
2720
- .filter(dirent => !dirent.isDirectory() )
2721
- .map(dirent => dirent.name);
2728
+ .readdirSync(functionalDir, { withFileTypes: true })
2729
+ .filter(dirent => !dirent.isDirectory())
2730
+ .map(dirent => dirent.name);
2722
2731
  case "Original":
2723
2732
  return fs
2724
- .readdirSync(functionalDir, { withFileTypes: true })
2725
- .filter(dirent => !dirent.isDirectory() && !dirent.name.startsWith(libFilter))
2726
- .map(dirent => dirent.name);
2727
- case "Library" :
2733
+ .readdirSync(functionalDir, { withFileTypes: true })
2734
+ .filter(dirent => !dirent.isDirectory() && !dirent.name.startsWith(libFilter))
2735
+ .map(dirent => dirent.name);
2736
+ case "Library":
2728
2737
  return fs
2729
- .readdirSync(functionalDir, { withFileTypes: true })
2730
- .filter(dirent => !dirent.isDirectory() && dirent.name.startsWith(libFilter))
2731
- .map(dirent => dirent.name);
2738
+ .readdirSync(functionalDir, { withFileTypes: true })
2739
+ .filter(dirent => !dirent.isDirectory() && dirent.name.startsWith(libFilter))
2740
+ .map(dirent => dirent.name);
2732
2741
  }
2733
2742
 
2734
2743
 
2735
- }
2744
+ };
2736
2745
 
2737
2746
  export const getSubTypeLabel = (type, subtype) => {
2738
2747
  const subTypeList = COMPONENT_SCHEMA.subtype;
@@ -2746,7 +2755,7 @@ export const getSubTypeLabel = (type, subtype) => {
2746
2755
  }
2747
2756
 
2748
2757
  return "";
2749
- }
2758
+ };
2750
2759
 
2751
2760
  export const getMaxComponentNameCount = () => {
2752
2761
  let count = MAX_RFT_CHARS;
@@ -2759,12 +2768,12 @@ export const getMaxComponentNameCount = () => {
2759
2768
 
2760
2769
  return count;
2761
2770
 
2762
- }
2771
+ };
2763
2772
 
2764
2773
  export const getMaxPrefixCount = () => {
2765
2774
  // TwoColumnDetails is 16 chars
2766
2775
  return (getMaxComponentNameCount() - 16);
2767
- }
2776
+ };
2768
2777
 
2769
2778
  export const isComponentValidLength = (componentKey) => {
2770
2779
  const configDef = getConfigDefaults();
@@ -2774,7 +2783,12 @@ export const isComponentValidLength = (componentKey) => {
2774
2783
  }
2775
2784
 
2776
2785
  return false;
2777
- }
2786
+ };
2787
+
2788
+ export const emptyDirSync = dir => (
2789
+ fs.rmSync(dir, { recursive: true, force: true }),
2790
+ fs.mkdirSync(dir, { recursive: true })
2791
+ );
2778
2792
 
2779
2793
  // init
2780
2794
  await forceDefaultsUpdate();