@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
|
@@ -1,70 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
3
4
|
const cli_variants_1 = require("@contentstack/cli-variants");
|
|
4
5
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
class ImportPersonalize extends base_class_1.default {
|
|
11
|
+
constructor({ importConfig, stackAPIClient }) {
|
|
12
|
+
super({ importConfig, stackAPIClient });
|
|
13
|
+
this.moduleDisplayMapper = {
|
|
14
|
+
events: 'Events',
|
|
15
|
+
attributes: 'Attributes',
|
|
16
|
+
audiences: 'Audiences',
|
|
17
|
+
experiences: 'Experiences',
|
|
18
|
+
};
|
|
7
19
|
this.config = importConfig;
|
|
8
|
-
this.config.context.module =
|
|
20
|
+
this.config.context.module = utils_1.MODULE_CONTEXTS.PERSONALIZE;
|
|
21
|
+
this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.PERSONALIZE];
|
|
9
22
|
this.personalizeConfig = importConfig.modules.personalize;
|
|
10
23
|
}
|
|
11
24
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
25
|
+
* @method start
|
|
26
|
+
* @returns {Promise<void>} Promise<void>
|
|
14
27
|
*/
|
|
15
28
|
async start() {
|
|
16
29
|
try {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
cli_utilities_1.log.debug('Starting personalize import process...', this.config.context);
|
|
31
|
+
const [canImport, modulesCount] = await this.analyzePersonalize();
|
|
32
|
+
if (!canImport) {
|
|
33
|
+
cli_utilities_1.log.info('Personalize import skipped', this.config.context);
|
|
21
34
|
return;
|
|
22
35
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (this.personalizeConfig.importData) {
|
|
33
|
-
cli_utilities_1.log.debug('Personalize data import is enabled', this.config.context);
|
|
34
|
-
const moduleMapper = {
|
|
35
|
-
events: cli_variants_1.Import.Events,
|
|
36
|
-
audiences: cli_variants_1.Import.Audiences,
|
|
37
|
-
attributes: cli_variants_1.Import.Attribute,
|
|
38
|
-
experiences: cli_variants_1.Import.Experiences,
|
|
39
|
-
};
|
|
40
|
-
const order = this.personalizeConfig
|
|
41
|
-
.importOrder;
|
|
42
|
-
cli_utilities_1.log.debug(`Processing ${order.length} personalize modules in order: ${order.join(', ')}`, this.config.context);
|
|
43
|
-
const moduleTypes = Object.keys(moduleMapper || {}).join(', ');
|
|
44
|
-
cli_utilities_1.log.debug(`Available module types: ${moduleTypes}`, this.config.context);
|
|
45
|
-
for (const module of order) {
|
|
46
|
-
cli_utilities_1.log.debug(`Starting import for personalize module: ${module}`, this.config.context);
|
|
47
|
-
const Module = moduleMapper[module];
|
|
48
|
-
if (!Module) {
|
|
49
|
-
cli_utilities_1.log.debug(`Module ${module} not found in moduleMapper`, this.config.context);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
cli_utilities_1.log.debug(`Creating instance of ${module} module`, this.config.context);
|
|
53
|
-
const moduleInstance = new Module(this.config);
|
|
54
|
-
cli_utilities_1.log.debug(`Importing ${module} module`, this.config.context);
|
|
55
|
-
await moduleInstance.import();
|
|
56
|
-
cli_utilities_1.log.success(`Successfully imported personalize module: ${module}`, this.config.context);
|
|
57
|
-
cli_utilities_1.log.debug(`Completed import for personalize module: ${module}`, this.config.context);
|
|
58
|
-
}
|
|
59
|
-
cli_utilities_1.log.debug('All personalize modules imported successfully', this.config.context);
|
|
36
|
+
const progress = this.createNestedProgress(this.currentModuleName);
|
|
37
|
+
this.addProjectProcess(progress);
|
|
38
|
+
this.addModuleProcesses(progress, modulesCount);
|
|
39
|
+
// Step 1: Import personalize project
|
|
40
|
+
await this.importProjects(progress);
|
|
41
|
+
// Step 2: Import personalize data modules (if enabled)
|
|
42
|
+
if (this.personalizeConfig.importData && modulesCount > 0) {
|
|
43
|
+
cli_utilities_1.log.debug('Processing personalize modules...', this.config.context);
|
|
44
|
+
await this.importModules(progress);
|
|
60
45
|
}
|
|
61
46
|
else {
|
|
62
|
-
cli_utilities_1.log.debug('
|
|
47
|
+
cli_utilities_1.log.debug('No personalize modules configured for processing', this.config.context);
|
|
63
48
|
}
|
|
49
|
+
this.completeProgress(true);
|
|
64
50
|
cli_utilities_1.log.success('Personalize import completed successfully', this.config.context);
|
|
65
51
|
}
|
|
66
52
|
catch (error) {
|
|
67
53
|
this.personalizeConfig.importData = false; // Stop personalize import if project creation fails
|
|
54
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Personalize import failed');
|
|
68
55
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
69
56
|
if (!this.personalizeConfig.importData) {
|
|
70
57
|
cli_utilities_1.log.debug('Personalize import data flag set to false due to error', this.config.context);
|
|
@@ -72,5 +59,109 @@ class ImportPersonalize {
|
|
|
72
59
|
}
|
|
73
60
|
}
|
|
74
61
|
}
|
|
62
|
+
addProjectProcess(progress) {
|
|
63
|
+
progress.addProcess(utils_1.PROCESS_NAMES.PERSONALIZE_PROJECTS, 1);
|
|
64
|
+
cli_utilities_1.log.debug(`Added ${utils_1.PROCESS_NAMES.PERSONALIZE_PROJECTS} process to personalize progress`, this.config.context);
|
|
65
|
+
}
|
|
66
|
+
addModuleProcesses(progress, moduleCount) {
|
|
67
|
+
if (moduleCount > 0) {
|
|
68
|
+
const order = this.personalizeConfig
|
|
69
|
+
.importOrder;
|
|
70
|
+
cli_utilities_1.log.debug(`Adding ${order.length} personalize module processes: ${order.join(', ')}`, this.config.context);
|
|
71
|
+
for (const module of order) {
|
|
72
|
+
const processName = this.moduleDisplayMapper[module];
|
|
73
|
+
progress.addProcess(processName, 1);
|
|
74
|
+
cli_utilities_1.log.debug(`Added ${processName} process to personalize progress`, this.config.context);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
cli_utilities_1.log.debug('No personalize modules to add to progress', this.config.context);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async importProjects(progress) {
|
|
82
|
+
progress.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.PERSONALIZE_PROJECTS].IMPORTING);
|
|
83
|
+
cli_utilities_1.log.debug('Starting projects import for personalization...', this.config.context);
|
|
84
|
+
const projectInstance = new cli_variants_1.Import.Project(this.config);
|
|
85
|
+
projectInstance.setParentProgressManager(progress);
|
|
86
|
+
await projectInstance.import();
|
|
87
|
+
progress.completeProcess(utils_1.PROCESS_NAMES.PERSONALIZE_PROJECTS, true);
|
|
88
|
+
}
|
|
89
|
+
async importModules(progress) {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
const moduleMapper = {
|
|
92
|
+
events: cli_variants_1.Import.Events,
|
|
93
|
+
audiences: cli_variants_1.Import.Audiences,
|
|
94
|
+
attributes: cli_variants_1.Import.Attribute,
|
|
95
|
+
experiences: cli_variants_1.Import.Experiences,
|
|
96
|
+
};
|
|
97
|
+
const order = this.personalizeConfig.importOrder;
|
|
98
|
+
cli_utilities_1.log.debug(`Personalize import order: ${order.join(', ')}`, this.config.context);
|
|
99
|
+
for (const module of order) {
|
|
100
|
+
cli_utilities_1.log.debug(`Processing personalize module: ${module}`, this.config.context);
|
|
101
|
+
const processName = this.moduleDisplayMapper[module];
|
|
102
|
+
const ModuleClass = moduleMapper[module];
|
|
103
|
+
if (ModuleClass) {
|
|
104
|
+
progress.startProcess(processName).updateStatus(`Importing ${module}...`, processName);
|
|
105
|
+
cli_utilities_1.log.debug(`Starting import for module: ${module}`, this.config.context);
|
|
106
|
+
if (this.personalizeConfig.importData) {
|
|
107
|
+
try {
|
|
108
|
+
const importer = new ModuleClass(this.config);
|
|
109
|
+
importer.setParentProgressManager(progress);
|
|
110
|
+
await importer.import();
|
|
111
|
+
progress.completeProcess(processName, true);
|
|
112
|
+
cli_utilities_1.log.debug(`Completed import for module: ${module}`, this.config.context);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
progress.completeProcess(processName, false);
|
|
116
|
+
cli_utilities_1.log.debug(`Failed to import module: ${module} - ${error === null || error === void 0 ? void 0 : error.message}`, this.config.context);
|
|
117
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.config.context), { module }));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
cli_utilities_1.log.debug(`Skipping ${module} - personalization not enabled`, this.config.context);
|
|
122
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `${module} skipped (no project)`, null, processName);
|
|
123
|
+
progress.completeProcess(processName, true);
|
|
124
|
+
cli_utilities_1.log.info(`Skipped ${module} import - no personalize project found`, this.config.context);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
cli_utilities_1.log.debug(`Module not implemented: ${module}`, this.config.context);
|
|
129
|
+
progress.startProcess(processName).updateStatus(`Module not implemented: ${module}`, processName);
|
|
130
|
+
(_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(false, `module: ${module}`, 'Module not implemented', processName);
|
|
131
|
+
progress.completeProcess(processName, false);
|
|
132
|
+
cli_utilities_1.log.info(`Module not implemented: ${module}`, this.config.context);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
cli_utilities_1.log.debug('All personalize modules processed', this.config.context);
|
|
136
|
+
}
|
|
137
|
+
async analyzePersonalize() {
|
|
138
|
+
return this.withLoadingSpinner('PERSONALIZE: Analyzing import configuration...', async () => {
|
|
139
|
+
var _a;
|
|
140
|
+
if (!this.personalizeConfig.baseURL[this.config.region.name]) {
|
|
141
|
+
cli_utilities_1.log.debug(`No baseURL found for region: ${this.config.region.name}`, this.config.context);
|
|
142
|
+
cli_utilities_1.log.info('Skipping Personalize project import, personalize url is not set', this.config.context);
|
|
143
|
+
this.personalizeConfig.importData = false;
|
|
144
|
+
return [false, 0];
|
|
145
|
+
}
|
|
146
|
+
const personalize = this.config.modules.personalize;
|
|
147
|
+
const { dirName, fileName } = personalize.projects;
|
|
148
|
+
const projectPath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.data), (0, cli_utilities_1.sanitizePath)(personalize.dirName), (0, cli_utilities_1.sanitizePath)(dirName), (0, cli_utilities_1.sanitizePath)(fileName));
|
|
149
|
+
cli_utilities_1.log.debug(`Checking for project file: ${projectPath}`, this.config.context);
|
|
150
|
+
if (!(0, fs_1.existsSync)(projectPath)) {
|
|
151
|
+
this.config.modules.personalize.importData = false;
|
|
152
|
+
cli_utilities_1.log.warn(`Project file not found: ${projectPath}`, this.config.context);
|
|
153
|
+
this.personalizeConfig.importData = false;
|
|
154
|
+
return [false, 0];
|
|
155
|
+
}
|
|
156
|
+
if (this.config.management_token) {
|
|
157
|
+
cli_utilities_1.log.debug('Management token detected, skipping personalize import', this.config.context);
|
|
158
|
+
cli_utilities_1.log.info('Skipping Personalize project import when using management token', this.config.context);
|
|
159
|
+
return [false, 0];
|
|
160
|
+
}
|
|
161
|
+
const modulesCount = this.personalizeConfig.importData ? ((_a = this.personalizeConfig.importOrder) === null || _a === void 0 ? void 0 : _a.length) || 0 : 0;
|
|
162
|
+
cli_utilities_1.log.debug(`Personalize analysis complete: canImport=true, modulesCount=${modulesCount}`, this.config.context);
|
|
163
|
+
return [true, modulesCount];
|
|
164
|
+
});
|
|
165
|
+
}
|
|
75
166
|
}
|
|
76
167
|
exports.default = ImportPersonalize;
|
|
@@ -6,5 +6,11 @@ export default class ImportStack extends BaseClass {
|
|
|
6
6
|
private stackSettings;
|
|
7
7
|
private envUidMapper;
|
|
8
8
|
constructor({ importConfig, stackAPIClient }: ModuleClassParams);
|
|
9
|
+
/**
|
|
10
|
+
* @method start
|
|
11
|
+
* @returns {Promise<void>} Promise<void>
|
|
12
|
+
*/
|
|
9
13
|
start(): Promise<void>;
|
|
14
|
+
private importStackSettings;
|
|
15
|
+
private analyzeStackSettings;
|
|
10
16
|
}
|
|
@@ -2,49 +2,93 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
|
-
const utils_1 = require("../../utils");
|
|
6
|
-
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
7
5
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
|
+
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
8
|
class ImportStack extends base_class_1.default {
|
|
9
9
|
constructor({ importConfig, stackAPIClient }) {
|
|
10
10
|
super({ importConfig, stackAPIClient });
|
|
11
11
|
this.stackSettings = null;
|
|
12
12
|
this.envUidMapper = {};
|
|
13
|
+
this.importConfig.context.module = utils_1.MODULE_CONTEXTS.STACK;
|
|
14
|
+
this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.STACK];
|
|
13
15
|
this.stackSettingsPath = (0, node_path_1.join)(this.importConfig.backupDir, 'stack', 'settings.json');
|
|
14
16
|
this.envUidMapperPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'environments', 'uid-mapping.json');
|
|
15
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* @method start
|
|
20
|
+
* @returns {Promise<void>} Promise<void>
|
|
21
|
+
*/
|
|
16
22
|
async start() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
try {
|
|
24
|
+
cli_utilities_1.log.debug('Starting stack settings import process...', this.importConfig.context);
|
|
25
|
+
if (this.importConfig.management_token) {
|
|
26
|
+
cli_utilities_1.log.info('Skipping stack settings import: Operation is not supported when using a management token.', this.importConfig.context);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const [canImport] = await this.analyzeStackSettings();
|
|
30
|
+
if (!canImport) {
|
|
31
|
+
cli_utilities_1.log.info('Stack settings import skipped', this.importConfig.context);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const progress = this.createSimpleProgress(this.currentModuleName, 1);
|
|
35
|
+
progress.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.STACK_IMPORT].IMPORTING);
|
|
36
|
+
cli_utilities_1.log.info('Starting stack settings import process', this.importConfig.context);
|
|
37
|
+
await this.importStackSettings();
|
|
38
|
+
this.completeProgress(true);
|
|
39
|
+
cli_utilities_1.log.success('Stack settings imported successfully!', this.importConfig.context);
|
|
31
40
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
catch (error) {
|
|
42
|
+
this.completeProgress(false, 'Stack settings import failed');
|
|
43
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
|
|
35
44
|
}
|
|
45
|
+
}
|
|
46
|
+
async importStackSettings() {
|
|
47
|
+
var _a, _b, _c;
|
|
48
|
+
cli_utilities_1.log.debug('Processing stack settings for import', this.importConfig.context);
|
|
49
|
+
// Update environment UID mapping if live preview is configured
|
|
36
50
|
if (((_a = this.stackSettings) === null || _a === void 0 ? void 0 : _a.live_preview) && ((_b = this.stackSettings) === null || _b === void 0 ? void 0 : _b.live_preview['default-env'])) {
|
|
37
51
|
const oldEnvUid = this.stackSettings.live_preview['default-env'];
|
|
38
52
|
const mappedEnvUid = this.envUidMapper[oldEnvUid];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
|
|
53
|
+
if (mappedEnvUid) {
|
|
54
|
+
this.stackSettings.live_preview['default-env'] = mappedEnvUid;
|
|
55
|
+
cli_utilities_1.log.debug(`Updated live preview environment: ${oldEnvUid} → ${mappedEnvUid}`, this.importConfig.context);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
cli_utilities_1.log.debug(`No mapping found for live preview environment: ${oldEnvUid}`, this.importConfig.context);
|
|
59
|
+
}
|
|
47
60
|
}
|
|
61
|
+
cli_utilities_1.log.debug('Applying stack settings to target stack', this.importConfig.context);
|
|
62
|
+
await this.stack.addSettings(this.stackSettings);
|
|
63
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(true, 'stack settings applied', null, utils_1.PROCESS_NAMES.STACK_IMPORT);
|
|
64
|
+
cli_utilities_1.log.debug('Stack settings applied successfully', this.importConfig.context);
|
|
65
|
+
}
|
|
66
|
+
async analyzeStackSettings() {
|
|
67
|
+
return this.withLoadingSpinner('STACK SETTINGS: Analyzing import data...', async () => {
|
|
68
|
+
cli_utilities_1.log.debug('Checking for stack settings file existence', this.importConfig.context);
|
|
69
|
+
if (!utils_1.fileHelper.fileExistsSync(this.stackSettingsPath)) {
|
|
70
|
+
cli_utilities_1.log.info('No stack setting found!', this.importConfig.context);
|
|
71
|
+
return [false];
|
|
72
|
+
}
|
|
73
|
+
cli_utilities_1.log.debug(`Found stack settings file: ${this.stackSettingsPath}`, this.importConfig.context);
|
|
74
|
+
this.stackSettings = utils_1.fsUtil.readFile(this.stackSettingsPath, true);
|
|
75
|
+
if (!this.stackSettings) {
|
|
76
|
+
cli_utilities_1.log.info('Stack settings file is empty or invalid', this.importConfig.context);
|
|
77
|
+
return [false];
|
|
78
|
+
}
|
|
79
|
+
cli_utilities_1.log.debug('Loading environment UID mappings', this.importConfig.context);
|
|
80
|
+
if (utils_1.fileHelper.fileExistsSync(this.envUidMapperPath)) {
|
|
81
|
+
this.envUidMapper = utils_1.fsUtil.readFile(this.envUidMapperPath, true);
|
|
82
|
+
const envMappingCount = Object.keys(this.envUidMapper || {}).length;
|
|
83
|
+
cli_utilities_1.log.debug(`Loaded ${envMappingCount} environment UID mappings`, this.importConfig.context);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
cli_utilities_1.log.warn('Skipping stack settings import. Please run the environments migration first.', this.importConfig.context);
|
|
87
|
+
return [false];
|
|
88
|
+
}
|
|
89
|
+
cli_utilities_1.log.debug('Stack settings analysis completed successfully', this.importConfig.context);
|
|
90
|
+
return [true];
|
|
91
|
+
});
|
|
48
92
|
}
|
|
49
93
|
}
|
|
50
94
|
exports.default = ImportStack;
|
|
@@ -28,15 +28,17 @@ export default class ImportTaxonomies extends BaseClass {
|
|
|
28
28
|
*/
|
|
29
29
|
importTaxonomies(): Promise<any>;
|
|
30
30
|
/**
|
|
31
|
-
* @method
|
|
31
|
+
* @method serializeTaxonomiesData
|
|
32
32
|
* @param {ApiOptions} apiOptions ApiOptions
|
|
33
33
|
* @returns {ApiOptions} ApiOptions
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
serializeTaxonomiesData(apiOptions: ApiOptions): ApiOptions;
|
|
36
36
|
/**
|
|
37
37
|
* create taxonomies success and fail in (mapper/taxonomies)
|
|
38
38
|
* create terms success and fail in (mapper/taxonomies/terms)
|
|
39
39
|
* @method createSuccessAndFailedFile
|
|
40
40
|
*/
|
|
41
41
|
createSuccessAndFailedFile(): void;
|
|
42
|
+
private analyzeTaxonomies;
|
|
43
|
+
private prepareMapperDirectories;
|
|
42
44
|
}
|
|
@@ -14,7 +14,8 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
14
14
|
this.failedTaxonomies = {};
|
|
15
15
|
this.createdTerms = {};
|
|
16
16
|
this.failedTerms = {};
|
|
17
|
-
this.importConfig.context.module =
|
|
17
|
+
this.importConfig.context.module = utils_1.MODULE_CONTEXTS.TAXONOMIES;
|
|
18
|
+
this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.TAXONOMIES];
|
|
18
19
|
this.taxonomiesConfig = importConfig.modules.taxonomies;
|
|
19
20
|
this.taxonomiesMapperDirPath = (0, node_path_1.join)(importConfig.backupDir, 'mapper', 'taxonomies');
|
|
20
21
|
this.termsMapperDirPath = (0, node_path_1.join)(this.taxonomiesMapperDirPath, 'terms');
|
|
@@ -29,30 +30,26 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
29
30
|
* @returns {Promise<void>} Promise<void>
|
|
30
31
|
*/
|
|
31
32
|
async start() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
try {
|
|
34
|
+
cli_utilities_1.log.debug('Starting taxonomies import process...', this.importConfig.context);
|
|
35
|
+
const [taxonomiesCount] = await this.analyzeTaxonomies();
|
|
36
|
+
if (taxonomiesCount === 0) {
|
|
37
|
+
cli_utilities_1.log.info('No taxonomies found to import', this.importConfig.context);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const progress = this.createSimpleProgress(this.currentModuleName, taxonomiesCount);
|
|
41
|
+
await this.prepareMapperDirectories();
|
|
42
|
+
progress.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.TAXONOMIES_IMPORT].IMPORTING);
|
|
43
|
+
cli_utilities_1.log.debug('Starting taxonomies import', this.importConfig.context);
|
|
44
|
+
await this.importTaxonomies();
|
|
45
|
+
this.createSuccessAndFailedFile();
|
|
46
|
+
this.completeProgress(true);
|
|
47
|
+
cli_utilities_1.log.success('Taxonomies imported successfully!', this.importConfig.context);
|
|
39
48
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
catch (error) {
|
|
50
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Taxonomies import failed');
|
|
51
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
|
|
43
52
|
}
|
|
44
|
-
//Step 2 create taxonomies & terms mapper directory
|
|
45
|
-
cli_utilities_1.log.debug('Creating mapper directories', this.importConfig.context);
|
|
46
|
-
await utils_1.fsUtil.makeDirectory(this.taxonomiesMapperDirPath);
|
|
47
|
-
await utils_1.fsUtil.makeDirectory(this.termsMapperDirPath);
|
|
48
|
-
cli_utilities_1.log.debug('Created taxonomies and terms mapper directories', this.importConfig.context);
|
|
49
|
-
// Step 3 import taxonomies
|
|
50
|
-
cli_utilities_1.log.debug('Starting taxonomies import', this.importConfig.context);
|
|
51
|
-
await this.importTaxonomies();
|
|
52
|
-
//Step 4 create taxonomy & related terms success & failure file
|
|
53
|
-
cli_utilities_1.log.debug('Creating success and failure files', this.importConfig.context);
|
|
54
|
-
this.createSuccessAndFailedFile();
|
|
55
|
-
cli_utilities_1.log.success('Taxonomies imported successfully!', this.importConfig.context);
|
|
56
53
|
}
|
|
57
54
|
/**
|
|
58
55
|
* create taxonomy and enter success & failure related data into taxonomies mapper file
|
|
@@ -69,46 +66,40 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
69
66
|
const apiContent = (0, values_1.default)(this.taxonomies);
|
|
70
67
|
cli_utilities_1.log.debug(`Starting to import ${apiContent.length} taxonomies`, this.importConfig.context);
|
|
71
68
|
const onSuccess = ({ apiData }) => {
|
|
72
|
-
var _a, _b;
|
|
69
|
+
var _a, _b, _c;
|
|
73
70
|
const taxonomyUID = (_a = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _a === void 0 ? void 0 : _a.uid;
|
|
74
71
|
const taxonomyName = (_b = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _b === void 0 ? void 0 : _b.name;
|
|
75
72
|
const termsCount = Object.keys((apiData === null || apiData === void 0 ? void 0 : apiData.terms) || {}).length;
|
|
76
73
|
this.createdTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
|
|
77
74
|
this.createdTerms[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.terms;
|
|
75
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(true, null, `taxonomy: ${taxonomyName || taxonomyUID} (${termsCount} terms)`, utils_1.PROCESS_NAMES.TAXONOMIES_IMPORT);
|
|
78
76
|
cli_utilities_1.log.success(`Taxonomy '${taxonomyUID}' imported successfully!`, this.importConfig.context);
|
|
79
|
-
cli_utilities_1.log.debug(`
|
|
80
|
-
cli_utilities_1.log.debug(`Taxonomy details: ${JSON.stringify({ uid: taxonomyUID, name: taxonomyName, termsCount })}`, this.importConfig.context);
|
|
77
|
+
cli_utilities_1.log.debug(`Taxonomy '${taxonomyName}' imported with ${termsCount} terms successfully!`, this.importConfig.context);
|
|
81
78
|
};
|
|
82
79
|
const onReject = ({ error, apiData }) => {
|
|
83
80
|
var _a, _b, _c, _d;
|
|
84
81
|
const taxonomyUID = (_a = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _a === void 0 ? void 0 : _a.uid;
|
|
85
82
|
const taxonomyName = (_b = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _b === void 0 ? void 0 : _b.name;
|
|
86
|
-
cli_utilities_1.log.debug(`Taxonomy '${taxonomyUID}' failed to import`, this.importConfig.context);
|
|
87
83
|
if ((error === null || error === void 0 ? void 0 : error.status) === 409 && (error === null || error === void 0 ? void 0 : error.statusText) === 'Conflict') {
|
|
88
84
|
cli_utilities_1.log.info(`Taxonomy '${taxonomyUID}' already exists!`, this.importConfig.context);
|
|
89
85
|
cli_utilities_1.log.debug(`Adding existing taxonomy '${taxonomyUID}' to created list`, this.importConfig.context);
|
|
90
86
|
this.createdTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
|
|
91
87
|
this.createdTerms[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.terms;
|
|
88
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(true, null, `taxonomy: ${taxonomyName || taxonomyUID} already exists`, utils_1.PROCESS_NAMES.TAXONOMIES_IMPORT);
|
|
92
89
|
}
|
|
93
90
|
else {
|
|
94
|
-
cli_utilities_1.log.debug(`Adding taxonomy '${taxonomyUID}' to failed list`, this.importConfig.context);
|
|
95
|
-
if ((error === null || error === void 0 ? void 0 : error.errorMessage) || (error === null || error === void 0 ? void 0 : error.message)) {
|
|
96
|
-
const errorMsg = (error === null || error === void 0 ? void 0 : error.errorMessage) || ((_c = error === null || error === void 0 ? void 0 : error.errors) === null || _c === void 0 ? void 0 : _c.taxonomy) || ((_d = error === null || error === void 0 ? void 0 : error.errors) === null || _d === void 0 ? void 0 : _d.term) || (error === null || error === void 0 ? void 0 : error.message);
|
|
97
|
-
cli_utilities_1.log.error(`Taxonomy '${taxonomyUID}' failed to be import! ${errorMsg}`, this.importConfig.context);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { taxonomyUID }), `Taxonomy '${taxonomyUID}' failed to import`);
|
|
101
|
-
}
|
|
102
91
|
this.failedTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
|
|
103
92
|
this.failedTerms[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.terms;
|
|
93
|
+
(_d = this.progressManager) === null || _d === void 0 ? void 0 : _d.tick(false, `taxonomy: ${taxonomyName || taxonomyUID}`, (error === null || error === void 0 ? void 0 : error.message) || 'Failed to import taxonomy', utils_1.PROCESS_NAMES.TAXONOMIES_IMPORT);
|
|
94
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { taxonomyUID }), `Taxonomy '${taxonomyUID}' failed to be imported`);
|
|
104
95
|
}
|
|
105
96
|
};
|
|
106
|
-
cli_utilities_1.log.debug(`Using concurrency limit: ${this.importConfig.
|
|
97
|
+
cli_utilities_1.log.debug(`Using concurrency limit: ${this.importConfig.fetchConcurrency || 2}`, this.importConfig.context);
|
|
107
98
|
await this.makeConcurrentCall({
|
|
108
99
|
apiContent,
|
|
109
100
|
processName: 'import taxonomies',
|
|
110
101
|
apiParams: {
|
|
111
|
-
serializeData: this.
|
|
102
|
+
serializeData: this.serializeTaxonomiesData.bind(this),
|
|
112
103
|
reject: onReject,
|
|
113
104
|
resolve: onSuccess,
|
|
114
105
|
entity: 'import-taxonomy',
|
|
@@ -119,15 +110,16 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
119
110
|
cli_utilities_1.log.debug('Taxonomies import process completed', this.importConfig.context);
|
|
120
111
|
}
|
|
121
112
|
/**
|
|
122
|
-
* @method
|
|
113
|
+
* @method serializeTaxonomiesData
|
|
123
114
|
* @param {ApiOptions} apiOptions ApiOptions
|
|
124
115
|
* @returns {ApiOptions} ApiOptions
|
|
125
116
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
117
|
+
serializeTaxonomiesData(apiOptions) {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
const { apiData: taxonomyData } = apiOptions;
|
|
120
|
+
cli_utilities_1.log.debug(`Serializing taxonomy: ${(_a = taxonomyData.taxonomy) === null || _a === void 0 ? void 0 : _a.name} (${(_b = taxonomyData.taxonomy) === null || _b === void 0 ? void 0 : _b.uid})`, this.importConfig.context);
|
|
121
|
+
const taxonomyUID = taxonomyData === null || taxonomyData === void 0 ? void 0 : taxonomyData.uid;
|
|
129
122
|
const filePath = (0, node_path_1.join)(this.taxonomiesFolderPath, `${taxonomyUID}.json`);
|
|
130
|
-
cli_utilities_1.log.debug(`Serializing taxonomy: ${taxonomyUID}`, this.importConfig.context);
|
|
131
123
|
cli_utilities_1.log.debug(`Looking for taxonomy file: ${filePath}`, this.importConfig.context);
|
|
132
124
|
if (utils_1.fileHelper.fileExistsSync(filePath)) {
|
|
133
125
|
const taxonomyDetails = utils_1.fsUtil.readFile(filePath, true);
|
|
@@ -150,10 +142,10 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
150
142
|
createSuccessAndFailedFile() {
|
|
151
143
|
var _a, _b, _c, _d;
|
|
152
144
|
cli_utilities_1.log.debug('Creating success and failed files for taxonomies and terms', this.importConfig.context);
|
|
153
|
-
const createdTaxCount = (_a = Object.keys(this.createdTaxonomies)) === null || _a === void 0 ? void 0 : _a.length;
|
|
154
|
-
const failedTaxCount = (_b = Object.keys(this.failedTaxonomies)) === null || _b === void 0 ? void 0 : _b.length;
|
|
155
|
-
const createdTermsCount = (_c = Object.keys(this.createdTerms)) === null || _c === void 0 ? void 0 : _c.length;
|
|
156
|
-
const failedTermsCount = (_d = Object.keys(this.failedTerms)) === null || _d === void 0 ? void 0 : _d.length;
|
|
145
|
+
const createdTaxCount = (_a = Object.keys(this.createdTaxonomies || {})) === null || _a === void 0 ? void 0 : _a.length;
|
|
146
|
+
const failedTaxCount = (_b = Object.keys(this.failedTaxonomies || {})) === null || _b === void 0 ? void 0 : _b.length;
|
|
147
|
+
const createdTermsCount = (_c = Object.keys(this.createdTerms || {})) === null || _c === void 0 ? void 0 : _c.length;
|
|
148
|
+
const failedTermsCount = (_d = Object.keys(this.failedTerms || {})) === null || _d === void 0 ? void 0 : _d.length;
|
|
157
149
|
cli_utilities_1.log.debug(`Summary - Created taxonomies: ${createdTaxCount}, Failed taxonomies: ${failedTaxCount}`, this.importConfig.context);
|
|
158
150
|
cli_utilities_1.log.debug(`Summary - Created terms: ${createdTermsCount}, Failed terms: ${failedTermsCount}`, this.importConfig.context);
|
|
159
151
|
if (this.createdTaxonomies !== undefined && !(0, isEmpty_1.default)(this.createdTaxonomies)) {
|
|
@@ -173,5 +165,27 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
173
165
|
cli_utilities_1.log.debug(`Written failed terms for ${failedTermsCount} taxonomies to file: ${this.termsFailsPath}`, this.importConfig.context);
|
|
174
166
|
}
|
|
175
167
|
}
|
|
168
|
+
async analyzeTaxonomies() {
|
|
169
|
+
return this.withLoadingSpinner('TAXONOMIES: Analyzing import data...', async () => {
|
|
170
|
+
cli_utilities_1.log.debug('Checking for taxonomies folder existence', this.importConfig.context);
|
|
171
|
+
if (utils_1.fileHelper.fileExistsSync(this.taxonomiesFolderPath)) {
|
|
172
|
+
cli_utilities_1.log.debug(`Found taxonomies folder: ${this.taxonomiesFolderPath}`, this.importConfig.context);
|
|
173
|
+
this.taxonomies = utils_1.fsUtil.readFile((0, node_path_1.join)(this.taxonomiesFolderPath, 'taxonomies.json'), true);
|
|
174
|
+
const taxonomyCount = Object.keys(this.taxonomies || {}).length;
|
|
175
|
+
cli_utilities_1.log.debug(`Loaded ${taxonomyCount} taxonomy items from file`, this.importConfig.context);
|
|
176
|
+
return [taxonomyCount];
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
cli_utilities_1.log.info(`No Taxonomies Found! - '${this.taxonomiesFolderPath}'`, this.importConfig.context);
|
|
180
|
+
return [0];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async prepareMapperDirectories() {
|
|
185
|
+
cli_utilities_1.log.debug('Creating mapper directories', this.importConfig.context);
|
|
186
|
+
await utils_1.fsUtil.makeDirectory(this.taxonomiesMapperDirPath);
|
|
187
|
+
await utils_1.fsUtil.makeDirectory(this.termsMapperDirPath);
|
|
188
|
+
cli_utilities_1.log.debug('Created taxonomies and terms mapper directories', this.importConfig.context);
|
|
189
|
+
}
|
|
176
190
|
}
|
|
177
191
|
exports.default = ImportTaxonomies;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { ImportConfig, ModuleClassParams } from '../../types';
|
|
2
|
-
|
|
2
|
+
import BaseClass from './base-class';
|
|
3
|
+
export default class ImportVariantEntries extends BaseClass {
|
|
3
4
|
private config;
|
|
4
5
|
personalize: ImportConfig['modules']['personalize'];
|
|
5
6
|
private projectMapperFilePath;
|
|
6
|
-
constructor({ importConfig }: ModuleClassParams);
|
|
7
|
+
constructor({ importConfig, stackAPIClient }: ModuleClassParams);
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* @method start
|
|
10
|
+
* @returns {Promise<void>} Promise<void>
|
|
10
11
|
*/
|
|
11
12
|
start(): Promise<void>;
|
|
13
|
+
private importVariantEntries;
|
|
14
|
+
private analyzeVariantEntries;
|
|
12
15
|
}
|