@pega/custom-dx-components 0.25.18 → 0.25.20
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/constants.js +3 -1
- package/src/tasks/build-jest-assets/index.js +5 -5
- package/src/tasks/create-version/helper.js +30 -0
- package/src/tasks/create-version/index.js +12 -4
- package/src/tasks/delete-pub/helper.js +1 -1
- package/src/tasks/delete-pub/index.js +6 -1
- package/src/tasks/export-archive/helper.js +12 -12
- package/src/tasks/export-archive/index.js +6 -0
- package/src/tasks/import-archive/helper.js +205 -3
- package/src/tasks/import-archive/index.js +146 -31
- package/src/tasks/index.js +1 -0
- package/src/tasks/init/template/package.json.mustache +2 -1
- package/src/tasks/list-pub/helper.js +3 -3
- package/src/tasks/publish-archive/index.js +5 -2
- package/src/tasks/restore/index.js +72 -0
- package/src/tasks/show-help/index.js +25 -7
- package/src/tasks/show-status/index.js +10 -6
- package/src/util.js +58 -1
- package/tests/assets/library/components/create/Pega_DXIL_MyTestText/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyBoolean/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyCaseWidget/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyCaseWidget/localizations.json +8 -0
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyCurrency/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDate/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDateTime/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDecimal/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDetails/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyEmail/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyForm/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyIconButtonURL/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyIconButtonURL/localizations.json +10 -0
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyInteger/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPage/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPageCaseWidget/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPageWidget/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPageWidget/localizations.json +10 -0
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyParagraph/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPercentage/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPhone/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPicklist/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyRadiobuttons/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MySearchbox/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MySearchbox/localizations.json +5 -0
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyText/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTextInput/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTimeOfDay/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTwoColumnForm/config.json +1 -1
- package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyURL/config.json +1 -1
- package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyCaseWidget/localizations.json +8 -0
- package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyIconButtonURL/localizations.json +10 -0
- package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyPageWidget/localizations.json +10 -0
- package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MySearchbox/localizations.json +5 -0
- package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MySearchbox/localizations.json +5 -0
- package/tests/functional/localCreateAllListDeleteAll.test.js +8 -8
- package/tests/functional/localLibCreateLibAlreadyDeleteLib.test.js +14 -14
- package/tests/functional/localLibCreateLibBuildLibDeleteLib.test.js +17 -17
- package/tests/functional/localLibCreateLibBuildLibListPubDeleteLib.test.js +20 -20
- package/tests/functional/localLibCreateLibDeleteLib.test.js +17 -17
- package/tests/functional/localLibCreateLibExportImportLib.test.js +27 -27
- package/tests/functional/localLibCreateLibExportLib.test.js +19 -19
- package/tests/functional/localLibCreateLibImportCompDeleteLib.test.js +14 -14
- package/tests/functional/localLibCreateLibListDeleteLib.test.js +22 -22
- package/tests/functional/localLibCreateLibListMoveDeleteLib.test.js +31 -31
- package/tests/functional/localLibCreateLibListSwitchDeleteLib.test.js +20 -20
- package/tests/functional/localLibCreateLibStatusDeleteLib.test.js +13 -29
- package/tests/functional/localLibCreateLibValidateDeleteLib.test.js +15 -15
- package/tests/functional/localLibCreateLibVersionDeleteLib.test.js +27 -27
- package/tests/functional/localLibCreateLibPermDeleteLib.test.js +0 -144
|
@@ -6,6 +6,7 @@ import inquirer from 'inquirer';
|
|
|
6
6
|
import ncp from 'ncp';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
import { Listr } from 'listr2';
|
|
9
|
+
import archiver from 'archiver';
|
|
9
10
|
|
|
10
11
|
import StreamZip from 'node-stream-zip';
|
|
11
12
|
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
showVersion,
|
|
18
19
|
getDirectoryFiles,
|
|
19
20
|
addDebugLog,
|
|
21
|
+
checkAccessTokenExpiration,
|
|
20
22
|
checkLibraryAndArchives,
|
|
21
23
|
getConfigDefaults,
|
|
22
24
|
getLibraryBased,
|
|
@@ -31,7 +33,7 @@ import {
|
|
|
31
33
|
getLibraryBasedCL
|
|
32
34
|
} from '../../util.js';
|
|
33
35
|
import { TASKS_CONFIG_JSON_FILENAME, ARCHIVES_PATH, TEMP_PATH } from '../../constants.js';
|
|
34
|
-
import { getFilePathQuestions, getFileNameQuestions, updateTempArchive, updateSavedFilePath } from './helper.js';
|
|
36
|
+
import { getFilePathQuestions, getFileNameQuestions, updateTempArchive, updateSavedFilePath, getServerOrDirectoryQuestion, getLibraryArchiveQuestion, getServerLibraryArchives, getServerLibraryArchive } from './helper.js';
|
|
35
37
|
import { showCurrentStatus } from '../show-status/index.js';
|
|
36
38
|
|
|
37
39
|
export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
|
|
@@ -236,6 +238,8 @@ addDebugLog("importArch", `filePath: ${filePath}, fileName: ${fileName}`, "");
|
|
|
236
238
|
|
|
237
239
|
const currentDirectory = process.cwd();
|
|
238
240
|
const tempDirectory = join(currentDirectory, TEMP_PATH);
|
|
241
|
+
|
|
242
|
+
|
|
239
243
|
const zipFilePath = join(filePath, fileName);
|
|
240
244
|
|
|
241
245
|
|
|
@@ -274,6 +278,8 @@ addDebugLog("importArch", `filePath: ${filePath}, fileName: ${fileName}`, "");
|
|
|
274
278
|
|
|
275
279
|
await unZipFromArchive(zipFilePath);
|
|
276
280
|
|
|
281
|
+
|
|
282
|
+
|
|
277
283
|
// if (!fs.existsSync(tempTasksConfig) || !fs.existsSync(tempPackage)) {
|
|
278
284
|
// console.log(chalk.red.bold(`Zip file: ${fileName} not a compatible DX Component archive.`));
|
|
279
285
|
// console.log(chalk.red.bold("Cleaning up..."));
|
|
@@ -431,6 +437,37 @@ export const getZipFileList = async(filePath) => {
|
|
|
431
437
|
}
|
|
432
438
|
}
|
|
433
439
|
|
|
440
|
+
function decodeBase64(encodedString) {
|
|
441
|
+
try {
|
|
442
|
+
const decodedString = atob(encodedString);
|
|
443
|
+
return decodedString;
|
|
444
|
+
} catch (error) {
|
|
445
|
+
console.error("Error decoding base64 string:", error);
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export const writeZipBuffer = async(fileName, fileBuffer) => {
|
|
451
|
+
const currentDirectory = process.cwd();
|
|
452
|
+
const tempDirectory = join(currentDirectory, TEMP_PATH);
|
|
453
|
+
|
|
454
|
+
// have to decode it and then re-encode it.
|
|
455
|
+
let decodedString;
|
|
456
|
+
try {
|
|
457
|
+
decodedString = atob(fileBuffer);
|
|
458
|
+
} catch (error) {
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (!fs.existsSync (tempDirectory)) {
|
|
462
|
+
fs.mkdirSync(tempDirectory);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const filePath = join(tempDirectory, fileName);
|
|
466
|
+
|
|
467
|
+
fs.writeFileSync(filePath, fileBuffer, 'base64');
|
|
468
|
+
|
|
469
|
+
}
|
|
470
|
+
|
|
434
471
|
export default async options => {
|
|
435
472
|
await showVersion();
|
|
436
473
|
// await checkLibraryAndArchives();
|
|
@@ -449,9 +486,11 @@ export default async options => {
|
|
|
449
486
|
addDebugLog("importArchive", "", "+");
|
|
450
487
|
|
|
451
488
|
|
|
452
|
-
if (options.params.length >=
|
|
453
|
-
const
|
|
454
|
-
const
|
|
489
|
+
if (options.params.length >= 6) {
|
|
490
|
+
const localOrServer = options.params[3];
|
|
491
|
+
const filePath = options.params[4];
|
|
492
|
+
const fileName = options.params[5];
|
|
493
|
+
|
|
455
494
|
await importArch( filePath, fileName, hasArch);
|
|
456
495
|
|
|
457
496
|
}
|
|
@@ -459,43 +498,119 @@ export default async options => {
|
|
|
459
498
|
|
|
460
499
|
inquirer.registerPrompt('fuzzypath', inquirerFuzzyPath);
|
|
461
500
|
|
|
462
|
-
let filePathQuestions;
|
|
463
|
-
try {
|
|
464
|
-
filePathQuestions = await getFilePathQuestions();
|
|
465
|
-
}
|
|
466
|
-
catch (ex) {
|
|
467
|
-
process.exit(1);
|
|
468
|
-
}
|
|
469
501
|
|
|
502
|
+
const localOrServerQuestion = await getServerOrDirectoryQuestion();
|
|
503
|
+
const localOrServerAnswer = await inquirer.prompt(localOrServerQuestion);
|
|
504
|
+
const {importFrom} = localOrServerAnswer;
|
|
470
505
|
|
|
471
|
-
|
|
472
|
-
try {
|
|
473
|
-
filePathAnswers = await inquirer.prompt(filePathQuestions);
|
|
474
|
-
}
|
|
475
|
-
catch(ex) {
|
|
476
|
-
process.exit(1);
|
|
477
|
-
}
|
|
506
|
+
if (importFrom === "Server") {
|
|
478
507
|
|
|
479
|
-
const { filePath } = filePathAnswers;
|
|
480
|
-
const zipFileList = await getZipFileList(filePath);
|
|
481
508
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
509
|
+
await checkAccessTokenExpiration();
|
|
510
|
+
|
|
511
|
+
let archiveVersions = [];
|
|
512
|
+
try {
|
|
513
|
+
archiveVersions = await getServerLibraryArchives();
|
|
514
|
+
}
|
|
515
|
+
catch (ex) {
|
|
516
|
+
console.log(chalk.redBright(ex));
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
if (archiveVersions && archiveVersions.pxResults.length > 0) {
|
|
521
|
+
// ALL option
|
|
522
|
+
|
|
523
|
+
// to name value pairs
|
|
524
|
+
const archiveResults = archiveVersions["pxResults"].map( archive => ( { value: `${archive.pyApplicationName},${archive.pyFileName},${archive.pyFileType},${archive.pyRuleSet},${archive.pyRuleSetVersion}`, name: `${archive.pyLabel}, ${archive.pyRuleSet}:${archive.pyRuleSetVersion}` }) );
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
const versionQuestions = await getLibraryArchiveQuestion(archiveResults);
|
|
528
|
+
const versionAnswers = await inquirer.prompt(versionQuestions);
|
|
529
|
+
|
|
530
|
+
const {archiveData} = versionAnswers;
|
|
531
|
+
|
|
532
|
+
if (archiveData != "") {
|
|
533
|
+
|
|
534
|
+
const arArchData = archiveData.split(",");
|
|
535
|
+
let fileName = `${arArchData[1]}.${arArchData[2]}`;
|
|
536
|
+
// get archive
|
|
537
|
+
const fileData = await getServerLibraryArchive(arArchData[0],arArchData[1], arArchData[2], arArchData[3], arArchData[4]);
|
|
538
|
+
|
|
539
|
+
// console.log(fileSource);
|
|
540
|
+
|
|
541
|
+
// fileName = "big.zip";
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
await writeZipBuffer(fileName, fileData.pyFileSource);
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
// import archive
|
|
549
|
+
const currentDirectory = process.cwd();
|
|
550
|
+
const tempDirectory = join(currentDirectory, TEMP_PATH);
|
|
551
|
+
|
|
552
|
+
await importArch( tempDirectory, fileName, hasArch);
|
|
553
|
+
// const zipFilePath = join(tempDirectory, fileName);
|
|
554
|
+
//await unZipFromArchive(zipFilePath);
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
// No library with that name
|
|
566
|
+
console.log(chalk.redBright(`No library archives exist on server.`));
|
|
567
|
+
process.exit(1);
|
|
568
|
+
|
|
569
|
+
}
|
|
570
|
+
|
|
485
571
|
}
|
|
572
|
+
else {
|
|
573
|
+
let filePathQuestions;
|
|
574
|
+
try {
|
|
575
|
+
filePathQuestions = await getFilePathQuestions();
|
|
576
|
+
}
|
|
577
|
+
catch (ex) {
|
|
578
|
+
process.exit(1);
|
|
579
|
+
}
|
|
486
580
|
|
|
487
|
-
await updateSavedFilePath(filePath);
|
|
488
581
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
582
|
+
let filePathAnswers;
|
|
583
|
+
try {
|
|
584
|
+
filePathAnswers = await inquirer.prompt(filePathQuestions);
|
|
585
|
+
}
|
|
586
|
+
catch(ex) {
|
|
587
|
+
process.exit(1);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const { filePath } = filePathAnswers;
|
|
591
|
+
const zipFileList = await getZipFileList(filePath);
|
|
592
|
+
|
|
593
|
+
if (!zipFileList || zipFileList.length === 0) {
|
|
594
|
+
console.log(chalk.red.bold(`No zip files exist at path: ${filePath}`));
|
|
595
|
+
process.exit();
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
await updateSavedFilePath(filePath);
|
|
599
|
+
|
|
600
|
+
const fileNameQuestions = await getFileNameQuestions(zipFileList);
|
|
601
|
+
const fileNameAnswers = await inquirer.prompt(fileNameQuestions);
|
|
602
|
+
const {fileName} = fileNameAnswers;
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
await importArch( filePath, fileName, hasArch);
|
|
606
|
+
|
|
607
|
+
// reapply to save if changed, because imported task.config may have overriden and we want
|
|
608
|
+
// to keep what was entered as the latest
|
|
609
|
+
await updateSavedFilePath(filePath);
|
|
610
|
+
}
|
|
492
611
|
|
|
493
612
|
|
|
494
|
-
await importArch( filePath, fileName, hasArch);
|
|
495
613
|
|
|
496
|
-
// reapply to save if changed, because imported task.config may have overriden and we want
|
|
497
|
-
// to keep what was entered as the latest
|
|
498
|
-
await updateSavedFilePath(filePath);
|
|
499
614
|
|
|
500
615
|
|
|
501
616
|
|
package/src/tasks/index.js
CHANGED
|
@@ -38,3 +38,4 @@ 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
40
|
export { default as restoreConfig } from './restore-config/index.js';
|
|
41
|
+
export { default as restore } from './restore/index.js';
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"deleteLibVersion": "custom-dx-components deleteVersion",
|
|
42
42
|
"move": "custom-dx-components moveComponent",
|
|
43
43
|
"publishLibVersion": "custom-dx-components publish",
|
|
44
|
+
"restoreLibVersion": "custom-dx-components restore",
|
|
44
45
|
"storeLibVersion": "custom-dx-components storeComponents",
|
|
45
46
|
"showStatus": "custom-dx-components showStatus",
|
|
46
47
|
"setPermanent": "custom-dx-components setPermanent",
|
|
@@ -106,7 +107,7 @@
|
|
|
106
107
|
"@babel/preset-react": "^7.26.3",
|
|
107
108
|
"@babel/preset-typescript": "^7.26.0",
|
|
108
109
|
"@pega/configs": "^0.16.2",
|
|
109
|
-
"@pega/custom-dx-components": "~0.25.
|
|
110
|
+
"@pega/custom-dx-components": "~0.25.20",
|
|
110
111
|
"@pega/pcore-pconnect-typedefs": "^4.1.0-alpha.1",
|
|
111
112
|
"@storybook/addon-actions": "^7.6.19",
|
|
112
113
|
"@storybook/addon-essentials": "^7.6.19",
|
|
@@ -83,8 +83,8 @@ addDebugLog("listLibJSONResponse", "services end", "");
|
|
|
83
83
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
async function
|
|
87
|
-
addDebugLog("
|
|
86
|
+
async function fetchComponentLibrariesFromInfinity(apiUrl, headers) {
|
|
87
|
+
addDebugLog("fetchComponentLibrariesFromInfinity", `apiUrl: ${apiUrl}`, "");
|
|
88
88
|
const serverConfig = await getPegaServerConfig();
|
|
89
89
|
return new Promise((resolve, reject) => {
|
|
90
90
|
let status = 500;
|
|
@@ -161,7 +161,7 @@ addDebugLog("getInfinityLibraries", '', "");
|
|
|
161
161
|
const headers = {};
|
|
162
162
|
headers.Authorization = `${tokenType} ${accessToken}`;
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
fetchComponentLibrariesFromInfinity(url, headers)
|
|
165
165
|
.then((response) => resolve(response))
|
|
166
166
|
.catch((e) => reject(e));
|
|
167
167
|
|
|
@@ -11,7 +11,7 @@ import { getPublishComponentQuestions } from './helper.js';
|
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT,
|
|
14
|
-
|
|
14
|
+
PUBLISH_COMPONENT_LIBRARY_ARCHIVE_SERVICE_REST_ENDPOINT,
|
|
15
15
|
TEMP_PATH,
|
|
16
16
|
TOKEN_PATH,
|
|
17
17
|
ARCHIVES_PATH
|
|
@@ -56,7 +56,7 @@ export const publishComponentLibraryArchiveToServer = async (data, doFetch) => {
|
|
|
56
56
|
const defaultPegaConfig = await getPegaServerConfig();
|
|
57
57
|
const url = constructCompleteUrl(
|
|
58
58
|
defaultPegaConfig.server,
|
|
59
|
-
isLaunchpad ? launchpadRestEndpoint :
|
|
59
|
+
isLaunchpad ? launchpadRestEndpoint : PUBLISH_COMPONENT_LIBRARY_ARCHIVE_SERVICE_REST_ENDPOINT
|
|
60
60
|
);
|
|
61
61
|
|
|
62
62
|
if (doFetch) {
|
|
@@ -157,6 +157,7 @@ export default async (orgLibName, selectedVersion) => {
|
|
|
157
157
|
|
|
158
158
|
if (orgLibName === configDef.currentOrgLib && selectedVersion === configDef.buildVersion) {
|
|
159
159
|
|
|
160
|
+
/*
|
|
160
161
|
console.log("\nYou've selected the current working library/version.");
|
|
161
162
|
console.log("Export store or the current.");
|
|
162
163
|
const archAnswers = await inquirer.prompt([
|
|
@@ -174,6 +175,8 @@ export default async (orgLibName, selectedVersion) => {
|
|
|
174
175
|
if (currentOrStore === "Current") {
|
|
175
176
|
archiveBeforeStore = true;
|
|
176
177
|
}
|
|
178
|
+
*/
|
|
179
|
+
archiveBeforeStore = true;
|
|
177
180
|
|
|
178
181
|
if (archiveBeforeStore) {
|
|
179
182
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
import { Listr } from 'listr2';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import inquirer from 'inquirer';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
showVersion,
|
|
8
|
+
addDebugLog,
|
|
9
|
+
checkLibraryAndArchives,
|
|
10
|
+
getConfigDefaults,
|
|
11
|
+
getLibraryBased,
|
|
12
|
+
restoreFromArchive,
|
|
13
|
+
cleanUpTemp
|
|
14
|
+
} from '../../util.js';
|
|
15
|
+
|
|
16
|
+
export default async options => {
|
|
17
|
+
await showVersion();
|
|
18
|
+
await checkLibraryAndArchives();
|
|
19
|
+
|
|
20
|
+
addDebugLog("restoreComponent", "", "+");
|
|
21
|
+
|
|
22
|
+
await cleanUpTemp();
|
|
23
|
+
|
|
24
|
+
const isLibraryBased = getLibraryBased();
|
|
25
|
+
if (!isLibraryBased) {
|
|
26
|
+
console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`)
|
|
27
|
+
process.exit();
|
|
28
|
+
}
|
|
29
|
+
const confDef = getConfigDefaults();
|
|
30
|
+
|
|
31
|
+
console.log(chalk.bold.yellow('\nChanges not saved to local storage will be LOST, code will be restored from local storage.'));
|
|
32
|
+
console.log("");
|
|
33
|
+
|
|
34
|
+
const restoreFromStore = await inquirer.prompt([
|
|
35
|
+
{
|
|
36
|
+
name: 'confirmRestore',
|
|
37
|
+
type: 'confirm',
|
|
38
|
+
message: `Restoring ${chalk.bold.green(`${confDef.displayLibVersion}`)} from local storage, proceed ?`,
|
|
39
|
+
default: true
|
|
40
|
+
}
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
if (restoreFromStore.confirmRestore) {
|
|
44
|
+
const switchToFileName = `${confDef.currentOrgLib}_${confDef.version}.arch.zip`;
|
|
45
|
+
const tasks = new Listr(
|
|
46
|
+
[
|
|
47
|
+
{
|
|
48
|
+
title: `Restoring ${confDef.displayLibVersion}`,
|
|
49
|
+
task: async () => {
|
|
50
|
+
// await zipVersionAndArchive(confDef.currentOrgLib, confDef.buildVersion);
|
|
51
|
+
await restoreFromArchive(switchToFileName, confDef.currentOrgLib, confDef.version);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
{ concurrent: false, exitOnError: true }
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
await tasks.run().catch(err => {
|
|
59
|
+
console.log(chalk.bold.red(err.toString()));
|
|
60
|
+
addDebugLog("restoreComponent", "", "-");
|
|
61
|
+
process.exit(1);
|
|
62
|
+
});
|
|
63
|
+
console.log(chalk.greenBright('\nComponents restored'));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
addDebugLog("restoreComponent", "", "-");
|
|
71
|
+
|
|
72
|
+
};
|
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
|
|
6
|
-
import { showVersion, getLibraryBased } from '../../util.js';
|
|
6
|
+
import { showVersion, getLibraryBased, getLibraryBasedCL } from '../../util.js';
|
|
7
7
|
|
|
8
8
|
export const showCurrentStatus = async () => {
|
|
9
9
|
|
|
@@ -58,9 +58,11 @@ export const showHelpV1 = () => {
|
|
|
58
58
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
export const showHelpV2 = () => {
|
|
61
|
+
export const showHelpV2 = (isCL) => {
|
|
62
62
|
console.log("");
|
|
63
|
-
|
|
63
|
+
if (!isCL) {
|
|
64
|
+
console.log(chalk.yellow("**** Beta capability and subject to change. Developer experimental. Do not use in a Production Deployment. ***\n"));
|
|
65
|
+
}
|
|
64
66
|
console.log(`--> All commands will not work until a library is created via ${chalk.cyan(`npm run createLib`)}.`);
|
|
65
67
|
console.log(`\nnpm run <command>`);
|
|
66
68
|
console.log(`\nUsage:`);
|
|
@@ -80,10 +82,18 @@ export const showHelpV2 = () => {
|
|
|
80
82
|
console.log(`${chalk.cyan('npm run createLibVersion')}\tcreate a new version within the current library`);
|
|
81
83
|
console.log(`${chalk.cyan('npm run switchLibVersion')}\tswitch to different version within the current library`);
|
|
82
84
|
console.log(`${chalk.cyan('npm run deleteLibVersion')}\tdelete current version, move to another version`);
|
|
85
|
+
console.log(`${chalk.cyan('npm run restoreLibVersion ')}\trestore current version from local storage (current changes will be LOST)`);
|
|
83
86
|
console.log(`${chalk.cyan('npm run storeLibVersion ')}\tstore current version to local storage (must SAVE components before)`);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
if (isCL) {
|
|
88
|
+
console.log(`${chalk.cyan('npm run exportLibVersion')}\texport current version as a zip file to a given local path or a server (must SAVE components before)`);
|
|
89
|
+
console.log(`${chalk.cyan('npm run importLibVersion')}\timport a zip file (created by export) from a given local path or a server`);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
console.log(`${chalk.cyan('npm run exportLibVersion')}\texport current version as a zip file to a given local path (must SAVE components before)`);
|
|
93
|
+
console.log(`${chalk.cyan('npm run importLibVersion')}\timport a zip file (created by export) from a given local path`);
|
|
94
|
+
console.log(`${chalk.cyan('npm run setPermanent ')}\tmake current version permanent or non permanent upon publish`);
|
|
95
|
+
}
|
|
96
|
+
|
|
87
97
|
|
|
88
98
|
console.log(`\n${chalk.underline(`Published Versions (needs authentication)`)}`);
|
|
89
99
|
console.log(`${chalk.cyan('npm run publish ')}\tpublish current library/version to server (creates a local published library as well)`);
|
|
@@ -109,17 +119,25 @@ export const showHelpV2 = () => {
|
|
|
109
119
|
console.log(`${chalk.cyan(`createLib, switchLib, createLibVersion, switchLibVersion, publishLibVersion, exportLibVersion`)}`);
|
|
110
120
|
console.log(`\nWhen editing in an IDE, always ${chalk.yellow("SAVE")} changes to components before doing a library/version context switch`);
|
|
111
121
|
console.log(`or changes will be lost!`);
|
|
122
|
+
console.log(`\nStoring is to LOCAL storage and is not backed up. You should export your library/versions archives to ${chalk.yellow("git")}`);
|
|
123
|
+
if (isCL) {
|
|
124
|
+
console.log(`or export archives to ${chalk.yellow("server")} for backup storage.`);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.log(`for backup storage.`);
|
|
128
|
+
}
|
|
112
129
|
console.log("");
|
|
113
130
|
}
|
|
114
131
|
|
|
115
132
|
|
|
116
133
|
export default async options => {
|
|
117
134
|
const isLibraryBased = getLibraryBased();
|
|
135
|
+
const isLibraryBasedCL = getLibraryBasedCL();
|
|
118
136
|
|
|
119
137
|
await showVersion();
|
|
120
138
|
|
|
121
139
|
if (isLibraryBased) {
|
|
122
|
-
await showHelpV2();
|
|
140
|
+
await showHelpV2(isLibraryBasedCL);
|
|
123
141
|
}
|
|
124
142
|
else {
|
|
125
143
|
await showHelpV1();
|
|
@@ -3,12 +3,13 @@ import path from 'path';
|
|
|
3
3
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
|
|
6
|
-
import { showVersion, getLibraryBased, addDebugLog, getConfigDefaults, getComponents, checkLibraryAndArchives } from '../../util.js';
|
|
6
|
+
import { showVersion, getLibraryBased, addDebugLog, getConfigDefaults, getComponents, checkLibraryAndArchives, getLibraryBasedCL } from '../../util.js';
|
|
7
7
|
|
|
8
8
|
export const showCurrentStatus = async () => {
|
|
9
9
|
|
|
10
10
|
const configDefaults = getConfigDefaults();
|
|
11
11
|
const componentList = await getComponents();
|
|
12
|
+
const isLibraryBasedCL = getLibraryBasedCL();
|
|
12
13
|
|
|
13
14
|
console.log("");
|
|
14
15
|
console.log("\tCurrent status");
|
|
@@ -16,12 +17,15 @@ export const showCurrentStatus = async () => {
|
|
|
16
17
|
console.log(`\tOrganization:\t ${chalk.bold.green(`${configDefaults.organization}`)}`);
|
|
17
18
|
console.log(`\tLibrary:\t ${chalk.bold.green(`${configDefaults.library}`)}`);
|
|
18
19
|
console.log(`\tVersion:\t ${chalk.bold.green(`${configDefaults.buildVersion}`)}`);
|
|
19
|
-
if (!
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
if (!isLibraryBasedCL) {
|
|
21
|
+
if (!configDefaults.devBuild) {
|
|
22
|
+
console.log(`\tPermanent:\t ${chalk.bold.magentaBright(`${!configDefaults.devBuild}`)}`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
console.log(`\tPermanent:\t ${chalk.bold.green(`${!configDefaults.devBuild}`)}`);
|
|
26
|
+
}
|
|
24
27
|
}
|
|
28
|
+
|
|
25
29
|
console.log(`\tComponent count: ${chalk.bold.green(`${componentList.length}`)}`);
|
|
26
30
|
|
|
27
31
|
console.log("");
|
package/src/util.js
CHANGED
|
@@ -155,6 +155,11 @@ export const setUpDefaults = async () => {
|
|
|
155
155
|
|
|
156
156
|
if (data[LIBRARY_BASED_CL]) {
|
|
157
157
|
retrievedConfigData.isLibraryBasedCL = data[LIBRARY_BASED_CL];
|
|
158
|
+
|
|
159
|
+
// if this is true, then force librarybased to true, so it doesn't have to be set
|
|
160
|
+
if (retrievedConfigData.isLibraryBasedCL) {
|
|
161
|
+
retrievedConfigData.isLibraryBased = retrievedConfigData.isLibraryBasedCL;
|
|
162
|
+
}
|
|
158
163
|
}
|
|
159
164
|
|
|
160
165
|
|
|
@@ -470,6 +475,55 @@ if (showDebug) addDebugLog("setLibraryBased", "", "");
|
|
|
470
475
|
|
|
471
476
|
}
|
|
472
477
|
|
|
478
|
+
export const setLibraryBasedCL = async (isLibraryBasedCL) => {
|
|
479
|
+
if (showDebug) addDebugLog("setLibraryBased", "", "");
|
|
480
|
+
const currentDirectory = process.cwd();
|
|
481
|
+
const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
|
|
482
|
+
|
|
483
|
+
try {
|
|
484
|
+
// force to throw error and not console log
|
|
485
|
+
await checkPathAccess(pegaConfigJsonPath, {}, true);
|
|
486
|
+
}
|
|
487
|
+
catch (ex) {
|
|
488
|
+
// when can't find it, always be false, assume no library based.
|
|
489
|
+
// This is IMPORTANT for init (npx install)
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
|
|
494
|
+
data = JSON.parse(data);
|
|
495
|
+
|
|
496
|
+
if (data[LIBRARY_BASED_CL] != undefined) {
|
|
497
|
+
data[LIBRARY_BASED_CL] = isLibraryBasedCL;
|
|
498
|
+
|
|
499
|
+
// if not undefined, force this as well
|
|
500
|
+
if (data[LIBRARY_BASED] != undefined) {
|
|
501
|
+
data[LIBRARY_BASED] = isLibraryBasedCL;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// update file
|
|
505
|
+
// stringify "4", makes the json string look like JSON in the file, formated instead of a single line
|
|
506
|
+
try {
|
|
507
|
+
fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(data, null, 4), { encoding: 'utf8',flag:'w' });
|
|
508
|
+
}
|
|
509
|
+
catch (err) {
|
|
510
|
+
console.error(err);
|
|
511
|
+
}
|
|
512
|
+
//await forceDefaultsUpdate();
|
|
513
|
+
defaultConfigs.isLibraryBasedCL = isLibraryBasedCL;
|
|
514
|
+
|
|
515
|
+
// force libraryBased if isLibraryBasedCL is true
|
|
516
|
+
defaultConfigs.isLibraryBased = isLibraryBasedCL;
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
// reset
|
|
520
|
+
pegaData = null;
|
|
521
|
+
pegaConfig = null;
|
|
522
|
+
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
}
|
|
526
|
+
|
|
473
527
|
export const getShowDebug = () => {
|
|
474
528
|
// const currentDirectory = process.cwd();
|
|
475
529
|
// const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
|
|
@@ -1847,6 +1901,9 @@ if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, v
|
|
|
1847
1901
|
|
|
1848
1902
|
};
|
|
1849
1903
|
|
|
1904
|
+
|
|
1905
|
+
|
|
1906
|
+
|
|
1850
1907
|
export const zipVersionAndArchiveAndReturnBuffer = async (orgLibName, version, currentDirectory = "") => {
|
|
1851
1908
|
if (showDebug) addDebugLog("zipVersionAndArchive", `orgLibName: ${orgLibName}, version: ${version}`, "");
|
|
1852
1909
|
// const srcDirectoryPath = await getSrcDirectoryPath();
|
|
@@ -1963,7 +2020,7 @@ export const zipUnArchiveToTempAndReturnBuffer = async(orgLibName, version) => {
|
|
|
1963
2020
|
for (const configF of configFiles) {
|
|
1964
2021
|
if (configF !== "package-lock.json") {
|
|
1965
2022
|
archive.file(
|
|
1966
|
-
join(
|
|
2023
|
+
join(tempDirectory, configF), { name: configF });
|
|
1967
2024
|
}
|
|
1968
2025
|
|
|
1969
2026
|
}
|