@pega/custom-dx-components 0.242.57 → 0.242.59
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 +1 -1
- package/src/cli.js +6 -0
- package/src/tasks/build-lib/index.js +7 -1
- package/src/tasks/create-lib/helper.js +2 -1
- package/src/tasks/create-lib/index.js +9 -2
- package/src/tasks/index.js +1 -0
- package/src/tasks/init/template/package.json.mustache +3 -2
- package/src/tasks/publish/index.js +18 -0
- package/src/tasks/restore-config/index.js +56 -0
- package/src/util.js +70 -9
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
renameComponent,
|
|
32
32
|
moveComponent,
|
|
33
33
|
renameLibrary,
|
|
34
|
+
restoreConfig,
|
|
34
35
|
revertWebPack,
|
|
35
36
|
promoteWebPack,
|
|
36
37
|
showStatus,
|
|
@@ -61,6 +62,7 @@ const TASKS = {
|
|
|
61
62
|
PUBLISH_LIB: 'publishLibrary',
|
|
62
63
|
RENAME: 'rename',
|
|
63
64
|
RENAME_LIB: 'renameLibrary',
|
|
65
|
+
RESTORE_CONFIG: 'restoreConfig',
|
|
64
66
|
QUARANTINE: 'quarantine',
|
|
65
67
|
MOVE: 'moveComponent',
|
|
66
68
|
LIST: 'list',
|
|
@@ -164,6 +166,10 @@ export default async (args = []) => {
|
|
|
164
166
|
renameLibrary(options);
|
|
165
167
|
break;
|
|
166
168
|
}
|
|
169
|
+
case TASKS.RESTORE_CONFIG: {
|
|
170
|
+
restoreConfig(options);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
167
173
|
case TASKS.QUARANTINE: {
|
|
168
174
|
quarantine(options);
|
|
169
175
|
break;
|
|
@@ -19,7 +19,8 @@ import {
|
|
|
19
19
|
checkLibraryAndArchives,
|
|
20
20
|
getConfigDevBuild,
|
|
21
21
|
checkJWTExpiration,
|
|
22
|
-
getConfigDefaults
|
|
22
|
+
getConfigDefaults,
|
|
23
|
+
getLibraryBased
|
|
23
24
|
} from '../../util.js';
|
|
24
25
|
import bundleComponent from '../bundle/index.js';
|
|
25
26
|
|
|
@@ -125,6 +126,11 @@ addDebugLog("buildLib", "services end", "");
|
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
export default async options => {
|
|
129
|
+
const isLibraryBased = getLibraryBased();
|
|
130
|
+
if (!isLibraryBased) {
|
|
131
|
+
console.log(`Command only supported for ${chalk.bold.green('library based')} components.`)
|
|
132
|
+
process.exit();
|
|
133
|
+
}
|
|
128
134
|
|
|
129
135
|
if (options.params.length != 4) {
|
|
130
136
|
// internal so already called
|
|
@@ -54,7 +54,7 @@ addDebugLog("getCreateLibComponentQuestions", "", "");
|
|
|
54
54
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export const getCreateLibComponentQuestions = async () => {
|
|
57
|
+
export const getCreateLibComponentQuestions = async (libraryName = "") => {
|
|
58
58
|
addDebugLog("getCreateLibComponentQuestions", "", "");
|
|
59
59
|
const archDirectories = await getLibraryArchiveDirectories();
|
|
60
60
|
const orgLib = getConfigDefaults();
|
|
@@ -64,6 +64,7 @@ addDebugLog("getCreateLibComponentQuestions", "", "");
|
|
|
64
64
|
{
|
|
65
65
|
name: 'libraryName',
|
|
66
66
|
message: 'Enter libray name',
|
|
67
|
+
default: libraryName,
|
|
67
68
|
validate: value => {
|
|
68
69
|
/* value should not be empty
|
|
69
70
|
It should not have spaces
|
|
@@ -34,7 +34,7 @@ export default async options => {
|
|
|
34
34
|
await cleanUpTemp();
|
|
35
35
|
|
|
36
36
|
addDebugLog("createLibrary", "", "+");
|
|
37
|
-
let libraryName;
|
|
37
|
+
let libraryName = "";
|
|
38
38
|
let version;
|
|
39
39
|
// permBuild is the opposite of devBuild
|
|
40
40
|
let permBuild;
|
|
@@ -56,6 +56,7 @@ addDebugLog("createLibrary", "", "+");
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
|
|
59
60
|
if (options.params.length >= 7) {
|
|
60
61
|
libraryName = options.params[3];
|
|
61
62
|
version = options.params[4];
|
|
@@ -63,7 +64,13 @@ addDebugLog("createLibrary", "", "+");
|
|
|
63
64
|
currentOrOriginal = options.params[6];
|
|
64
65
|
permBuild = !!(dPerm === 'Y' || dPerm === 'y' || dPerm === true || dPerm === 'true');
|
|
65
66
|
} else {
|
|
66
|
-
|
|
67
|
+
|
|
68
|
+
if (!hasArch) {
|
|
69
|
+
// if no archives, get library name from tasks.config as default
|
|
70
|
+
libraryName = orgLib.library;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const questions = await getCreateLibComponentQuestions(libraryName);
|
|
67
74
|
const answers = await inquirer.prompt(questions);
|
|
68
75
|
({ libraryName, version, permBuild } = answers);
|
|
69
76
|
}
|
package/src/tasks/index.js
CHANGED
|
@@ -37,3 +37,4 @@ export { default as buildComponent } from './build-comp/index.js';
|
|
|
37
37
|
export { default as buildAllComponents } from './build-all/index.js';
|
|
38
38
|
export { default as buildLibrary } from './build-lib/index.js';
|
|
39
39
|
export { default as buildJestAssets } from './build-jest-assets/index.js';
|
|
40
|
+
export { default as restoreConfig } from './restore-config/index.js';
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"_internal-build-jest-assets": "custom-dx-components buildJestAssets",
|
|
54
54
|
"_internal-buildLibrary": "custom-dx-components buildLibrary",
|
|
55
55
|
"_internal-publishLibrary": "custom-dx-components publishLibrary",
|
|
56
|
+
"_internal-restoreConfig": "custom-dx-components restoreConfig",
|
|
56
57
|
"_internal-test-quarantine": "custom-dx-components quarantine",
|
|
57
58
|
"_lint:styles": "stylelint \"./**/*.@(js|jsx|ts|tsx)\"",
|
|
58
59
|
"_lint:format": "prettier -c .",
|
|
@@ -100,8 +101,8 @@
|
|
|
100
101
|
},
|
|
101
102
|
"devDependencies": {
|
|
102
103
|
"@pega/configs": "^0.15.1",
|
|
103
|
-
"@pega/custom-dx-components": "~0.242.
|
|
104
|
-
"@pega/pcore-pconnect-typedefs": "
|
|
104
|
+
"@pega/custom-dx-components": "~0.242.59",
|
|
105
|
+
"@pega/pcore-pconnect-typedefs": "3.2.1",
|
|
105
106
|
"@storybook/addon-actions": "^7.6.19",
|
|
106
107
|
"@storybook/addon-essentials": "^7.6.19",
|
|
107
108
|
"@storybook/addon-knobs": "^7.1.1",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import inquirer from 'inquirer';
|
|
2
2
|
import { Listr } from 'listr2';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
+
import fs from 'fs';
|
|
4
5
|
|
|
5
6
|
import validate from '../validator/index.js';
|
|
6
7
|
import bundleComponent from '../bundle/index.js';
|
|
@@ -11,6 +12,10 @@ import { getPublishComponentQuestions, publishComponentToServer, zipComponent }
|
|
|
11
12
|
import { default as buildLibrary } from '../build-lib/index.js';
|
|
12
13
|
import { default as publishLibrary } from '../publish-lib/index.js';
|
|
13
14
|
|
|
15
|
+
import {
|
|
16
|
+
TOKEN_PATH
|
|
17
|
+
} from '../../constants.js';
|
|
18
|
+
|
|
14
19
|
export default async options => {
|
|
15
20
|
|
|
16
21
|
await showVersion();
|
|
@@ -74,6 +79,19 @@ addDebugLog("publish", "", "+");
|
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
|
|
82
|
+
let OauthData;
|
|
83
|
+
try {
|
|
84
|
+
OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
|
|
85
|
+
}
|
|
86
|
+
catch (ex) {
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!OauthData) {
|
|
91
|
+
console.log(chalk.redBright("Need to authenticate, missing services token."));
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
|
|
77
95
|
// non library based publish
|
|
78
96
|
let componentKey;
|
|
79
97
|
let sourceMap;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
|
|
6
|
+
import inquirer from 'inquirer';
|
|
7
|
+
import ncp from 'ncp';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
|
|
10
|
+
import { restoreTopLevelConfigFilesFromTemplate,
|
|
11
|
+
restoreDependenciesFromTemplate,
|
|
12
|
+
getLibraryBased,
|
|
13
|
+
showVersion,
|
|
14
|
+
addDebugLog
|
|
15
|
+
} from '../../util.js';
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export default async options => {
|
|
21
|
+
addDebugLog("restoreConfig", "", "+");
|
|
22
|
+
const isLibraryBased = getLibraryBased();
|
|
23
|
+
if (!isLibraryBased) {
|
|
24
|
+
console.log(`Command only supported for ${chalk.bold.green('library based')} components.`);
|
|
25
|
+
process.exit();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await showVersion();
|
|
29
|
+
|
|
30
|
+
const restoreAns = await inquirer.prompt([
|
|
31
|
+
|
|
32
|
+
{
|
|
33
|
+
name: 'restoreDev',
|
|
34
|
+
type: 'confirm',
|
|
35
|
+
message: 'Also restore package dependencies/devDepencies ?',
|
|
36
|
+
default: false
|
|
37
|
+
},
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
await restoreTopLevelConfigFilesFromTemplate(false);
|
|
41
|
+
console.log(chalk.green("Original config files restored."));
|
|
42
|
+
|
|
43
|
+
if (restoreAns.restoreDev) {
|
|
44
|
+
await restoreDependenciesFromTemplate();
|
|
45
|
+
console.log(chalk.green("Package dependencies and devDependencies restored."));
|
|
46
|
+
|
|
47
|
+
console.log('\n***************************************************************');
|
|
48
|
+
console.log(chalk.bold.yellow('Dependencies have changed, recommend updating.'));
|
|
49
|
+
console.log(`>>> PLEASE run ${chalk.bold.yellow("'npm update'")}.`);
|
|
50
|
+
console.log('***************************************************************\n');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
addDebugLog("restoreConfig", "END", "-");
|
|
55
|
+
|
|
56
|
+
};
|
package/src/util.js
CHANGED
|
@@ -604,7 +604,7 @@ if (showDebug) addDebugLog("getTemplateConfigFiles", ``, "");
|
|
|
604
604
|
|
|
605
605
|
}
|
|
606
606
|
|
|
607
|
-
export const restoreTopLevelConfigFilesFromTemplate = async() => {
|
|
607
|
+
export const restoreTopLevelConfigFilesFromTemplate = async(clearDep = true) => {
|
|
608
608
|
if (showDebug) addDebugLog("restoreTopLevelConfigFilesFromTemplate", ``, "");
|
|
609
609
|
// we can't loose devDep that is part of install, so go get the template mustache and push
|
|
610
610
|
// those in, replacing any changes there, but allowing additional, an keeping it updated
|
|
@@ -661,9 +661,10 @@ if (showDebug) addDebugLog("restoreTopLevelConfigFilesFromTemplate", ``, "");
|
|
|
661
661
|
|
|
662
662
|
|
|
663
663
|
// clear out
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
664
|
+
if (clearDep) {
|
|
665
|
+
cData.dependencies = {};
|
|
666
|
+
cData.devDependencies = {};
|
|
667
|
+
}
|
|
667
668
|
|
|
668
669
|
|
|
669
670
|
const tDep = tData.dependencies;
|
|
@@ -1557,10 +1558,13 @@ if (showDebug) addDebugLog("getComponentsConfigs", "", "");
|
|
|
1557
1558
|
const componentDirectory = await getComponentDirectoryPath(componentKey, compDir);
|
|
1558
1559
|
const configPath = join(componentDirectory, 'config.json');
|
|
1559
1560
|
|
|
1560
|
-
|
|
1561
|
+
if (fs.existsSync(configPath)) {
|
|
1562
|
+
let data = fs.readFileSync(configPath, { encoding: 'utf8' });
|
|
1563
|
+
|
|
1564
|
+
data = JSON.parse(data);
|
|
1565
|
+
componentsConfigJSON.push(data);
|
|
1566
|
+
}
|
|
1561
1567
|
|
|
1562
|
-
data = JSON.parse(data);
|
|
1563
|
-
componentsConfigJSON.push(data);
|
|
1564
1568
|
|
|
1565
1569
|
}
|
|
1566
1570
|
}
|
|
@@ -1722,7 +1726,7 @@ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
|
|
|
1722
1726
|
retrievedPackageData = fs.readFileSync(tempPackagePath);
|
|
1723
1727
|
}
|
|
1724
1728
|
catch (ex) {
|
|
1725
|
-
console.log(
|
|
1729
|
+
console.log(chalk.red(`\nUnable to retrieve package.json from store.`))
|
|
1726
1730
|
process.exit(1);
|
|
1727
1731
|
}
|
|
1728
1732
|
|
|
@@ -1730,7 +1734,7 @@ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
|
|
|
1730
1734
|
currentPackageData = fs.readFileSync(currentPackagePath);
|
|
1731
1735
|
}
|
|
1732
1736
|
catch (ex) {
|
|
1733
|
-
console.log(
|
|
1737
|
+
console.log(chalk.red(`\nUnable to retrieve current package.json.`))
|
|
1734
1738
|
process.exit(1);
|
|
1735
1739
|
}
|
|
1736
1740
|
|
|
@@ -1795,6 +1799,63 @@ if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
|
|
|
1795
1799
|
|
|
1796
1800
|
}
|
|
1797
1801
|
|
|
1802
|
+
|
|
1803
|
+
export const restoreDependenciesFromTemplate = async () => {
|
|
1804
|
+
if (showDebug) addDebugLog("restoreDependenciesFromTemplate", "", "");
|
|
1805
|
+
const currentDirectory = process.cwd();
|
|
1806
|
+
const currentPackagePath = join(currentDirectory, PACKAGE_JSON_FILENAME);
|
|
1807
|
+
|
|
1808
|
+
let currentPackageData;
|
|
1809
|
+
|
|
1810
|
+
// reset
|
|
1811
|
+
haveDependencyDifference = true;
|
|
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
|
+
let cData = JSON.parse(currentPackageData);
|
|
1823
|
+
|
|
1824
|
+
|
|
1825
|
+
// we can't loose devDep that is part of install, so go get the template mustache and push
|
|
1826
|
+
// those in, replacing any changes there, but allowing additional, an keeping it updated
|
|
1827
|
+
// so won't loose new function if an old archive
|
|
1828
|
+
const initDir = join(currentDirectory, "node_modules", "@pega", "custom-dx-components", "src", "tasks", "init");
|
|
1829
|
+
const templateDir = join(initDir, "template");
|
|
1830
|
+
const packageTemplateJsonPath = path.join(templateDir, 'package.json.mustache');
|
|
1831
|
+
let retrievedTemplateData;
|
|
1832
|
+
try {
|
|
1833
|
+
retrievedTemplateData = fs.readFileSync(packageTemplateJsonPath);
|
|
1834
|
+
}
|
|
1835
|
+
catch (ex) {
|
|
1836
|
+
console.log($chalk.red(`\nUnable to retrieve package.json.mustache from code.`))
|
|
1837
|
+
process.exit(1);
|
|
1838
|
+
}
|
|
1839
|
+
const tData = JSON.parse(retrievedTemplateData);
|
|
1840
|
+
const tDevDep = tData.devDependencies;
|
|
1841
|
+
const tDep = tData.dependencies;
|
|
1842
|
+
|
|
1843
|
+
for (const [key, value] of Object.entries(tDevDep)) {
|
|
1844
|
+
cData.devDependencies[key] = value;
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
for (const [key, value] of Object.entries(tDep)) {
|
|
1848
|
+
cData.dependencies[key] = value;
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
|
|
1852
|
+
// update current package json file
|
|
1853
|
+
fs.writeFileSync(currentPackagePath, JSON.stringify(cData, null, 4), { encoding: 'utf8',flag:'w' });
|
|
1854
|
+
|
|
1855
|
+
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
|
|
1798
1859
|
export const restoreDependenciesFromPackage_old = async () => {
|
|
1799
1860
|
if (showDebug) addDebugLog("restoreDependenciesFromPackage", "", "");
|
|
1800
1861
|
const currentDirectory = process.cwd();
|