@contentstack/cli-cm-import 1.28.1 → 2.0.1-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 +78 -0
- package/lib/utils/setup-branch.js +1 -1
- package/oclif.manifest.json +2 -2
- package/package.json +3 -3
- 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
|
@@ -10,13 +10,14 @@ const tslib_1 = require("tslib");
|
|
|
10
10
|
const path = tslib_1.__importStar(require("path"));
|
|
11
11
|
const lodash_1 = require("lodash");
|
|
12
12
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
13
|
-
const utils_1 = require("../../utils");
|
|
14
13
|
const base_class_1 = tslib_1.__importDefault(require("./base-class"));
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
15
15
|
class ImportLocales extends base_class_1.default {
|
|
16
16
|
constructor({ importConfig, stackAPIClient }) {
|
|
17
17
|
super({ importConfig, stackAPIClient });
|
|
18
18
|
this.config = importConfig;
|
|
19
|
-
this.config.context.module =
|
|
19
|
+
this.config.context.module = utils_1.MODULE_CONTEXTS.LOCALES;
|
|
20
|
+
this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.LOCALES];
|
|
20
21
|
this.localeConfig = importConfig.modules.locales;
|
|
21
22
|
this.masterLanguage = importConfig.masterLocale;
|
|
22
23
|
this.masterLanguageConfig = importConfig.modules.masterLocale;
|
|
@@ -33,116 +34,65 @@ class ImportLocales extends base_class_1.default {
|
|
|
33
34
|
this.langUidMapperPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.data), 'mapper', 'languages', 'uid-mapper.json');
|
|
34
35
|
}
|
|
35
36
|
async start() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
cli_utilities_1.log.debug(`Loaded existing language UID data: ${langUidCount} items`, this.config.context);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
cli_utilities_1.log.debug('No existing language UID mappings found', this.config.context);
|
|
37
|
+
try {
|
|
38
|
+
cli_utilities_1.log.debug('Starting locales import process...', this.config.context);
|
|
39
|
+
const [localesCount] = await this.analyzeLocales();
|
|
40
|
+
if (localesCount === 0) {
|
|
41
|
+
cli_utilities_1.log.info('No languages found to import', this.config.context);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const progress = this.setupLocalesProgress(localesCount);
|
|
45
|
+
this.prepareLocalesMapper();
|
|
46
|
+
await this.processMasterLocale(progress);
|
|
47
|
+
await this.processLocaleCreation(progress);
|
|
48
|
+
await this.processLocaleUpdate(progress);
|
|
49
|
+
cli_utilities_1.log.debug('Writing failed locales to file', this.config.context);
|
|
50
|
+
utils_1.fsUtil.writeFile(this.langFailsPath, this.failedLocales);
|
|
51
|
+
cli_utilities_1.log.debug(`Written ${this.failedLocales.length} failed locales to file`, this.config.context);
|
|
52
|
+
this.completeProgress(true);
|
|
53
|
+
cli_utilities_1.log.success('Languages have been imported successfully!', this.config.context);
|
|
57
54
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
61
|
-
});
|
|
62
|
-
cli_utilities_1.log.debug('Creating locales', this.config.context);
|
|
63
|
-
await this.createLocales().catch((error) => {
|
|
64
|
-
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
65
|
-
Promise.reject('Failed to import locales');
|
|
66
|
-
});
|
|
67
|
-
cli_utilities_1.log.debug('Writing failed locales to file', this.config.context);
|
|
68
|
-
utils_1.fsUtil.writeFile(this.langFailsPath, this.failedLocales);
|
|
69
|
-
cli_utilities_1.log.debug(`Written ${this.failedLocales.length} failed locales to file`, this.config.context);
|
|
70
|
-
cli_utilities_1.log.debug('Updating locales', this.config.context);
|
|
71
|
-
await this.updateLocales().catch((error) => {
|
|
55
|
+
catch (error) {
|
|
56
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Locales import failed');
|
|
72
57
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
73
|
-
|
|
74
|
-
});
|
|
75
|
-
cli_utilities_1.log.success('Languages have been imported successfully!', this.config.context);
|
|
58
|
+
}
|
|
76
59
|
}
|
|
77
60
|
async checkAndUpdateMasterLocale() {
|
|
78
|
-
var _a, _b, _c
|
|
61
|
+
var _a, _b, _c;
|
|
79
62
|
cli_utilities_1.log.debug('Checking and updating master locale', this.config.context);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
.locale(this.masterLanguage['code'])
|
|
87
|
-
.fetch()
|
|
88
|
-
.catch((error) => {
|
|
89
|
-
cli_utilities_1.log.debug('Error fetching master language details', this.config.context);
|
|
90
|
-
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
91
|
-
});
|
|
92
|
-
if (((_d = masterLangDetails === null || masterLangDetails === void 0 ? void 0 : masterLangDetails.name) === null || _d === void 0 ? void 0 : _d.toString().toUpperCase()) !==
|
|
93
|
-
((_e = sourceMasterLangDetails[0]['name']) === null || _e === void 0 ? void 0 : _e.toString().toUpperCase())) {
|
|
94
|
-
cli_utilities_1.log.debug('Master language name differs between source and destination', this.config.context);
|
|
95
|
-
cli_utilities_1.log.debug(`Current master language name: ${masterLangDetails['name']}`, this.config.context);
|
|
96
|
-
cli_utilities_1.log.debug(`Source master language name: ${sourceMasterLangDetails[0]['name']}`, this.config.context);
|
|
97
|
-
cli_utilities_1.cliux.print('WARNING!!! The master language name for the source and destination is different.', {
|
|
98
|
-
color: 'yellow',
|
|
99
|
-
});
|
|
100
|
-
cli_utilities_1.cliux.print(`Old Master language name: ${masterLangDetails['name']}`, { color: 'red' });
|
|
101
|
-
cli_utilities_1.cliux.print(`New Master language name: ${sourceMasterLangDetails[0]['name']}`, { color: 'green' });
|
|
102
|
-
const langUpdateConfirmation = await cli_utilities_1.cliux.inquire({
|
|
103
|
-
type: 'confirm',
|
|
104
|
-
message: 'Are you sure you want to update name of master language?',
|
|
105
|
-
name: 'confirmation',
|
|
106
|
-
});
|
|
107
|
-
if (langUpdateConfirmation) {
|
|
108
|
-
cli_utilities_1.log.debug('User confirmed master language name update', this.config.context);
|
|
109
|
-
let langUid = sourceMasterLangDetails[0] && sourceMasterLangDetails[0]['uid'];
|
|
110
|
-
let sourceMasterLanguage = this.sourceMasterLanguage[langUid];
|
|
111
|
-
if (!sourceMasterLanguage) {
|
|
112
|
-
cli_utilities_1.log.info(`Master language details not found with id ${langUid} to update`, this.config.context);
|
|
113
|
-
}
|
|
114
|
-
cli_utilities_1.log.debug(`Updating master language name: ${sourceMasterLanguage.name}`, this.config.context);
|
|
115
|
-
const langUpdateRequest = this.stackAPIClient.locale(sourceMasterLanguage.code);
|
|
116
|
-
langUpdateRequest.name = sourceMasterLanguage.name;
|
|
117
|
-
await langUpdateRequest.update().catch(function (error) {
|
|
118
|
-
cli_utilities_1.log.debug('Error updating master language name', this.config.context);
|
|
119
|
-
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
120
|
-
});
|
|
121
|
-
cli_utilities_1.log.success('Master Languages name have been updated successfully!', this.config.context);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
cli_utilities_1.log.debug('User declined master language name update', this.config.context);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
cli_utilities_1.log.debug('Master language names match, no update needed', this.config.context);
|
|
129
|
-
}
|
|
63
|
+
const sourceMasterLangDetails = this.getSourceMasterLangDetails();
|
|
64
|
+
if (!sourceMasterLangDetails)
|
|
65
|
+
return;
|
|
66
|
+
if (((_a = this.masterLanguage) === null || _a === void 0 ? void 0 : _a.code) !== (sourceMasterLangDetails === null || sourceMasterLangDetails === void 0 ? void 0 : sourceMasterLangDetails.code)) {
|
|
67
|
+
this.logCodeMismatch(sourceMasterLangDetails.code);
|
|
68
|
+
return;
|
|
130
69
|
}
|
|
131
|
-
|
|
132
|
-
|
|
70
|
+
cli_utilities_1.log.debug(`Master locale code matches: ${this.masterLanguage.code}`, this.config.context);
|
|
71
|
+
const masterLangDetails = await this.fetchTargetMasterLocale();
|
|
72
|
+
if (!masterLangDetails)
|
|
73
|
+
return;
|
|
74
|
+
if (((_b = masterLangDetails === null || masterLangDetails === void 0 ? void 0 : masterLangDetails.name) === null || _b === void 0 ? void 0 : _b.toString().toUpperCase()) === ((_c = sourceMasterLangDetails['name']) === null || _c === void 0 ? void 0 : _c.toString().toUpperCase())) {
|
|
75
|
+
this.tickProgress(true, `${masterLangDetails.name} (no update needed)`);
|
|
76
|
+
cli_utilities_1.log.debug('Master language names match, no update required', this.config.context);
|
|
77
|
+
return;
|
|
133
78
|
}
|
|
79
|
+
await this.handleNameMismatch(sourceMasterLangDetails, masterLangDetails);
|
|
134
80
|
}
|
|
135
81
|
async createLocales() {
|
|
136
82
|
const languagesToCreate = (0, lodash_1.filter)((0, lodash_1.values)(this.languages), (lang) => lang.code !== this.masterLanguage.code);
|
|
137
83
|
cli_utilities_1.log.debug(`Creating ${languagesToCreate.length} locales (excluding master locale)`, this.config.context);
|
|
138
84
|
const onSuccess = ({ response = {}, apiData: { uid, code } = undefined }) => {
|
|
85
|
+
var _a;
|
|
139
86
|
this.langUidMapper[uid] = response.uid;
|
|
140
87
|
this.createdLocales.push((0, lodash_1.pick)(response, [...this.localeConfig.requiredKeys]));
|
|
88
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `locale: ${code}`, null, utils_1.PROCESS_NAMES.LOCALES_CREATE);
|
|
141
89
|
cli_utilities_1.log.info(`Created locale: '${code}'`, this.config.context);
|
|
142
90
|
cli_utilities_1.log.debug(`Locale UID mapping: ${uid} → ${response.uid}`, this.config.context);
|
|
143
91
|
utils_1.fsUtil.writeFile(this.langUidMapperPath, this.langUidMapper);
|
|
144
92
|
};
|
|
145
93
|
const onReject = ({ error, apiData: { uid, code } = undefined }) => {
|
|
94
|
+
var _a;
|
|
95
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, `locale: ${code}`, (error === null || error === void 0 ? void 0 : error.message) || `Language '${code}' failed to import`, utils_1.PROCESS_NAMES.LOCALES_CREATE);
|
|
146
96
|
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 247) {
|
|
147
97
|
cli_utilities_1.log.info((0, utils_1.formatError)(error), this.config.context);
|
|
148
98
|
}
|
|
@@ -167,17 +117,21 @@ class ImportLocales extends base_class_1.default {
|
|
|
167
117
|
async updateLocales() {
|
|
168
118
|
cli_utilities_1.log.debug(`Updating ${(0, lodash_1.values)(this.languages).length} locales`, this.config.context);
|
|
169
119
|
const onSuccess = ({ response = {}, apiData: { uid, code } = undefined }) => {
|
|
120
|
+
var _a;
|
|
170
121
|
cli_utilities_1.log.info(`Updated locale: '${code}'`, this.config.context);
|
|
171
122
|
cli_utilities_1.log.debug(`Locale update completed for: ${code}`, this.config.context);
|
|
123
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `locale: ${code}`, null, utils_1.PROCESS_NAMES.LOCALES_UPDATE);
|
|
172
124
|
utils_1.fsUtil.writeFile(this.langSuccessPath, this.createdLocales);
|
|
173
125
|
};
|
|
174
126
|
const onReject = ({ error, apiData: { uid, code } = undefined }) => {
|
|
127
|
+
var _a;
|
|
128
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, `locale: ${code}`, `Failed to update locale ${code}`, utils_1.PROCESS_NAMES.LOCALES_UPDATE);
|
|
175
129
|
cli_utilities_1.log.error(`Language '${code}' failed to update`, this.config.context);
|
|
176
130
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.config.context), { code }));
|
|
177
131
|
utils_1.fsUtil.writeFile(this.langFailsPath, this.failedLocales);
|
|
178
132
|
};
|
|
179
133
|
return await this.makeConcurrentCall({
|
|
180
|
-
processName: 'Update locales',
|
|
134
|
+
processName: 'Locale Update locales',
|
|
181
135
|
apiContent: (0, lodash_1.values)(this.languages),
|
|
182
136
|
apiParams: {
|
|
183
137
|
reject: onReject.bind(this),
|
|
@@ -188,5 +142,151 @@ class ImportLocales extends base_class_1.default {
|
|
|
188
142
|
concurrencyLimit: this.reqConcurrency,
|
|
189
143
|
});
|
|
190
144
|
}
|
|
145
|
+
async analyzeLocales() {
|
|
146
|
+
return this.withLoadingSpinner('LOCALES: Analyzing import data...', async () => {
|
|
147
|
+
var _a;
|
|
148
|
+
cli_utilities_1.log.debug('Loading locales from file', this.config.context);
|
|
149
|
+
this.languages = utils_1.fsUtil.readFile(path.join(this.langFolderPath, this.localeConfig.fileName));
|
|
150
|
+
if (!this.languages || (0, lodash_1.isEmpty)(this.languages)) {
|
|
151
|
+
cli_utilities_1.log.info('No languages found to import', this.config.context);
|
|
152
|
+
return [0];
|
|
153
|
+
}
|
|
154
|
+
this.sourceMasterLanguage = utils_1.fsUtil.readFile(path.join(this.langFolderPath, this.masterLanguageConfig.fileName));
|
|
155
|
+
cli_utilities_1.log.debug('Loaded source master language configuration', this.config.context);
|
|
156
|
+
const localesCount = (_a = (0, lodash_1.keys)(this.languages || {})) === null || _a === void 0 ? void 0 : _a.length;
|
|
157
|
+
cli_utilities_1.log.debug(`Found ${localesCount} languages to import`, this.config.context);
|
|
158
|
+
return [localesCount];
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
setupLocalesProgress(localesCount) {
|
|
162
|
+
const progress = this.createNestedProgress(this.currentModuleName);
|
|
163
|
+
progress.addProcess(utils_1.PROCESS_NAMES.MASTER_LOCALE, 1);
|
|
164
|
+
if (localesCount > 0) {
|
|
165
|
+
progress.addProcess(utils_1.PROCESS_NAMES.LOCALES_CREATE, localesCount);
|
|
166
|
+
progress.addProcess(utils_1.PROCESS_NAMES.LOCALES_UPDATE, localesCount);
|
|
167
|
+
}
|
|
168
|
+
return progress;
|
|
169
|
+
}
|
|
170
|
+
async prepareLocalesMapper() {
|
|
171
|
+
cli_utilities_1.log.debug('Creating languages mapper directory', this.config.context);
|
|
172
|
+
utils_1.fileHelper.makeDirectory(this.langMapperPath);
|
|
173
|
+
cli_utilities_1.log.debug('Created languages mapper directory', this.config.context);
|
|
174
|
+
if (utils_1.fileHelper.fileExistsSync(this.langUidMapperPath)) {
|
|
175
|
+
this.langUidMapper = utils_1.fsUtil.readFile(this.langUidMapperPath) || {};
|
|
176
|
+
const langUidCount = Object.keys(this.langUidMapper || {}).length;
|
|
177
|
+
cli_utilities_1.log.debug(`Loaded existing language UID data: ${langUidCount} items`, this.config.context);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
cli_utilities_1.log.debug('No existing language UID mappings found', this.config.context);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async processMasterLocale(progress) {
|
|
184
|
+
progress
|
|
185
|
+
.startProcess(utils_1.PROCESS_NAMES.MASTER_LOCALE)
|
|
186
|
+
.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.MASTER_LOCALE].PROCESSING, utils_1.PROCESS_NAMES.MASTER_LOCALE);
|
|
187
|
+
cli_utilities_1.log.debug('Checking and updating master locale', this.config.context);
|
|
188
|
+
try {
|
|
189
|
+
await this.checkAndUpdateMasterLocale();
|
|
190
|
+
progress.completeProcess(utils_1.PROCESS_NAMES.MASTER_LOCALE, true);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
progress.completeProcess(utils_1.PROCESS_NAMES.MASTER_LOCALE, false);
|
|
194
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async processLocaleCreation(progress) {
|
|
198
|
+
progress
|
|
199
|
+
.startProcess(utils_1.PROCESS_NAMES.LOCALES_CREATE)
|
|
200
|
+
.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.LOCALES_CREATE].CREATING, utils_1.PROCESS_NAMES.LOCALES_CREATE);
|
|
201
|
+
cli_utilities_1.log.debug('Creating locales', this.config.context);
|
|
202
|
+
try {
|
|
203
|
+
await this.createLocales();
|
|
204
|
+
progress.completeProcess(utils_1.PROCESS_NAMES.LOCALES_CREATE, true);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
progress.completeProcess(utils_1.PROCESS_NAMES.LOCALES_CREATE, false);
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async processLocaleUpdate(progress) {
|
|
212
|
+
progress
|
|
213
|
+
.startProcess(utils_1.PROCESS_NAMES.LOCALES_UPDATE)
|
|
214
|
+
.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.LOCALES_UPDATE].UPDATING, utils_1.PROCESS_NAMES.LOCALES_UPDATE);
|
|
215
|
+
cli_utilities_1.log.debug('Updating locales', this.config.context);
|
|
216
|
+
try {
|
|
217
|
+
await this.updateLocales();
|
|
218
|
+
progress.completeProcess(utils_1.PROCESS_NAMES.LOCALES_UPDATE, true);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
progress.completeProcess(utils_1.PROCESS_NAMES.LOCALES_UPDATE, false);
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
getSourceMasterLangDetails() {
|
|
226
|
+
const details = this.sourceMasterLanguage && Object.values(this.sourceMasterLanguage);
|
|
227
|
+
const lang = details === null || details === void 0 ? void 0 : details[0];
|
|
228
|
+
if (!lang) {
|
|
229
|
+
cli_utilities_1.log.info('No source master language details found', this.config.context);
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
return lang;
|
|
233
|
+
}
|
|
234
|
+
async fetchTargetMasterLocale() {
|
|
235
|
+
try {
|
|
236
|
+
cli_utilities_1.log.debug('Fetching current master language details from stack', this.config.context);
|
|
237
|
+
return await this.stackAPIClient.locale(this.masterLanguage.code).fetch();
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
cli_utilities_1.log.debug('Error fetching master language details', this.config.context);
|
|
241
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
logCodeMismatch(sourceCode) {
|
|
246
|
+
var _a;
|
|
247
|
+
const targetCode = (_a = this.masterLanguage) === null || _a === void 0 ? void 0 : _a.code;
|
|
248
|
+
const message = `master locale: codes differ (${sourceCode} vs ${targetCode})`;
|
|
249
|
+
this.tickProgress(true, message);
|
|
250
|
+
cli_utilities_1.log.debug(`Master Locale language codes do not match. Source: ${sourceCode}, Target: ${targetCode}`, this.config.context);
|
|
251
|
+
}
|
|
252
|
+
async handleNameMismatch(source, target) {
|
|
253
|
+
cli_utilities_1.log.debug('Master Locale language name differs between source and destination', this.config.context);
|
|
254
|
+
cli_utilities_1.log.debug(`Current: ${target.name}, Source: ${source.name}`, this.config.context);
|
|
255
|
+
cli_utilities_1.cliux.print('WARNING!!! The master language name for the source and destination is different.', {
|
|
256
|
+
color: 'yellow',
|
|
257
|
+
});
|
|
258
|
+
cli_utilities_1.cliux.print('WARNING!!! The master language name for the source and destination is different.', {
|
|
259
|
+
color: 'yellow',
|
|
260
|
+
});
|
|
261
|
+
cli_utilities_1.cliux.print(`Old Master Locale language name: ${target.name}`, { color: 'red' });
|
|
262
|
+
cli_utilities_1.cliux.print(`New Master Locale language name: ${source.name}`, { color: 'green' });
|
|
263
|
+
const langUpdateConfirmation = await cli_utilities_1.cliux.inquire({
|
|
264
|
+
type: 'confirm',
|
|
265
|
+
message: 'Are you sure you want to update name of master language?',
|
|
266
|
+
name: 'confirmation',
|
|
267
|
+
});
|
|
268
|
+
if (!langUpdateConfirmation) {
|
|
269
|
+
this.tickProgress(true, `${target.name} (skipped update)`);
|
|
270
|
+
cli_utilities_1.log.info('Master Locale language update cancelled by user', this.config.context);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
cli_utilities_1.log.debug('User confirmed master language update', this.config.context);
|
|
274
|
+
try {
|
|
275
|
+
const updatePayload = Object.assign(Object.assign({}, source), { uid: target.uid });
|
|
276
|
+
const langUpdateRequest = this.stackAPIClient.locale(source.code);
|
|
277
|
+
langUpdateRequest.name = source.name;
|
|
278
|
+
await langUpdateRequest.update(updatePayload);
|
|
279
|
+
this.tickProgress(true, `${source.name} (updated)`);
|
|
280
|
+
cli_utilities_1.log.success(`Successfully updated master language name from '${target.name}' to '${source.name}'`, this.config.context);
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
this.tickProgress(false, source === null || source === void 0 ? void 0 : source.name, (error === null || error === void 0 ? void 0 : error.message) || 'Failed to update master locale');
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
tickProgress(success, message, error) {
|
|
288
|
+
var _a;
|
|
289
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(success, `master locale: ${message}`, error || null, utils_1.PROCESS_NAMES.MASTER_LOCALE);
|
|
290
|
+
}
|
|
191
291
|
}
|
|
192
292
|
exports.default = ImportLocales;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NodeCrypto, ContentstackMarketplaceClient } from '@contentstack/cli-utilities';
|
|
2
2
|
import { ModuleClassParams, ImportConfig, Installation, Manifest } from '../../types';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import BaseClass from './base-class';
|
|
4
|
+
export default class ImportMarketplaceApps extends BaseClass {
|
|
5
5
|
private mapperDirPath;
|
|
6
6
|
private marketPlaceFolderPath;
|
|
7
7
|
private marketPlaceUidMapperPath;
|
|
@@ -16,7 +16,7 @@ export default class ImportMarketplaceApps {
|
|
|
16
16
|
nodeCrypto: NodeCrypto;
|
|
17
17
|
appSdk: ContentstackMarketplaceClient;
|
|
18
18
|
existingNames: Set<string>;
|
|
19
|
-
constructor({ importConfig }: ModuleClassParams);
|
|
19
|
+
constructor({ importConfig, stackAPIClient }: ModuleClassParams);
|
|
20
20
|
/**
|
|
21
21
|
* This function starts the process of importing marketplace apps.
|
|
22
22
|
* @returns The function `start()` returns a `Promise<void>`.
|
|
@@ -125,4 +125,7 @@ export default class ImportMarketplaceApps {
|
|
|
125
125
|
* app. It contains the following properties:
|
|
126
126
|
*/
|
|
127
127
|
updateAppsConfig(app: Installation): Promise<void>;
|
|
128
|
+
private analyzeMarketplaceApps;
|
|
129
|
+
private prepareMarketplaceAppMapper;
|
|
130
|
+
private setupMarketplaceEnvironment;
|
|
128
131
|
}
|