@contentstack/cli-cm-import 1.28.1 → 2.0.0-beta
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/README.md +5 -7
- package/lib/commands/cm/stacks/import.d.ts +2 -0
- package/lib/commands/cm/stacks/import.js +46 -11
- package/lib/config/index.js +0 -1
- package/lib/import/module-importer.js +6 -20
- package/lib/import/modules/assets.d.ts +6 -0
- package/lib/import/modules/assets.js +102 -25
- package/lib/import/modules/base-class.d.ts +17 -0
- package/lib/import/modules/base-class.js +45 -0
- package/lib/import/modules/content-types.d.ts +7 -10
- package/lib/import/modules/content-types.js +132 -68
- package/lib/import/modules/custom-roles.d.ts +6 -2
- package/lib/import/modules/custom-roles.js +80 -69
- package/lib/import/modules/entries.d.ts +7 -0
- package/lib/import/modules/entries.js +278 -163
- package/lib/import/modules/environments.d.ts +3 -0
- package/lib/import/modules/environments.js +69 -38
- package/lib/import/modules/extensions.d.ts +3 -0
- package/lib/import/modules/extensions.js +99 -64
- package/lib/import/modules/global-fields.d.ts +8 -1
- package/lib/import/modules/global-fields.js +123 -63
- package/lib/import/modules/index.d.ts +1 -0
- package/lib/import/modules/index.js +1 -0
- package/lib/import/modules/labels.d.ts +3 -0
- package/lib/import/modules/labels.js +104 -54
- package/lib/import/modules/locales.d.ts +15 -4
- package/lib/import/modules/locales.js +194 -94
- package/lib/import/modules/marketplace-apps.d.ts +6 -3
- package/lib/import/modules/marketplace-apps.js +177 -102
- package/lib/import/modules/personalize.d.ts +11 -4
- package/lib/import/modules/personalize.js +138 -47
- package/lib/import/modules/stack.d.ts +6 -0
- package/lib/import/modules/stack.js +71 -27
- package/lib/import/modules/taxonomies.d.ts +4 -2
- package/lib/import/modules/taxonomies.js +60 -46
- package/lib/import/modules/variant-entries.d.ts +7 -4
- package/lib/import/modules/variant-entries.js +76 -35
- package/lib/import/modules/webhooks.d.ts +3 -0
- package/lib/import/modules/webhooks.js +71 -40
- package/lib/import/modules/workflows.d.ts +3 -0
- package/lib/import/modules/workflows.js +98 -48
- package/lib/types/default-config.d.ts +0 -1
- package/lib/types/import-config.d.ts +0 -1
- package/lib/types/index.d.ts +1 -12
- package/lib/utils/backup-handler.js +0 -1
- package/lib/utils/constants.d.ts +243 -0
- package/lib/utils/constants.js +264 -0
- package/lib/utils/import-config-handler.js +2 -0
- package/lib/utils/import-path-resolver.js +3 -13
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +6 -2
- package/lib/utils/marketplace-app-helper.js +3 -8
- package/lib/utils/progress-strategy-registry.d.ts +7 -0
- package/lib/utils/progress-strategy-registry.js +72 -0
- package/lib/utils/setup-branch.js +1 -1
- package/oclif.manifest.json +2 -2
- package/package.json +2 -2
- package/lib/import/modules-js/assets.d.ts +0 -33
- package/lib/import/modules-js/assets.js +0 -428
- package/lib/import/modules-js/content-types.d.ts +0 -34
- package/lib/import/modules-js/content-types.js +0 -204
- package/lib/import/modules-js/custom-roles.d.ts +0 -15
- package/lib/import/modules-js/custom-roles.js +0 -143
- package/lib/import/modules-js/entries.d.ts +0 -54
- package/lib/import/modules-js/entries.js +0 -1280
- package/lib/import/modules-js/environments.d.ts +0 -13
- package/lib/import/modules-js/environments.js +0 -85
- package/lib/import/modules-js/extensions.d.ts +0 -18
- package/lib/import/modules-js/extensions.js +0 -86
- package/lib/import/modules-js/global-fields.d.ts +0 -13
- package/lib/import/modules-js/global-fields.js +0 -106
- package/lib/import/modules-js/index.d.ts +0 -1
- package/lib/import/modules-js/index.js +0 -33
- package/lib/import/modules-js/labels.d.ts +0 -20
- package/lib/import/modules-js/labels.js +0 -148
- package/lib/import/modules-js/locales.d.ts +0 -24
- package/lib/import/modules-js/locales.js +0 -196
- package/lib/import/modules-js/marketplace-apps.d.ts +0 -63
- package/lib/import/modules-js/marketplace-apps.js +0 -429
- package/lib/import/modules-js/webhooks.d.ts +0 -17
- package/lib/import/modules-js/webhooks.js +0 -85
- package/lib/import/modules-js/workflows.d.ts +0 -19
- package/lib/import/modules-js/workflows.js +0 -170
- package/lib/utils/log.d.ts +0 -12
- package/lib/utils/log.js +0 -31
|
@@ -25,4 +25,7 @@ export default class ImportEnvironments extends BaseClass {
|
|
|
25
25
|
*/
|
|
26
26
|
serializeEnvironments(apiOptions: ApiOptions): ApiOptions;
|
|
27
27
|
getEnvDetails(envName: string): Promise<any>;
|
|
28
|
+
private analyzeEnvironments;
|
|
29
|
+
private prepareEnvironmentMapper;
|
|
30
|
+
private processImportResults;
|
|
28
31
|
}
|
|
@@ -10,7 +10,8 @@ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
|
10
10
|
class ImportEnvironments extends base_class_1.default {
|
|
11
11
|
constructor({ importConfig, stackAPIClient }) {
|
|
12
12
|
super({ importConfig, stackAPIClient });
|
|
13
|
-
this.importConfig.context.module =
|
|
13
|
+
this.importConfig.context.module = utils_1.MODULE_CONTEXTS.ENVIRONMENTS;
|
|
14
|
+
this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.ENVIRONMENTS];
|
|
14
15
|
this.environmentsConfig = importConfig.modules.environments;
|
|
15
16
|
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'environments');
|
|
16
17
|
this.environmentsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.environmentsConfig.dirName);
|
|
@@ -26,44 +27,25 @@ class ImportEnvironments extends base_class_1.default {
|
|
|
26
27
|
* @returns {Promise<void>} Promise<void>
|
|
27
28
|
*/
|
|
28
29
|
async start() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
await utils_1.fsUtil.makeDirectory(this.mapperDirPath);
|
|
44
|
-
cli_utilities_1.log.debug('Loading existing environment UID mappings', this.importConfig.context);
|
|
45
|
-
this.envUidMapper = utils_1.fileHelper.fileExistsSync(this.envUidMapperPath)
|
|
46
|
-
? utils_1.fsUtil.readFile((0, node_path_1.join)(this.envUidMapperPath), true)
|
|
47
|
-
: {};
|
|
48
|
-
if (((_a = Object.keys(this.envUidMapper)) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
49
|
-
const envUidCount = Object.keys(this.envUidMapper || {}).length;
|
|
50
|
-
cli_utilities_1.log.debug(`Loaded existing environment UID data: ${envUidCount} items`, this.importConfig.context);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
cli_utilities_1.log.debug('No existing environment UID mappings found', this.importConfig.context);
|
|
54
|
-
}
|
|
55
|
-
cli_utilities_1.log.debug('Starting environment import process', this.importConfig.context);
|
|
56
|
-
await this.importEnvironments();
|
|
57
|
-
cli_utilities_1.log.debug('Processing environment import results', this.importConfig.context);
|
|
58
|
-
if ((_b = this.envSuccess) === null || _b === void 0 ? void 0 : _b.length) {
|
|
59
|
-
utils_1.fsUtil.writeFile(this.envSuccessPath, this.envSuccess);
|
|
60
|
-
cli_utilities_1.log.debug(`Written ${this.envSuccess.length} successful environments to file`, this.importConfig.context);
|
|
30
|
+
try {
|
|
31
|
+
cli_utilities_1.log.debug('Starting environments import process...', this.importConfig.context);
|
|
32
|
+
const [environmentsCount] = await this.analyzeEnvironments();
|
|
33
|
+
if (environmentsCount === 0) {
|
|
34
|
+
cli_utilities_1.log.info('No Environments Found', this.importConfig.context);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const progress = this.createSimpleProgress(this.currentModuleName, environmentsCount);
|
|
38
|
+
await this.prepareEnvironmentMapper();
|
|
39
|
+
progress.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.ENVIRONMENTS_IMPORT].IMPORTING);
|
|
40
|
+
await this.importEnvironments();
|
|
41
|
+
await this.processImportResults();
|
|
42
|
+
this.completeProgress(true);
|
|
43
|
+
cli_utilities_1.log.success('Environments have been imported successfully!', this.importConfig.context);
|
|
61
44
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
cli_utilities_1.
|
|
45
|
+
catch (error) {
|
|
46
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Environments import failed');
|
|
47
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
|
|
65
48
|
}
|
|
66
|
-
cli_utilities_1.log.success('Environments have been imported successfully!', this.importConfig.context);
|
|
67
49
|
}
|
|
68
50
|
async importEnvironments() {
|
|
69
51
|
cli_utilities_1.log.debug('Validating environments data', this.importConfig.context);
|
|
@@ -75,14 +57,16 @@ class ImportEnvironments extends base_class_1.default {
|
|
|
75
57
|
cli_utilities_1.log.debug(`Starting to import ${apiContent.length} environments`, this.importConfig.context);
|
|
76
58
|
cli_utilities_1.log.debug(`Environment names: ${apiContent.map((e) => e.name).join(', ')}`, this.importConfig.context);
|
|
77
59
|
const onSuccess = ({ response, apiData: { uid, name } = { uid: null, name: '' } }) => {
|
|
60
|
+
var _a;
|
|
78
61
|
this.envSuccess.push(response);
|
|
79
62
|
this.envUidMapper[uid] = response.uid;
|
|
63
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `environment: ${name || uid}`, null, utils_1.PROCESS_NAMES.ENVIRONMENTS_IMPORT);
|
|
80
64
|
cli_utilities_1.log.success(`Environment '${name}' imported successfully`, this.importConfig.context);
|
|
81
65
|
cli_utilities_1.log.debug(`Environment UID mapping: ${uid} → ${response.uid}`, this.importConfig.context);
|
|
82
66
|
utils_1.fsUtil.writeFile(this.envUidMapperPath, this.envUidMapper);
|
|
83
67
|
};
|
|
84
68
|
const onReject = async ({ error, apiData }) => {
|
|
85
|
-
var _a;
|
|
69
|
+
var _a, _b, _c;
|
|
86
70
|
const err = (error === null || error === void 0 ? void 0 : error.message) ? JSON.parse(error.message) : error;
|
|
87
71
|
const { name, uid } = apiData;
|
|
88
72
|
cli_utilities_1.log.debug(`Environment '${name}' (${uid}) failed to import`, this.importConfig.context);
|
|
@@ -91,11 +75,14 @@ class ImportEnvironments extends base_class_1.default {
|
|
|
91
75
|
const res = await this.getEnvDetails(name);
|
|
92
76
|
this.envUidMapper[uid] = (res === null || res === void 0 ? void 0 : res.uid) || ' ';
|
|
93
77
|
utils_1.fsUtil.writeFile(this.envUidMapperPath, this.envUidMapper);
|
|
78
|
+
(_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, null, `environment: ${name || uid} (already exists)`, utils_1.PROCESS_NAMES.ENVIRONMENTS_IMPORT);
|
|
94
79
|
cli_utilities_1.log.info(`Environment '${name}' already exists`, this.importConfig.context);
|
|
95
80
|
cli_utilities_1.log.debug(`Added existing environment UID mapping: ${uid} → ${res === null || res === void 0 ? void 0 : res.uid}`, this.importConfig.context);
|
|
96
81
|
}
|
|
97
82
|
else {
|
|
98
83
|
this.envFailed.push(apiData);
|
|
84
|
+
this.envFailed.push(apiData);
|
|
85
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(false, `environment: ${name || uid}`, (error === null || error === void 0 ? void 0 : error.message) || 'Failed to import environment', utils_1.PROCESS_NAMES.ENVIRONMENTS_IMPORT);
|
|
99
86
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { name }), `Environment '${name}' failed to be import`);
|
|
100
87
|
}
|
|
101
88
|
};
|
|
@@ -120,11 +107,14 @@ class ImportEnvironments extends base_class_1.default {
|
|
|
120
107
|
* @returns {ApiOptions} ApiOptions
|
|
121
108
|
*/
|
|
122
109
|
serializeEnvironments(apiOptions) {
|
|
110
|
+
var _a;
|
|
123
111
|
const { apiData: environment } = apiOptions;
|
|
124
112
|
cli_utilities_1.log.debug(`Serializing environment: ${environment.name} (${environment.uid})`, this.importConfig.context);
|
|
125
113
|
if (this.envUidMapper.hasOwnProperty(environment.uid)) {
|
|
126
114
|
cli_utilities_1.log.info(`Environment '${environment.name}' already exists. Skipping it to avoid duplicates!`, this.importConfig.context);
|
|
127
115
|
cli_utilities_1.log.debug(`Skipping environment serialization for: ${environment.uid}`, this.importConfig.context);
|
|
116
|
+
// Still tick progress for skipped environments
|
|
117
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `environment: ${environment.name}`, `environment: ${environment.name} (skipped - already exists)`, utils_1.PROCESS_NAMES.ENVIRONMENTS_IMPORT);
|
|
128
118
|
apiOptions.entity = undefined;
|
|
129
119
|
}
|
|
130
120
|
else {
|
|
@@ -147,5 +137,46 @@ class ImportEnvironments extends base_class_1.default {
|
|
|
147
137
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { envName }));
|
|
148
138
|
});
|
|
149
139
|
}
|
|
140
|
+
async analyzeEnvironments() {
|
|
141
|
+
return this.withLoadingSpinner('ENVIRONMENTS: Analyzing import data...', async () => {
|
|
142
|
+
cli_utilities_1.log.debug('Checking for environments folder existence', this.importConfig.context);
|
|
143
|
+
if (!utils_1.fileHelper.fileExistsSync(this.environmentsFolderPath)) {
|
|
144
|
+
cli_utilities_1.log.info(`No Environments Found - '${this.environmentsFolderPath}'`, this.importConfig.context);
|
|
145
|
+
return [0];
|
|
146
|
+
}
|
|
147
|
+
cli_utilities_1.log.debug(`Found environments folder: ${this.environmentsFolderPath}`, this.importConfig.context);
|
|
148
|
+
this.environments = utils_1.fsUtil.readFile((0, node_path_1.join)(this.environmentsFolderPath, 'environments.json'), true);
|
|
149
|
+
const count = Object.keys(this.environments || {}).length;
|
|
150
|
+
cli_utilities_1.log.debug(`Loaded ${count} environment items from file`, this.importConfig.context);
|
|
151
|
+
return [count];
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async prepareEnvironmentMapper() {
|
|
155
|
+
cli_utilities_1.log.debug('Creating environments mapper directory', this.importConfig.context);
|
|
156
|
+
await utils_1.fsUtil.makeDirectory(this.mapperDirPath);
|
|
157
|
+
cli_utilities_1.log.debug('Loading existing environment UID mappings', this.importConfig.context);
|
|
158
|
+
this.envUidMapper = utils_1.fileHelper.fileExistsSync(this.envUidMapperPath)
|
|
159
|
+
? utils_1.fsUtil.readFile(this.envUidMapperPath, true)
|
|
160
|
+
: {};
|
|
161
|
+
const count = Object.keys(this.envUidMapper || {}).length;
|
|
162
|
+
if (count > 0) {
|
|
163
|
+
cli_utilities_1.log.debug(`Loaded existing environment UID data: ${count} items`, this.importConfig.context);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
cli_utilities_1.log.debug('No existing environment UID mappings found', this.importConfig.context);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async processImportResults() {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
cli_utilities_1.log.debug('Processing environment import results', this.importConfig.context);
|
|
172
|
+
if ((_a = this.envSuccess) === null || _a === void 0 ? void 0 : _a.length) {
|
|
173
|
+
utils_1.fsUtil.writeFile(this.envSuccessPath, this.envSuccess);
|
|
174
|
+
cli_utilities_1.log.debug(`Written ${this.envSuccess.length} successful environments to file`, this.importConfig.context);
|
|
175
|
+
}
|
|
176
|
+
if ((_b = this.envFailed) === null || _b === void 0 ? void 0 : _b.length) {
|
|
177
|
+
utils_1.fsUtil.writeFile(this.envFailsPath, this.envFailed);
|
|
178
|
+
cli_utilities_1.log.debug(`Written ${this.envFailed.length} failed environments to file`, this.importConfig.context);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
150
181
|
}
|
|
151
182
|
exports.default = ImportEnvironments;
|
|
@@ -11,7 +11,8 @@ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
|
11
11
|
class ImportExtensions extends base_class_1.default {
|
|
12
12
|
constructor({ importConfig, stackAPIClient }) {
|
|
13
13
|
super({ importConfig, stackAPIClient });
|
|
14
|
-
this.importConfig.context.module =
|
|
14
|
+
this.importConfig.context.module = utils_1.MODULE_CONTEXTS.EXTENSIONS;
|
|
15
|
+
this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.EXTENSIONS];
|
|
15
16
|
this.extensionsConfig = importConfig.modules.extensions;
|
|
16
17
|
this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'extensions');
|
|
17
18
|
this.extensionsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.extensionsConfig.dirName);
|
|
@@ -30,67 +31,45 @@ class ImportExtensions extends base_class_1.default {
|
|
|
30
31
|
* @returns {Promise<void>} Promise<void>
|
|
31
32
|
*/
|
|
32
33
|
async start() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.extensions = utils_1.fsUtil.readFile((0, node_path_1.join)(this.extensionsFolderPath, 'extensions.json'), true);
|
|
39
|
-
// Check if extensions file was read successfully
|
|
40
|
-
if (!this.extensions) {
|
|
41
|
-
cli_utilities_1.log.info(`No extensions found in file - '${(0, node_path_1.join)(this.extensionsFolderPath, 'extensions.json')}'`, this.importConfig.context);
|
|
34
|
+
try {
|
|
35
|
+
cli_utilities_1.log.debug('Starting Create process...', this.importConfig.context);
|
|
36
|
+
const [extensionsCount] = await this.analyzeExtensions();
|
|
37
|
+
if (extensionsCount === 0) {
|
|
38
|
+
cli_utilities_1.log.info('No extensions found to import', this.importConfig.context);
|
|
42
39
|
return;
|
|
43
40
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
cli_utilities_1.log.debug('Starting extensions import', this.importConfig.context);
|
|
69
|
-
await this.importExtensions();
|
|
70
|
-
// Update the uid of the extension
|
|
71
|
-
cli_utilities_1.log.debug('Updating extension UIDs', this.importConfig.context);
|
|
72
|
-
this.updateUidExtension();
|
|
73
|
-
// Note: if any extensions present, then update it
|
|
74
|
-
if (this.importConfig.replaceExisting && this.existingExtensions.length > 0) {
|
|
75
|
-
cli_utilities_1.log.debug(`Replacing ${this.existingExtensions.length} existing extensions`, this.importConfig.context);
|
|
76
|
-
await this.replaceExtensions().catch((error) => {
|
|
77
|
-
cli_utilities_1.log.debug('Error replacing extensions', this.importConfig.context);
|
|
78
|
-
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
cli_utilities_1.log.debug('Processing extensions import results', this.importConfig.context);
|
|
82
|
-
if ((_a = this.extSuccess) === null || _a === void 0 ? void 0 : _a.length) {
|
|
83
|
-
utils_1.fsUtil.writeFile(this.extSuccessPath, this.extSuccess);
|
|
84
|
-
cli_utilities_1.log.debug(`Written ${this.extSuccess.length} successful extensions to file`, this.importConfig.context);
|
|
41
|
+
const progress = this.createNestedProgress(this.currentModuleName);
|
|
42
|
+
progress.addProcess(utils_1.PROCESS_NAMES.EXTENSIONS_CREATE, extensionsCount);
|
|
43
|
+
await this.prepareExtensionMapper();
|
|
44
|
+
cli_utilities_1.log.debug('Checking content types in extension scope', this.importConfig.context);
|
|
45
|
+
this.getContentTypesInScope();
|
|
46
|
+
progress
|
|
47
|
+
.startProcess(utils_1.PROCESS_NAMES.EXTENSIONS_CREATE)
|
|
48
|
+
.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.EXTENSIONS_CREATE].CREATING, utils_1.PROCESS_NAMES.EXTENSIONS_CREATE);
|
|
49
|
+
cli_utilities_1.log.debug('Starting Create', this.importConfig.context);
|
|
50
|
+
await this.importExtensions();
|
|
51
|
+
progress.completeProcess(utils_1.PROCESS_NAMES.EXTENSIONS_CREATE, true);
|
|
52
|
+
cli_utilities_1.log.debug('Updating extension UIDs', this.importConfig.context);
|
|
53
|
+
this.updateUidExtension();
|
|
54
|
+
if (this.importConfig.replaceExisting && this.existingExtensions.length > 0) {
|
|
55
|
+
progress.addProcess(utils_1.PROCESS_NAMES.EXTENSIONS_REPLACE_EXISTING, this.existingExtensions.length);
|
|
56
|
+
progress
|
|
57
|
+
.startProcess(utils_1.PROCESS_NAMES.EXTENSIONS_REPLACE_EXISTING)
|
|
58
|
+
.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.EXTENSIONS_REPLACE_EXISTING].REPLACING, utils_1.PROCESS_NAMES.EXTENSIONS_REPLACE_EXISTING);
|
|
59
|
+
await this.replaceExtensions();
|
|
60
|
+
progress.completeProcess(utils_1.PROCESS_NAMES.EXTENSIONS_REPLACE_EXISTING, true);
|
|
61
|
+
}
|
|
62
|
+
await this.processExtensionResults();
|
|
63
|
+
this.completeProgress(true);
|
|
64
|
+
cli_utilities_1.log.success('Extensions have been imported successfully!', this.importConfig.context);
|
|
85
65
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
cli_utilities_1.
|
|
66
|
+
catch (error) {
|
|
67
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Create failed');
|
|
68
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
|
|
89
69
|
}
|
|
90
|
-
cli_utilities_1.log.success('Extensions have been imported successfully!', this.importConfig.context);
|
|
91
70
|
}
|
|
92
71
|
async importExtensions() {
|
|
93
|
-
cli_utilities_1.log.debug('Starting
|
|
72
|
+
cli_utilities_1.log.debug('Starting Create process', this.importConfig.context);
|
|
94
73
|
if (this.extensions === undefined || (0, isEmpty_1.default)(this.extensions)) {
|
|
95
74
|
cli_utilities_1.log.info('No Extensions Found', this.importConfig.context);
|
|
96
75
|
return;
|
|
@@ -98,27 +77,34 @@ class ImportExtensions extends base_class_1.default {
|
|
|
98
77
|
const apiContent = (0, values_1.default)(this.extensions);
|
|
99
78
|
cli_utilities_1.log.debug(`Importing ${apiContent.length} extensions`, this.importConfig.context);
|
|
100
79
|
const onSuccess = ({ response, apiData: { uid, title } = { uid: null, title: '' } }) => {
|
|
80
|
+
var _a;
|
|
101
81
|
this.extSuccess.push(response);
|
|
102
82
|
this.extUidMapper[uid] = response.uid;
|
|
83
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `extension: ${title || uid}`, null, utils_1.PROCESS_NAMES.EXTENSIONS_CREATE);
|
|
103
84
|
cli_utilities_1.log.success(`Extension '${title}' imported successfully`, this.importConfig.context);
|
|
104
85
|
cli_utilities_1.log.debug(`Extension import completed: ${title} (${uid})`, this.importConfig.context);
|
|
105
86
|
utils_1.fsUtil.writeFile(this.extUidMapperPath, this.extUidMapper);
|
|
106
87
|
};
|
|
107
88
|
const onReject = ({ error, apiData }) => {
|
|
108
|
-
var _a;
|
|
109
|
-
const { title } = apiData;
|
|
89
|
+
var _a, _b, _c, _d;
|
|
90
|
+
const { title, uid } = apiData;
|
|
110
91
|
cli_utilities_1.log.debug(`Extension '${title}' import failed`, this.importConfig.context);
|
|
111
92
|
if ((_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.title) {
|
|
112
93
|
if (this.importConfig.replaceExisting) {
|
|
113
94
|
this.existingExtensions.push(apiData);
|
|
95
|
+
(_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, `extension: ${title || uid} (marked for replacement)`, null, utils_1.PROCESS_NAMES.EXTENSIONS_CREATE);
|
|
114
96
|
cli_utilities_1.log.debug(`Extension '${title}' marked for replacement`, this.importConfig.context);
|
|
115
97
|
}
|
|
98
|
+
else {
|
|
99
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(true, `extension: ${title || uid} (already exists)`, null, utils_1.PROCESS_NAMES.EXTENSIONS_CREATE);
|
|
100
|
+
}
|
|
116
101
|
if (!this.importConfig.skipExisting) {
|
|
117
102
|
cli_utilities_1.log.info(`Extension '${title}' already exists`, this.importConfig.context);
|
|
118
103
|
}
|
|
119
104
|
}
|
|
120
105
|
else {
|
|
121
106
|
this.extFailed.push(apiData);
|
|
107
|
+
(_d = this.progressManager) === null || _d === void 0 ? void 0 : _d.tick(false, `extension: ${title || uid}`, (error === null || error === void 0 ? void 0 : error.message) || 'Failed to import extension', utils_1.PROCESS_NAMES.EXTENSIONS_CREATE);
|
|
122
108
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { title }), `Extension '${title}' failed to be import`);
|
|
123
109
|
}
|
|
124
110
|
};
|
|
@@ -134,23 +120,27 @@ class ImportExtensions extends base_class_1.default {
|
|
|
134
120
|
},
|
|
135
121
|
concurrencyLimit: this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1,
|
|
136
122
|
}, undefined, false);
|
|
137
|
-
cli_utilities_1.log.debug('
|
|
123
|
+
cli_utilities_1.log.debug('Create process completed', this.importConfig.context);
|
|
138
124
|
}
|
|
139
125
|
async replaceExtensions() {
|
|
140
126
|
cli_utilities_1.log.debug(`Replacing ${this.existingExtensions.length} existing extensions`, this.importConfig.context);
|
|
141
127
|
const onSuccess = ({ response, apiData: { uid, title } = { uid: null, title: '' } }) => {
|
|
128
|
+
var _a;
|
|
142
129
|
this.extSuccess.push(response);
|
|
143
130
|
this.extUidMapper[uid] = response.uid;
|
|
144
|
-
|
|
145
|
-
cli_utilities_1.log.
|
|
131
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `extension: ${title || uid} (updated)`, null, utils_1.PROCESS_NAMES.EXTENSIONS_REPLACE_EXISTING);
|
|
132
|
+
cli_utilities_1.log.success(`Extension '${title}' updated successfully`, this.importConfig.context);
|
|
133
|
+
cli_utilities_1.log.debug(`Extension update completed: ${title} (${uid})`, this.importConfig.context);
|
|
146
134
|
utils_1.fsUtil.writeFile(this.extUidMapperPath, this.extUidMapper);
|
|
147
135
|
};
|
|
148
136
|
const onReject = ({ error, apiData }) => {
|
|
149
|
-
|
|
137
|
+
var _a;
|
|
138
|
+
const { title, uid } = apiData;
|
|
150
139
|
this.extFailed.push(apiData);
|
|
151
|
-
(
|
|
140
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, `extension: ${title || uid}`, (error === null || error === void 0 ? void 0 : error.message) || `Extension '${title}' failed to be updated`, utils_1.PROCESS_NAMES.EXTENSIONS_REPLACE_EXISTING);
|
|
141
|
+
cli_utilities_1.log.debug(`Extension '${title}' update failed`, this.importConfig.context);
|
|
142
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { title }), `Extension '${title}' failed to be updated`);
|
|
152
143
|
};
|
|
153
|
-
cli_utilities_1.log.debug(`Using concurrency limit for replacement: ${this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1}`, this.importConfig.context);
|
|
154
144
|
await this.makeConcurrentCall({
|
|
155
145
|
apiContent: this.existingExtensions,
|
|
156
146
|
processName: 'Replace extensions',
|
|
@@ -256,5 +246,50 @@ class ImportExtensions extends base_class_1.default {
|
|
|
256
246
|
cli_utilities_1.log.debug(`Written ${this.extensionObject.length} pending extensions to file`, this.importConfig.context);
|
|
257
247
|
}
|
|
258
248
|
}
|
|
249
|
+
async analyzeExtensions() {
|
|
250
|
+
return this.withLoadingSpinner('EXTENSIONS: Analyzing import data...', async () => {
|
|
251
|
+
cli_utilities_1.log.debug('Checking for extensions folder existence', this.importConfig.context);
|
|
252
|
+
if (!utils_1.fileHelper.fileExistsSync(this.extensionsFolderPath)) {
|
|
253
|
+
cli_utilities_1.log.info(`No Extensions Found - '${this.extensionsFolderPath}'`, this.importConfig.context);
|
|
254
|
+
return [0];
|
|
255
|
+
}
|
|
256
|
+
cli_utilities_1.log.debug(`Found extensions folder: ${this.extensionsFolderPath}`, this.importConfig.context);
|
|
257
|
+
this.extensions = utils_1.fsUtil.readFile((0, node_path_1.join)(this.extensionsFolderPath, 'extensions.json'), true);
|
|
258
|
+
if (!this.extensions) {
|
|
259
|
+
cli_utilities_1.log.info(`No extensions found in file - '${(0, node_path_1.join)(this.extensionsFolderPath, 'extensions.json')}'`, this.importConfig.context);
|
|
260
|
+
return [0];
|
|
261
|
+
}
|
|
262
|
+
const count = Object.keys(this.extensions || {}).length;
|
|
263
|
+
cli_utilities_1.log.debug(`Loaded ${count} extension items from file`, this.importConfig.context);
|
|
264
|
+
return [count];
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
async prepareExtensionMapper() {
|
|
268
|
+
cli_utilities_1.log.debug('Creating extensions mapper directory', this.importConfig.context);
|
|
269
|
+
await utils_1.fsUtil.makeDirectory(this.mapperDirPath);
|
|
270
|
+
cli_utilities_1.log.debug('Loading existing extensions UID data', this.importConfig.context);
|
|
271
|
+
this.extUidMapper = utils_1.fileHelper.fileExistsSync(this.extUidMapperPath)
|
|
272
|
+
? utils_1.fsUtil.readFile(this.extUidMapperPath, true) || {}
|
|
273
|
+
: {};
|
|
274
|
+
const count = Object.keys(this.extUidMapper || {}).length;
|
|
275
|
+
if (count > 0) {
|
|
276
|
+
cli_utilities_1.log.debug(`Loaded existing extensions UID data: ${count} items`, this.importConfig.context);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
cli_utilities_1.log.debug('No existing extensions UID data found', this.importConfig.context);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async processExtensionResults() {
|
|
283
|
+
var _a, _b;
|
|
284
|
+
cli_utilities_1.log.debug('Processing Create results', this.importConfig.context);
|
|
285
|
+
if ((_a = this.extSuccess) === null || _a === void 0 ? void 0 : _a.length) {
|
|
286
|
+
utils_1.fsUtil.writeFile(this.extSuccessPath, this.extSuccess);
|
|
287
|
+
cli_utilities_1.log.debug(`Written ${this.extSuccess.length} successful extensions to file`, this.importConfig.context);
|
|
288
|
+
}
|
|
289
|
+
if ((_b = this.extFailed) === null || _b === void 0 ? void 0 : _b.length) {
|
|
290
|
+
utils_1.fsUtil.writeFile(this.extFailsPath, this.extFailed);
|
|
291
|
+
cli_utilities_1.log.debug(`Written ${this.extFailed.length} failed extensions to file`, this.importConfig.context);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
259
294
|
}
|
|
260
295
|
exports.default = ImportExtensions;
|
|
@@ -25,7 +25,11 @@ export default class ImportGlobalFields extends BaseClass {
|
|
|
25
25
|
private existingGFs;
|
|
26
26
|
private gFsConfig;
|
|
27
27
|
constructor({ importConfig, stackAPIClient }: ModuleClassParams);
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* @method start
|
|
30
|
+
* @returns {Promise<void>} Promise<void>
|
|
31
|
+
*/
|
|
32
|
+
start(): Promise<void>;
|
|
29
33
|
seedGFs(): Promise<any>;
|
|
30
34
|
/**
|
|
31
35
|
* @method serializeGFs
|
|
@@ -46,4 +50,7 @@ export default class ImportGlobalFields extends BaseClass {
|
|
|
46
50
|
* @returns {ApiOptions} ApiOptions
|
|
47
51
|
*/
|
|
48
52
|
serializeReplaceGFs(apiOptions: ApiOptions): ApiOptions;
|
|
53
|
+
private analyzeGlobalFields;
|
|
54
|
+
private prepareGlobalFieldMapper;
|
|
55
|
+
private processGlobalFieldResults;
|
|
49
56
|
}
|