@pega/custom-dx-components 0.242.54 → 0.242.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "0.242.54",
3
+ "version": "0.242.55",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/constants.js CHANGED
@@ -18,6 +18,8 @@ export const ARCHIVES_PATH = 'store';
18
18
  export const TEMP_PATH = 'store/temp';
19
19
  export const COMPONENTS_CONFIG_FILE_NAME = 'componentsconfig.json';
20
20
 
21
+
22
+
21
23
  /* REST end points */
22
24
  export const PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/publish_component';
23
25
  export const LIST_COMPONENT_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/list_component';
@@ -26,6 +26,19 @@ addDebugLog("updateAllComponentsConfig", `newVersion: ${newVersion}`, "");
26
26
  }
27
27
  };
28
28
 
29
+ export const getCurrentOrOriginalQuestion = async () => {
30
+ addDebugLog("getCurrentOrOriginal", "", "");
31
+
32
+ return [
33
+ {
34
+ name: 'currentOrOriginal',
35
+ type: 'rawlist',
36
+ message: 'Current config changes or original defaults ?',
37
+ default: 'Original',
38
+ choices: ['Current', 'Original']
39
+ }
40
+ ];
41
+ }
29
42
 
30
43
  export const getOkToProceedQuestion = async () => {
31
44
  addDebugLog("getCreateLibComponentQuestions", "", "");
@@ -15,10 +15,12 @@ import {
15
15
  hasLibraryAndVersion,
16
16
  getConfigDefaults,
17
17
  forceDefaultsUpdate,
18
- cleanUpTemp
18
+ cleanUpTemp,
19
+ restoreTopLevelConfigFilesFromTemplate,
20
+ getHaveDependencyDifference
19
21
  } from '../../util.js';
20
22
 
21
- import { getCreateLibComponentQuestions, getOkToProceedQuestion, updateAllComponentsConfig } from './helper.js';
23
+ import { getCreateLibComponentQuestions, getOkToProceedQuestion, updateAllComponentsConfig, getCurrentOrOriginalQuestion } from './helper.js';
22
24
  import { showCurrentStatus } from '../show-status/index.js';
23
25
 
24
26
  export default async options => {
@@ -39,6 +41,8 @@ addDebugLog("createLibrary", "", "+");
39
41
  const orgLib = getConfigDefaults();
40
42
  const hasArch = await hasArchives();
41
43
 
44
+ let currentOrOriginal = "";
45
+
42
46
  if (hasArch && options.params.length < 6) {
43
47
  console.log(chalk.bold.yellow('\nBe sure to SAVE all changes before creating a new library, unsaved changes will be LOST.'))
44
48
  console.log(chalk.bold.yellow('Current library/version will be stored and the newly created library/version will be your default.'))
@@ -52,10 +56,11 @@ addDebugLog("createLibrary", "", "+");
52
56
  }
53
57
  }
54
58
 
55
- if (options.params.length >= 6) {
59
+ if (options.params.length >= 7) {
56
60
  libraryName = options.params[3];
57
61
  version = options.params[4];
58
62
  const dPerm = options.params[5];
63
+ currentOrOriginal = options.params[6];
59
64
  permBuild = !!(dPerm === 'Y' || dPerm === 'y' || dPerm === true || dPerm === 'true');
60
65
  } else {
61
66
  const questions = await getCreateLibComponentQuestions();
@@ -93,6 +98,26 @@ addDebugLog("createLibrary", "", "+");
93
98
  version = version.concat("-dev");
94
99
  }
95
100
 
101
+ if (hasArch && currentOrOriginal === "") {
102
+
103
+ console.log(`\n${chalk.yellow(`You may have updated package.json, and other config files.`)}`);
104
+ console.log(`${chalk.yellow(`Do you wish to keep those CURRENT changes OR revert back to ORIGINAL install configs.`)}\n`);
105
+
106
+ // need to ask the question
107
+ const curOrgQuestion = await getCurrentOrOriginalQuestion();
108
+ const currAnswers = await inquirer.prompt(curOrgQuestion);
109
+ ({ currentOrOriginal } = currAnswers);
110
+ }
111
+ else {
112
+ currentOrOriginal = 'Original';
113
+ }
114
+
115
+ if (currentOrOriginal === 'Original') {
116
+ await restoreTopLevelConfigFilesFromTemplate();
117
+ }
118
+
119
+
120
+
96
121
  // update library name in config and create a blank archive
97
122
  await updateComponentDefaultLibrary(libraryName);
98
123
  await zipVersionAndArchive(newOrgLib, version);
@@ -108,6 +133,17 @@ addDebugLog("createLibrary", "", "+");
108
133
  await forceDefaultsUpdate();
109
134
  await showCurrentStatus();
110
135
 
136
+ if (currentOrOriginal === 'Original') {
137
+ if (getHaveDependencyDifference()) {
138
+
139
+ console.log('\n***************************************************************');
140
+ console.log(chalk.bold.yellow('Dependencies have changed between libraries, recommend updating.'));
141
+ console.log(`>>> PLEASE run ${chalk.bold.yellow("'npm update'")}.`);
142
+ console.log('***************************************************************\n');
143
+
144
+ }
145
+ }
146
+
111
147
  addDebugLog("createLibrary", "END", "-");
112
148
 
113
149
  return true;
@@ -100,7 +100,7 @@
100
100
  },
101
101
  "devDependencies": {
102
102
  "@pega/configs": "^0.15.1",
103
- "@pega/custom-dx-components": "~0.242.54",
103
+ "@pega/custom-dx-components": "~0.242.55",
104
104
  "@pega/pcore-pconnect-typedefs": "~3.2.0-alpha.1",
105
105
  "@storybook/addon-actions": "^7.6.19",
106
106
  "@storybook/addon-essentials": "^7.6.19",
package/src/util.js CHANGED
@@ -539,6 +539,151 @@ if (showDebug) addDebugLog("getComponents", "", "");
539
539
  .map(dirent => dirent.name);
540
540
  };
541
541
 
542
+ export const getTopLevelConfigFiles = async (directory) => {
543
+ if (showDebug) addDebugLog("getTopLevelConfigFiles", `directory: ${directory}`, "");
544
+ if (fs.existsSync(directory)) {
545
+ return fs
546
+ .readdirSync(directory, { withFileTypes: true })
547
+ .filter(dirent => !dirent.isDirectory())
548
+ .map(dirent => dirent.name);
549
+ }
550
+ else {
551
+ return [];
552
+ }
553
+ }
554
+
555
+ export const removeTopLevelConfigFiles = async (directory) => {
556
+ if (showDebug) addDebugLog("removeTopLevelConfigFiles", `directory: ${directory}`, "");
557
+ const configFiles = await getTopLevelConfigFiles(directory);
558
+
559
+ if (configFiles && configFiles.length > 0) {
560
+ for (const configF of configFiles) {
561
+ if (configF !== "package-lock.json" && configF !== "package.json" && configF !== "tasks.config.json" ) {
562
+ fs.rmSync( join(directory, configF), { recursive: true, force: true, maxRetries: 2 });
563
+ }
564
+ }
565
+ }
566
+ }
567
+
568
+ export const restoreTopLevelConfigFiles = async(directory) => {
569
+ if (showDebug) addDebugLog("restoreTopLevelConfigFiles", `directory: ${directory}`, "");
570
+ const currentDirectory = process.cwd();
571
+ const tempDirectory = join(currentDirectory, TEMP_PATH);
572
+ const configFiles = await getTopLevelConfigFiles(tempDirectory);
573
+
574
+ if (configFiles && configFiles.length > 0) {
575
+ for (const configF of configFiles) {
576
+ if (configF !== "package-lock.json" && configF !== "package.json") {
577
+ fs.copyFileSync(join(tempDirectory, configF), join(directory, configF));
578
+ }
579
+ }
580
+ }
581
+ }
582
+
583
+ export const getTemplateConfigFiles = async () => {
584
+ if (showDebug) addDebugLog("getTemplateConfigFiles", ``, "");
585
+ const currentDirectory = process.cwd();
586
+ const initDir = join(currentDirectory, "node_modules", "@pega", "custom-dx-components", "src", "tasks", "init");
587
+ const templateDir = join(initDir, "template");
588
+
589
+ if (fs.existsSync(templateDir)) {
590
+ return fs
591
+ .readdirSync(templateDir, { withFileTypes: true })
592
+ .filter(dirent => !dirent.isDirectory())
593
+ .map(dirent => dirent.name);
594
+ }
595
+ else {
596
+ return [];
597
+ }
598
+
599
+ }
600
+
601
+ export const restoreTopLevelConfigFilesFromTemplate = async() => {
602
+ if (showDebug) addDebugLog("restoreTopLevelConfigFilesFromTemplate", ``, "");
603
+ // we can't loose devDep that is part of install, so go get the template mustache and push
604
+ // those in, replacing any changes there, but allowing additional, an keeping it updated
605
+ // so won't loose new function if an old archive
606
+ const currentDirectory = process.cwd();
607
+ const initDir = join(currentDirectory, "node_modules", "@pega", "custom-dx-components", "src", "tasks", "init");
608
+ const templateDir = join(initDir, "template");
609
+ const packageTemplateJsonPath = path.join(templateDir, 'package.json.mustache');
610
+
611
+ const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
612
+ let currentPackageData;
613
+
614
+ // reset
615
+ haveDependencyDifference = false;
616
+
617
+ try {
618
+ currentPackageData = fs.readFileSync(currentPackagePath);
619
+ }
620
+ catch (ex) {
621
+ console.log($chalk.red(`\nUnable to retrieve current package.json.`))
622
+ process.exit(1);
623
+ }
624
+ let cData = JSON.parse(currentPackageData);
625
+
626
+ let retrievedTemplateData;
627
+ try {
628
+ retrievedTemplateData = fs.readFileSync(packageTemplateJsonPath);
629
+ }
630
+ catch (ex) {
631
+ console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`))
632
+ process.exit(1);
633
+ }
634
+
635
+ // copy template dependecies and devDependencies
636
+ const tData = JSON.parse(retrievedTemplateData);
637
+
638
+
639
+ // check to see if any dependency changes
640
+ const sDep = JSON.stringify(tData.dependencies);
641
+ const sDevDep = JSON.stringify(tData.devDependencies);
642
+
643
+ const sCurDep = JSON.stringify(cData.dependencies);
644
+ const sCurDevDep = JSON.stringify(cData.devDependencies);
645
+
646
+ // any changes, update haveDependencyDifference variable
647
+ if (sDep != sCurDep) {
648
+ haveDependencyDifference = true;
649
+ }
650
+ else if (sDevDep != sCurDevDep) {
651
+ haveDependencyDifference = true;
652
+ }
653
+
654
+ await removeTopLevelConfigFiles(currentDirectory);
655
+
656
+
657
+ // clear out
658
+ cData.dependencies = {};
659
+ cData.devDependencies = {};
660
+
661
+
662
+
663
+ const tDep = tData.dependencies;
664
+ for (const [key, value] of Object.entries(tDep)) {
665
+ cData.dependencies[key] = value;
666
+ }
667
+ const tDevDep = tData.devDependencies;
668
+ for (const [key, value] of Object.entries(tDevDep)) {
669
+ cData.devDependencies[key] = value;
670
+ }
671
+
672
+ // update current package json file
673
+ fs.writeFileSync(currentPackagePath, JSON.stringify(cData, null, 4), { encoding: 'utf8',flag:'w' });
674
+
675
+ // restore from template
676
+ const templateFiles = await getTemplateConfigFiles();
677
+ if (templateFiles && templateFiles.length > 0) {
678
+ for (const tFile of templateFiles) {
679
+ if (tFile !== "package.json.mustache" && tFile !== "templateNPMRC.txt" && tFile !== "tasks.config.json") {
680
+ fs.copyFileSync(join(templateDir, tFile), join(currentDirectory, tFile));
681
+ }
682
+ }
683
+ }
684
+
685
+ }
686
+
542
687
  export const getSubComponents = async (directory, type) => {
543
688
  if (showDebug) addDebugLog("getDirectoryFiles", `directory: ${directory}, type: ${type}`, "");
544
689
  const subDirectory = join(directory, type);
@@ -1466,16 +1611,29 @@ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, v
1466
1611
  // Add src directory
1467
1612
  archive.directory(srcDirectoryPath, 'src');
1468
1613
 
1469
- // Add config.json file
1470
- if (fs.existsSync(tasksConfig)) {
1471
- archive.file(tasksConfig, { name: path.basename(tasksConfig) });
1472
- }
1614
+ // grab all files (not directories and archive)
1615
+ const configFiles = await getTopLevelConfigFiles(currentDirectory);
1616
+ if (configFiles && configFiles.length > 0) {
1617
+ for (const configF of configFiles) {
1618
+ if (configF !== "package-lock.json") {
1619
+ archive.file(
1620
+ join(currentDirectory, configF), { name: configF });
1621
+ }
1473
1622
 
1474
- // Add package.json file
1475
- if (fs.existsSync(packageJson)) {
1476
- archive.file(packageJson, { name: path.basename(packageJson) });
1623
+ }
1477
1624
  }
1478
1625
 
1626
+ // // Add config.json file
1627
+ // if (fs.existsSync(tasksConfig)) {
1628
+ // archive.file(tasksConfig, { name: path.basename(tasksConfig) });
1629
+ // }
1630
+
1631
+ // // Add package.json file
1632
+ // if (fs.existsSync(packageJson)) {
1633
+ // archive.file(packageJson, { name: path.basename(packageJson) });
1634
+ // }
1635
+
1636
+
1479
1637
  // pipe archive data to the file
1480
1638
  archive.pipe(output);
1481
1639
 
@@ -1517,6 +1675,7 @@ if (showDebug) addDebugLog("unZipFromArchive", `fileName: ${fileName}`, "");
1517
1675
  };
1518
1676
 
1519
1677
 
1678
+
1520
1679
  export const updateComponentTaskConfig = async () => {
1521
1680
  if (showDebug) addDebugLog("updateComponentTaskConfig", "", "");
1522
1681
  const currentDirectory = process.cwd();
@@ -1570,7 +1729,7 @@ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
1570
1729
  }
1571
1730
 
1572
1731
 
1573
- const rData = JSON.parse(retrievedPackageData);
1732
+ let rData = JSON.parse(retrievedPackageData);
1574
1733
  let cData = JSON.parse(currentPackageData);
1575
1734
 
1576
1735
  // now keep current package.json, but replace devDependencies and dependencies.
@@ -1609,16 +1768,106 @@ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
1609
1768
  const tData = JSON.parse(retrievedTemplateData);
1610
1769
  const tDevDep = tData.devDependencies;
1611
1770
  for (const [key, value] of Object.entries(tDevDep)) {
1612
- cData.devDependencies[key] = value;
1771
+ rData.devDependencies[key] = value;
1613
1772
  }
1614
1773
 
1774
+ // overwrite cData specifics
1775
+ rData.name = cData.name;
1776
+ rData.description = cData.description;
1777
+ rData.organization = cData.organization;
1778
+ rData.main = cData.main;
1779
+ rData.type = cData.type;
1780
+ rData.scripts = cData.scripts;
1781
+ rData.scriptsComments = cData.scriptsComments;
1782
+ rData.repository = cData.repository;
1783
+ rData.keywords = cData.keywords;
1784
+
1615
1785
 
1616
1786
  // update current package json file
1617
- fs.writeFileSync(currentPackagePath, JSON.stringify(cData, null, 4), { encoding: 'utf8',flag:'w' });
1787
+ fs.writeFileSync(currentPackagePath, JSON.stringify(rData, null, 4), { encoding: 'utf8',flag:'w' });
1618
1788
 
1619
1789
 
1620
1790
  }
1621
1791
 
1792
+ export const restoreDependenciesFromPackage_old = async () => {
1793
+ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
1794
+ const currentDirectory = process.cwd();
1795
+ const tempDirectory = join(currentDirectory, TEMP_PATH);
1796
+ const tempPackagePath = join (tempDirectory, PACKAGE_JSON_FILENAME);
1797
+ const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
1798
+
1799
+ let retrievedPackageData;
1800
+ let currentPackageData;
1801
+
1802
+ // reset
1803
+ haveDependencyDifference = false;
1804
+
1805
+ try {
1806
+ retrievedPackageData = fs.readFileSync(tempPackagePath);
1807
+ }
1808
+ catch (ex) {
1809
+ console.log($chalk.red(`\nUnable to retrieve package.json from store.`))
1810
+ process.exit(1);
1811
+ }
1812
+
1813
+ try {
1814
+ currentPackageData = fs.readFileSync(currentPackagePath);
1815
+ }
1816
+ catch (ex) {
1817
+ console.log($chalk.red(`\nUnable to retrieve current package.json.`))
1818
+ process.exit(1);
1819
+ }
1820
+
1821
+
1822
+ const rData = JSON.parse(retrievedPackageData);
1823
+ let cData = JSON.parse(currentPackageData);
1824
+
1825
+ // now keep current package.json, but replace devDependencies and dependencies.
1826
+ const sDep = JSON.stringify(rData.dependencies);
1827
+ const sDevDep = JSON.stringify(rData.devDependencies);
1828
+
1829
+ const sCurDep = JSON.stringify(cData.dependencies);
1830
+ const sCurDevDep = JSON.stringify(cData.devDependencies);
1831
+
1832
+ // any changes, update haveDependencyDifference variable
1833
+ if (sDep != sCurDep) {
1834
+ haveDependencyDifference = true;
1835
+ }
1836
+ else if (sDevDep != sCurDevDep) {
1837
+ haveDependencyDifference = true;
1838
+ }
1839
+
1840
+
1841
+ cData.dependencies = JSON.parse(sDep);
1842
+ cData.devDependencies = JSON.parse(sDevDep);
1843
+
1844
+ // we can't loose devDep that is part of install, so go get the template mustache and push
1845
+ // those in, replacing any changes there, but allowing additional, an keeping it updated
1846
+ // so won't loose new function if an old archive
1847
+ const initDir = join(currentDirectory, "node_modules", "@pega", "custom-dx-components", "src", "tasks", "init");
1848
+ const templateDir = join(initDir, "template");
1849
+ const packageTemplateJsonPath = path.join(templateDir, 'package.json.mustache');
1850
+ let retrievedTemplateData;
1851
+ try {
1852
+ retrievedTemplateData = fs.readFileSync(packageTemplateJsonPath);
1853
+ }
1854
+ catch (ex) {
1855
+ console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`))
1856
+ process.exit(1);
1857
+ }
1858
+ const tData = JSON.parse(retrievedTemplateData);
1859
+ const tDevDep = tData.devDependencies;
1860
+ for (const [key, value] of Object.entries(tDevDep)) {
1861
+ cData.devDependencies[key] = value;
1862
+ }
1863
+
1864
+
1865
+ // update current package json file
1866
+ fs.writeFileSync(currentPackagePath, JSON.stringify(cData, null, 4), { encoding: 'utf8',flag:'w' });
1867
+
1868
+
1869
+ }
1870
+
1622
1871
  export const getHaveDependencyDifference = () => {
1623
1872
  if (showDebug) addDebugLog("getHaveDependencyDifference", ``, "");
1624
1873
  return haveDependencyDifference;
@@ -1639,6 +1888,11 @@ if (showDebug) addDebugLog("restoreFromArchive", `fileName: ${fileName}, orgLibN
1639
1888
  const tempDirectoryComponents = join(tempDirectory, "src", "components");
1640
1889
  const currentComponentsPath = join(currentDirectory, "src", "components");
1641
1890
 
1891
+ // remove all config files
1892
+ await removeTopLevelConfigFiles(currentDirectory);
1893
+
1894
+ await restoreTopLevelConfigFiles(currentDirectory);
1895
+
1642
1896
  // take your current tasks.config and update with component and devBuild from saved tasks.config
1643
1897
  await updateComponentTaskConfig();
1644
1898
 
@@ -1662,8 +1916,10 @@ if (showDebug) addDebugLog("restoreFromArchive", `fileName: ${fileName}, orgLibN
1662
1916
  }
1663
1917
  }
1664
1918
 
1919
+
1665
1920
  // copy temp src/components
1666
1921
  if (fs.existsSync(tempDirectoryComponents)) {
1922
+
1667
1923
  fs.cpSync(tempDirectoryComponents, currentComponentsPath, { recursive: true, force: true });
1668
1924
  }
1669
1925
  else {