@pega/custom-dx-components 0.242.27 → 0.242.29
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 +30 -0
- package/src/constants.js +3 -2
- package/src/tasks/build-all/index.js +14 -1
- package/src/tasks/build-comp/helper.js +6 -4
- package/src/tasks/build-comp/index.js +12 -1
- package/src/tasks/bundle/builder/index.js +8 -6
- package/src/tasks/create/index.js +4 -2
- package/src/tasks/create-all/index.js +5 -3
- package/src/tasks/create-lib/index.js +4 -6
- package/src/tasks/create-version/helper.js +1 -0
- package/src/tasks/create-version/index.js +10 -6
- package/src/tasks/delete/index.js +1 -1
- package/src/tasks/delete-all/index.js +1 -1
- package/src/tasks/delete-lib/index.js +55 -32
- package/src/tasks/delete-pub/index.js +3 -2
- package/src/tasks/delete-version/index.js +45 -0
- package/src/tasks/export-archive/helper.js +85 -0
- package/src/tasks/export-archive/index.js +224 -0
- package/src/tasks/import-archive/helper.js +51 -0
- package/src/tasks/import-archive/index.js +301 -0
- package/src/tasks/index.js +5 -0
- package/src/tasks/init/template/package.json.mustache +20 -13
- package/src/tasks/list/helper.js +2 -2
- package/src/tasks/list/index.js +1 -1
- package/src/tasks/list-lib/index.js +8 -10
- package/src/tasks/list-pub/index.js +5 -5
- package/src/tasks/move/helper.js +56 -0
- package/src/tasks/move/index.js +441 -0
- package/src/tasks/promote-webpack/index.js +2 -3
- package/src/tasks/publish/index.js +1 -2
- package/src/tasks/publish-all/index.js +2 -2
- package/src/tasks/publish-lib/index.js +8 -4
- package/src/tasks/rename-lib/index.js +2 -3
- package/src/tasks/revert-webpack/index.js +2 -3
- package/src/tasks/show-status/index.js +2 -3
- package/src/tasks/store/index.js +53 -0
- package/src/tasks/switch-lib/index.js +4 -4
- package/src/tasks/switch-version/index.js +10 -6
- package/src/util.js +231 -179
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
+
"_***Component_and_Library_mode***": "Component and library mode commands",
|
|
8
9
|
"startStorybook": "storybook dev --port 6040 --quiet",
|
|
9
10
|
"lint": "eslint .",
|
|
10
11
|
"authenticate": "custom-dx-components authenticate",
|
|
@@ -12,27 +13,33 @@
|
|
|
12
13
|
"buildAllComponents": "custom-dx-components buildAllComponents",
|
|
13
14
|
"create": "custom-dx-components create",
|
|
14
15
|
"createAll": "custom-dx-components createAll",
|
|
15
|
-
"publish": "custom-dx-components publish",
|
|
16
|
-
"publishAll": "custom-dx-components publishAll",
|
|
17
16
|
"rename": "custom-dx-components rename",
|
|
18
17
|
"list": "custom-dx-components list",
|
|
19
18
|
"validate-schema": "custom-dx-components validateSchema",
|
|
20
19
|
"update": "custom-dx-components update",
|
|
21
20
|
"delete": "custom-dx-components delete",
|
|
22
21
|
"deleteAll": "custom-dx-components deleteAll",
|
|
22
|
+
"_***Component_mode_only***": "Component only commands",
|
|
23
|
+
"publish": "custom-dx-components publish",
|
|
24
|
+
"publishAll": "custom-dx-components publishAll",
|
|
23
25
|
"promoteWebPack": "custom-dx-components promoteWebPack",
|
|
24
26
|
"revertWebPack": "custom-dx-components revertWebPack",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
27
|
+
"_***Library_mode_only***": "Library mode only commands",
|
|
28
|
+
"createLib": "custom-dx-components createLibrary",
|
|
29
|
+
"switchLib": "custom-dx-components switchLibrary",
|
|
30
|
+
"createLibVersion": "custom-dx-components createVersion",
|
|
31
|
+
"switchLibVersion": "custom-dx-components switchVersion",
|
|
32
|
+
"listLib": "custom-dx-components listLibrary",
|
|
33
|
+
"listPublishedLib": "custom-dx-components listPublished",
|
|
34
|
+
"deleteLib": "custom-dx-components deleteLibrary",
|
|
35
|
+
"deletePublishedLib": "custom-dx-components deletePublished",
|
|
36
|
+
"deleteLibVersion": "custom-dx-components deleteVersion",
|
|
37
|
+
"publishLibVersion": "custom-dx-components publish",
|
|
38
|
+
"storeLibVersion": "custom-dx-components storeComponents",
|
|
35
39
|
"showStatus": "custom-dx-components showStatus",
|
|
40
|
+
"moveLibVersion": "custom-dx-components moveComponent",
|
|
41
|
+
"importLibVersion": "custom-dx-components importArchive",
|
|
42
|
+
"exportLibVersion": "custom-dx-components exportArchive",
|
|
36
43
|
"validate": "custom-dx-components buildComponent",
|
|
37
44
|
"validateAll": "custom-dx-components buildAllComponents",
|
|
38
45
|
"_internal-test-coverage": "node --input-type=module --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand node_modules/@pega/custom-dx-component --ci --testResultsProcessor='jest-junit' --coverage",
|
|
@@ -89,7 +96,7 @@
|
|
|
89
96
|
},
|
|
90
97
|
"devDependencies": {
|
|
91
98
|
"@pega/configs": "^0.6.0",
|
|
92
|
-
"@pega/custom-dx-components": "0.242.
|
|
99
|
+
"@pega/custom-dx-components": "0.242.29",
|
|
93
100
|
"@pega/pcore-pconnect-typedefs": "~3.0.0",
|
|
94
101
|
"@storybook/addon-actions": "^7.6.7",
|
|
95
102
|
"@storybook/addon-essentials": "^7.6.19",
|
package/src/tasks/list/helper.js
CHANGED
|
@@ -5,14 +5,13 @@ import fetch from 'node-fetch';
|
|
|
5
5
|
import { join } from 'path';
|
|
6
6
|
|
|
7
7
|
import { LIST_COMPONENT_SERVICE_REST_ENDPOINT, LP_LIST_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH, COMPONENT_SCHEMA, TASKS_CONFIG_JSON_FILENAME, COMPONENTS_DIRECTORY_PATH, COMPONENTS_PATH } from '../../constants.js';
|
|
8
|
-
import { constructCompleteUrl, getComponents, getPegaServerConfig, getHttpsAgent,
|
|
8
|
+
import { constructCompleteUrl, getComponents, getPegaServerConfig, getHttpsAgent, addDebugLog, getLibraryBased, getComponentsConfigs, getConfigDefaults } from '../../util.js';
|
|
9
9
|
|
|
10
10
|
export const SOURCE_OF_COMPONENT_TYPES = {
|
|
11
11
|
SERVER: 'Server',
|
|
12
12
|
LOCAL: 'Local'
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
const isLibraryBased = getLibraryBased();
|
|
16
15
|
|
|
17
16
|
export const getListComponentsQuestions = async (options) => {
|
|
18
17
|
addDebugLog("getListComponentsQuestions", "", "");
|
|
@@ -82,6 +81,7 @@ addDebugLog("getLaunchPadFilterQuestions", "", "");
|
|
|
82
81
|
export const listLocalComponents = async (sourceOfComponents) => {
|
|
83
82
|
addDebugLog("listLocalComponents", `sourceOfComponents: ${sourceOfComponents}`, "");
|
|
84
83
|
|
|
84
|
+
const isLibraryBased = getLibraryBased();
|
|
85
85
|
if (isLibraryBased) {
|
|
86
86
|
const defConfig = getConfigDefaults();
|
|
87
87
|
const data = await getComponentsConfigs();
|
package/src/tasks/list/index.js
CHANGED
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
getListComponentsQuestions
|
|
14
14
|
} from './helper.js';
|
|
15
15
|
|
|
16
|
-
const isLibraryBased = getLibraryBased();
|
|
17
16
|
|
|
18
17
|
const getList = async (sourceOfComponents, answers) => {
|
|
19
18
|
addDebugLog("getList", `sourceOfComponents: ${sourceOfComponents}`, "");
|
|
@@ -69,6 +68,7 @@ addDebugLog("getList", `sourceOfComponents: ${sourceOfComponents}`, "");
|
|
|
69
68
|
export default async (options) => {
|
|
70
69
|
await showVersion();
|
|
71
70
|
await checkLibraryAndArchives();
|
|
71
|
+
const isLibraryBased = getLibraryBased();
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
addDebugLog("list", "", "+");
|
|
@@ -4,13 +4,11 @@ import chalk from 'chalk';
|
|
|
4
4
|
import {showVersion, getLibraryBased, addDebugLog, checkLibraryAndArchives, getLibraryArchivesVersions, getConfigDefaults, getLocalArchivedLibrraryVersionData, getComponentsConfigs } from '../../util.js';
|
|
5
5
|
import { getArchiveLibraryQuestions } from './helper.js';
|
|
6
6
|
|
|
7
|
-
const isLibraryBased = getLibraryBased();
|
|
8
|
-
|
|
9
|
-
|
|
10
7
|
export default async (options) => {
|
|
8
|
+
const isLibraryBased = getLibraryBased();
|
|
11
9
|
|
|
12
10
|
if (!isLibraryBased) {
|
|
13
|
-
console.log(`Command only supported for ${chalk.bold.green('library
|
|
11
|
+
console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`)
|
|
14
12
|
process.exit();
|
|
15
13
|
}
|
|
16
14
|
|
|
@@ -71,20 +69,20 @@ addDebugLog("listLibrary", "", "+");
|
|
|
71
69
|
if (libraryName === compDef.currentOrgLib && selectedVersion === compDef.buildVersion) {
|
|
72
70
|
|
|
73
71
|
console.log("\nYou've selected the current working library/version.");
|
|
74
|
-
console.log("You can list current components or the last
|
|
72
|
+
console.log("You can list current components or the last store of this library/version.");
|
|
75
73
|
const archAnswers = await inquirer.prompt([
|
|
76
74
|
{
|
|
77
|
-
name: '
|
|
75
|
+
name: 'currentOrStore',
|
|
78
76
|
type: 'rawlist',
|
|
79
|
-
message: 'Select current or
|
|
77
|
+
message: 'Select current or store',
|
|
80
78
|
default: "Current",
|
|
81
|
-
choices: ["Current", "
|
|
79
|
+
choices: ["Current", "Store"]
|
|
82
80
|
},
|
|
83
81
|
]);
|
|
84
82
|
|
|
85
|
-
const
|
|
83
|
+
const currentOrStore = archAnswers.currentOrStore;
|
|
86
84
|
|
|
87
|
-
if (
|
|
85
|
+
if (currentOrStore === "Current") {
|
|
88
86
|
data = await getComponentsConfigs();
|
|
89
87
|
builtOn = "(no date - current)";
|
|
90
88
|
}
|
|
@@ -7,7 +7,7 @@ import { listLibJSONResponse } from '@pega/constellation-dx-components-build-uti
|
|
|
7
7
|
|
|
8
8
|
import { getListLibraryQuestions, SOURCE_OF_COMPONENT_TYPES } from './helper.js';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
|
|
12
12
|
export const getServerLibraryVersions = async(libraryName) => {
|
|
13
13
|
addDebugLog("getServerLibraryVersions", `libraryName: ${libraryName}`, "");
|
|
@@ -34,9 +34,9 @@ addDebugLog("listLibJSONResponse", "services end", "");
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export default async (options) => {
|
|
37
|
-
|
|
37
|
+
const isLibraryBased = getLibraryBased();
|
|
38
38
|
if (!isLibraryBased) {
|
|
39
|
-
console.log(`Command only supported for ${chalk.bold.green('library
|
|
39
|
+
console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`)
|
|
40
40
|
process.exit();
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -115,7 +115,7 @@ addDebugLog("listPublished", "", "+");
|
|
|
115
115
|
else {
|
|
116
116
|
// No library with that name
|
|
117
117
|
console.log(chalk.redBright(`No local library named: ${libraryName} exists.`));
|
|
118
|
-
console.log(chalk.redBright(`You need to
|
|
118
|
+
console.log(chalk.redBright(`You need to publish library: ${libraryName} first.`));
|
|
119
119
|
addDebugLog("listPublished", "END", "-");
|
|
120
120
|
process.exit(1);
|
|
121
121
|
|
|
@@ -156,7 +156,7 @@ addDebugLog("listPublished", "END", "-");
|
|
|
156
156
|
else {
|
|
157
157
|
// No library with that name
|
|
158
158
|
console.log(chalk.redBright(`No server library named: ${libraryName} exists.`));
|
|
159
|
-
console.log(chalk.redBright(`You need to
|
|
159
|
+
console.log(chalk.redBright(`You need to publish library: ${libraryName} first.`));
|
|
160
160
|
addDebugLog("listPublished", "END", "-");
|
|
161
161
|
process.exit(1);
|
|
162
162
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
|
|
3
|
+
import { addDebugLog, getConfigDefaults } from '../../util.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const getComponentKeyQuestion = async(localComponents, copyMoveLC, paramComponentKey = null) => {
|
|
7
|
+
const orAll = localComponents.length > 1 ? "or ALL" : "";
|
|
8
|
+
|
|
9
|
+
return [
|
|
10
|
+
|
|
11
|
+
{
|
|
12
|
+
name: 'componentKey',
|
|
13
|
+
type: 'rawlist',
|
|
14
|
+
pageSize: 15,
|
|
15
|
+
message: `Select component to ${copyMoveLC} ${orAll}`,
|
|
16
|
+
choices: localComponents,
|
|
17
|
+
when: () => !paramComponentKey
|
|
18
|
+
}
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export const getLibraryQuestions = async (archLibs) => {
|
|
25
|
+
addDebugLog("getLibraryQuestions", "", "");
|
|
26
|
+
const configDef = getConfigDefaults();
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
name: 'libraryName',
|
|
32
|
+
type: 'rawlist',
|
|
33
|
+
message: 'Select library to move to',
|
|
34
|
+
choices: archLibs
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const getLibraryVersionQuestion = async (libraryName, libVersions) => {
|
|
40
|
+
addDebugLog("getLibraryVersionQuestion", `libraryName: ${libraryName}`, "");
|
|
41
|
+
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
name: 'version',
|
|
45
|
+
type: 'rawlist',
|
|
46
|
+
message: `Select ${chalk.green.bold(`${libraryName}`)} library version to move to`,
|
|
47
|
+
choices: libVersions
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'copyShared',
|
|
51
|
+
type: 'confirm',
|
|
52
|
+
message: `Copy ${chalk.yellow.bold("/shared")} directory (same named files will be overridden) ?`,
|
|
53
|
+
default: true
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
};
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
5
|
+
import inquirer from 'inquirer';
|
|
6
|
+
import ncp from 'ncp';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
checkPathAccess,
|
|
11
|
+
showVersion,
|
|
12
|
+
getComponentsObj,
|
|
13
|
+
getDirectoryFiles,
|
|
14
|
+
addDebugLog,
|
|
15
|
+
checkLibraryAndArchives,
|
|
16
|
+
getConfigDefaults,
|
|
17
|
+
getLibraryBased,
|
|
18
|
+
unZipFromArchive,
|
|
19
|
+
zipVersionAndArchive,
|
|
20
|
+
getLibraryArchivesVersions,
|
|
21
|
+
getLibraryArchiveDirectories
|
|
22
|
+
} from '../../util.js';
|
|
23
|
+
import { TASKS_CONFIG_JSON_FILENAME, COMPONENTS_DIRECTORY_PATH, COMPONENTS_PATH, ARCHIVES_PATH, TEMP_PATH } from '../../constants.js';
|
|
24
|
+
import { getComponentKeyQuestion, getLibraryQuestions, getLibraryVersionQuestion } from './helper.js';
|
|
25
|
+
|
|
26
|
+
export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
|
|
27
|
+
const currentDirectory = process.cwd();
|
|
28
|
+
const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
import {
|
|
32
|
+
convertIntoPascalCase,
|
|
33
|
+
getComponentDirectoryPath
|
|
34
|
+
} from '../../util.js';
|
|
35
|
+
import { or } from 'ajv/dist/compile/codegen/index.js';
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const copy = promisify(ncp);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export const updateConfig = async (
|
|
42
|
+
{
|
|
43
|
+
oldComponentKey,
|
|
44
|
+
newComponentKey,
|
|
45
|
+
library,
|
|
46
|
+
version,
|
|
47
|
+
targetDirectory,
|
|
48
|
+
},
|
|
49
|
+
options,
|
|
50
|
+
onlyCompanion = false
|
|
51
|
+
) => {
|
|
52
|
+
|
|
53
|
+
addDebugLog("updateConfig", `oldComponentKey: ${oldComponentKey}, newComponentKey: ${newComponentKey}`, "");
|
|
54
|
+
|
|
55
|
+
let configData = fs.readFileSync(join(targetDirectory, "/config.json"), { encoding: 'utf8' });
|
|
56
|
+
configData = configData && JSON.parse(configData);
|
|
57
|
+
|
|
58
|
+
configData.name = newComponentKey;
|
|
59
|
+
if (configData.componentKey) configData.componentKey = newComponentKey;
|
|
60
|
+
configData.library = library;
|
|
61
|
+
configData.version = version;
|
|
62
|
+
|
|
63
|
+
// stringify "4", makes the json string look like JSON in the file, formated instead of a single line
|
|
64
|
+
fs.writeFileSync(join(targetDirectory, "/config.json"), JSON.stringify(configData, null, 4), { encoding: 'utf8' });
|
|
65
|
+
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const updateFile = async (
|
|
69
|
+
fileName,
|
|
70
|
+
oldComponentKeyPC,
|
|
71
|
+
newComponentKeyPC,
|
|
72
|
+
targetDirectory,
|
|
73
|
+
) => {
|
|
74
|
+
|
|
75
|
+
addDebugLog("updateFile", `fileName: ${fileName}, oldComponentKeyPC: ${oldComponentKeyPC}, newComponentKeyPC: ${newComponentKeyPC}, targetDirectory: ${targetDirectory}`, "");
|
|
76
|
+
|
|
77
|
+
let fileData = fs.readFileSync(join(targetDirectory, "/", fileName), { encoding: 'utf8' });
|
|
78
|
+
|
|
79
|
+
if (fileData.indexOf(oldComponentKeyPC) >= 0) {
|
|
80
|
+
fileData = fileData.replaceAll(oldComponentKeyPC, newComponentKeyPC);
|
|
81
|
+
|
|
82
|
+
fs.writeFileSync(join(targetDirectory, "/", fileName), fileData, { encoding: 'utf8' });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
// rename the component
|
|
89
|
+
export const renameComponent = async (
|
|
90
|
+
componentKey,
|
|
91
|
+
library,
|
|
92
|
+
version,
|
|
93
|
+
copyMove,
|
|
94
|
+
options
|
|
95
|
+
) => {
|
|
96
|
+
|
|
97
|
+
addDebugLog("renameComponent", `library: ${library}, componentKey: ${componentKey}`, "");
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
const componentName = componentKey.split("_")[2];
|
|
101
|
+
|
|
102
|
+
const configDef = getConfigDefaults();
|
|
103
|
+
|
|
104
|
+
const newComponentKey = `${library}_${componentName}`;
|
|
105
|
+
|
|
106
|
+
const oldComponentKey = componentKey;
|
|
107
|
+
const newComponentKeyPC = convertIntoPascalCase(newComponentKey);
|
|
108
|
+
const oldComponentKeyPC = convertIntoPascalCase(oldComponentKey);
|
|
109
|
+
|
|
110
|
+
const currentDirectory = await getComponentDirectoryPath(componentKey);
|
|
111
|
+
const targetDirectory = await getComponentDirectoryPath(newComponentKey);
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if (copyMove === "Move") {
|
|
116
|
+
// custom component
|
|
117
|
+
try {
|
|
118
|
+
fs.renameSync(currentDirectory, targetDirectory);
|
|
119
|
+
} catch(err) {
|
|
120
|
+
console.log(err)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// copy
|
|
125
|
+
// custom component
|
|
126
|
+
try {
|
|
127
|
+
fs.cpSync(currentDirectory, targetDirectory, { recursive: true});
|
|
128
|
+
} catch(err) {
|
|
129
|
+
console.log(err)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
const targetFileList = await getDirectoryFiles(targetDirectory);
|
|
137
|
+
|
|
138
|
+
for (var fileIndex in targetFileList) {
|
|
139
|
+
const fileName = targetFileList[fileIndex];
|
|
140
|
+
|
|
141
|
+
if (fileName === "config.json") {
|
|
142
|
+
await updateConfig(
|
|
143
|
+
{
|
|
144
|
+
oldComponentKey,
|
|
145
|
+
newComponentKey,
|
|
146
|
+
componentName,
|
|
147
|
+
library,
|
|
148
|
+
version,
|
|
149
|
+
targetDirectory,
|
|
150
|
+
},
|
|
151
|
+
options
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
await updateFile(
|
|
156
|
+
fileName,
|
|
157
|
+
oldComponentKeyPC,
|
|
158
|
+
newComponentKeyPC,
|
|
159
|
+
targetDirectory );
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
} // for
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
return newComponentKey;
|
|
167
|
+
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
export const moveComp = async(componentKey, copyMove, orgLibName, version, copyShared, localComponents, options) => {
|
|
172
|
+
// put lib/version into temp directory
|
|
173
|
+
const currentDirectory = process.cwd();
|
|
174
|
+
const tempDirectory = join(currentDirectory, TEMP_PATH);
|
|
175
|
+
const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
|
|
176
|
+
const fileName = `${orgLibName}_${version}.zip`;
|
|
177
|
+
const archFileName = join(archiveDirectory, fileName);
|
|
178
|
+
const currentCompPath = join(currentDirectory, "src", "components");
|
|
179
|
+
const tempCompPath = join(tempDirectory, "src", "components");
|
|
180
|
+
|
|
181
|
+
await unZipFromArchive(archFileName);
|
|
182
|
+
|
|
183
|
+
const copiedOrMoved = copyMove === "Copy" ? "Copied" : "Moved";
|
|
184
|
+
|
|
185
|
+
let newComponentKey;
|
|
186
|
+
|
|
187
|
+
if (componentKey === 'ALL') {
|
|
188
|
+
for (let index in localComponents) {
|
|
189
|
+
// skip first ALL
|
|
190
|
+
if (index > 1) {
|
|
191
|
+
const localComponentKey = localComponents[index];
|
|
192
|
+
newComponentKey = await localMoveCopyComp(localComponentKey.value, orgLibName, version, copyMove, currentDirectory, tempDirectory);
|
|
193
|
+
if (newComponentKey) {
|
|
194
|
+
console.log(`${copiedOrMoved} ${chalk.green(`${localComponentKey.value}`)} to ${chalk.green(`${orgLibName}/${version}`)} as ${chalk.green(`${newComponentKey}`)}`);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
console.log(chalk.yellow(`Not ${copiedOrMoved}`));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const currentSharedPath = join(currentCompPath, "shared");
|
|
204
|
+
const targetSharedPatah = join(tempCompPath, "shared");
|
|
205
|
+
|
|
206
|
+
// copy shared
|
|
207
|
+
if (copyShared) {
|
|
208
|
+
fs.cpSync(currentSharedPath, targetSharedPatah, { recursive: true, force: true });
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// rearchive temp directory
|
|
212
|
+
await zipVersionAndArchive(orgLibName, version, tempDirectory);
|
|
213
|
+
|
|
214
|
+
// delete temp directory
|
|
215
|
+
fs.rmSync(tempDirectory, { recursive: true, force: true, maxRetries: 5 });
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
|
|
222
|
+
// if (copyMove === "Move") {
|
|
223
|
+
// await localMoveComp(componentKey, orgLibName, version, currentDirectory, tempDirectory);
|
|
224
|
+
// }
|
|
225
|
+
// else {
|
|
226
|
+
// await localCopyComp(componentKey, orgLibName, version, currentDirectory, tempDirectory);
|
|
227
|
+
// }
|
|
228
|
+
|
|
229
|
+
const newComponentKey = await localMoveCopyComp(componentKey, orgLibName, version, copyMove, currentDirectory, tempDirectory);
|
|
230
|
+
|
|
231
|
+
if (newComponentKey) {
|
|
232
|
+
const currentSharedPath = join(currentCompPath, "shared");
|
|
233
|
+
const targetSharedPatah = join(tempCompPath, "shared");
|
|
234
|
+
|
|
235
|
+
// copy shared
|
|
236
|
+
if (copyShared) {
|
|
237
|
+
fs.cpSync(currentSharedPath, targetSharedPatah, { recursive: true, force: true });
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
console.log(`\n${copiedOrMoved} ${chalk.green(`${componentKey}`)} to ${chalk.green(`${orgLibName}/${version}`)} as ${chalk.green(`${newComponentKey}`)}\n`);
|
|
242
|
+
|
|
243
|
+
// rearchive temp directory
|
|
244
|
+
await zipVersionAndArchive(orgLibName, version, tempDirectory);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
console.log(chalk.yellow(`No components were ${copiedOrMoved}`));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
// delete temp directory
|
|
252
|
+
fs.rmSync(tempDirectory, { recursive: true, force: true, maxRetries: 5 });
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export const localMoveCopyComp = async(componentKey, orgLibName, version, copyMove, currentDirectory, tempDirectory ) => {
|
|
260
|
+
const currentCompPath = join(currentDirectory, "src", "components");
|
|
261
|
+
const tempCompPath = join(tempDirectory, "src", "components");
|
|
262
|
+
|
|
263
|
+
const tempCompName = componentKey.split("_")[2];
|
|
264
|
+
const newTempComponentKey = `${orgLibName}_${tempCompName}`;
|
|
265
|
+
const tempDirComp = join(tempCompPath, `${newTempComponentKey}`);
|
|
266
|
+
|
|
267
|
+
if (fs.existsSync(tempDirComp)) {
|
|
268
|
+
const answers = await inquirer.prompt([
|
|
269
|
+
{
|
|
270
|
+
name: 'confirmOverride',
|
|
271
|
+
type: 'confirm',
|
|
272
|
+
message: `Component ${chalk.yellow(`${tempCompName}`)} currently exists in ${chalk.yellow(`${orgLibName}/${version}`)}, override?`,
|
|
273
|
+
default: false
|
|
274
|
+
}
|
|
275
|
+
]);
|
|
276
|
+
if (!answers.confirmOverride) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
// rename the component
|
|
283
|
+
const newComponentKey = await renameComponent(componentKey, orgLibName, version, copyMove);
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
const currentComponentsPath = join(currentCompPath, `${newComponentKey}`);
|
|
289
|
+
const tempDirectoryComponents = join(tempCompPath, `${newComponentKey}`);
|
|
290
|
+
|
|
291
|
+
// copy component into temp directory
|
|
292
|
+
fs.cpSync(currentComponentsPath, tempDirectoryComponents, { recursive: true, force: true });
|
|
293
|
+
|
|
294
|
+
// remove from components
|
|
295
|
+
fs.rmSync(currentComponentsPath, { recursive: true, force: true, maxRetries: 2 });
|
|
296
|
+
|
|
297
|
+
return newComponentKey;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
export default async options => {
|
|
303
|
+
await showVersion();
|
|
304
|
+
await checkLibraryAndArchives();
|
|
305
|
+
|
|
306
|
+
addDebugLog("move", "", "+");
|
|
307
|
+
|
|
308
|
+
await checkPathAccess(pegaConfigJsonPath);
|
|
309
|
+
const isLibraryBased = getLibraryBased();
|
|
310
|
+
if (!isLibraryBased) {
|
|
311
|
+
console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`)
|
|
312
|
+
process.exit();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
|
|
316
|
+
data = data && JSON.parse(data);
|
|
317
|
+
|
|
318
|
+
if (!data[COMPONENTS_DIRECTORY_PATH]) {
|
|
319
|
+
console.error(
|
|
320
|
+
`${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
|
|
321
|
+
);
|
|
322
|
+
process.exit(1);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
let copyMove;
|
|
326
|
+
let copyMoveLC;
|
|
327
|
+
let componentKey;
|
|
328
|
+
let orgLibName;
|
|
329
|
+
let version;
|
|
330
|
+
let copyShared;
|
|
331
|
+
|
|
332
|
+
let localComponents = await getComponentsObj();
|
|
333
|
+
|
|
334
|
+
if (!localComponents || localComponents.length === 0 ) {
|
|
335
|
+
console.log(chalk.red.bold("No components to move/copy."));
|
|
336
|
+
process.exit();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (options.params.length >= 8) {
|
|
340
|
+
componentKey = options.params[3];
|
|
341
|
+
copyMove = options.param[4];
|
|
342
|
+
orgLibName = options.params[5];
|
|
343
|
+
version = options.params[6];
|
|
344
|
+
copyShared = options.params[7];
|
|
345
|
+
|
|
346
|
+
await moveComp(
|
|
347
|
+
componentKey,
|
|
348
|
+
copyMove,
|
|
349
|
+
orgLibName,
|
|
350
|
+
version,
|
|
351
|
+
copyShared,
|
|
352
|
+
localComponents,
|
|
353
|
+
options
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
|
|
359
|
+
// VS Code pluggin would send in the component
|
|
360
|
+
let paramComponentKey;
|
|
361
|
+
if (options.params.length == 4) {
|
|
362
|
+
paramComponentKey = options.params[3];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const configDef = getConfigDefaults();
|
|
366
|
+
console.log(`Current library: ${chalk.green(`${configDef.displayLibVersion}`)}`);
|
|
367
|
+
|
|
368
|
+
// test to see if currnet library has more than one version
|
|
369
|
+
// if no available versions can not move/copy to it, so send in current lib
|
|
370
|
+
// as library to be removed from the list
|
|
371
|
+
let removeOrgLib = "";
|
|
372
|
+
let libVersions;
|
|
373
|
+
try {
|
|
374
|
+
libVersions = await getLibraryArchivesVersions(configDef.currentOrgLib, configDef.buildVersion);
|
|
375
|
+
}
|
|
376
|
+
catch (ex) {}
|
|
377
|
+
if (!libVersions || libVersions.length === 0) {
|
|
378
|
+
removeOrgLib = configDef.currentOrgLib;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const archLibs = await getLibraryArchiveDirectories(removeOrgLib);
|
|
382
|
+
|
|
383
|
+
if (!archLibs || archLibs.length === 0) {
|
|
384
|
+
console.log(chalk.red.bold("No available libraries to move/copy to."));
|
|
385
|
+
process.exit();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const copyMoveQuestion = [
|
|
389
|
+
{
|
|
390
|
+
name: 'copyMove',
|
|
391
|
+
type: 'rawlist',
|
|
392
|
+
message: "Copy or Move",
|
|
393
|
+
choices: ["Copy", "Move"],
|
|
394
|
+
default: "Copy"
|
|
395
|
+
}
|
|
396
|
+
];
|
|
397
|
+
|
|
398
|
+
const copyMoveAnswer = await inquirer.prompt(copyMoveQuestion);
|
|
399
|
+
({copyMove} = copyMoveAnswer);
|
|
400
|
+
copyMoveLC = copyMove.toLowerCase();
|
|
401
|
+
|
|
402
|
+
if (localComponents && localComponents.length > 1) {
|
|
403
|
+
localComponents.unshift({name: 'ALL', value: 'ALL'});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const keyQuestions = await getComponentKeyQuestion(localComponents, copyMoveLC, paramComponentKey);
|
|
407
|
+
|
|
408
|
+
const answers = await inquirer.prompt(keyQuestions);
|
|
409
|
+
({ componentKey = paramComponentKey} = answers);
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
const libQuestions = await getLibraryQuestions(archLibs);
|
|
414
|
+
const libAnswers = await inquirer.prompt(libQuestions);
|
|
415
|
+
orgLibName = libAnswers.libraryName;
|
|
416
|
+
const buildVersion = configDef.currentOrgLib === orgLibName ? configDef.buildVersion : "";
|
|
417
|
+
|
|
418
|
+
try {
|
|
419
|
+
libVersions = await getLibraryArchivesVersions(orgLibName, buildVersion);
|
|
420
|
+
}
|
|
421
|
+
catch (ex) {}
|
|
422
|
+
|
|
423
|
+
const versionQuestions = await getLibraryVersionQuestion(orgLibName, libVersions);
|
|
424
|
+
const versionAnswers = await inquirer.prompt(versionQuestions);
|
|
425
|
+
({version, copyShared} = versionAnswers);
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
await moveComp(
|
|
429
|
+
componentKey,
|
|
430
|
+
copyMove,
|
|
431
|
+
orgLibName,
|
|
432
|
+
version,
|
|
433
|
+
copyShared,
|
|
434
|
+
localComponents,
|
|
435
|
+
options
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
addDebugLog("rename", "END", "-");
|
|
440
|
+
|
|
441
|
+
};
|