@contentstack/cli-cm-import 1.25.1 → 1.26.1
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 +3 -3
- package/lib/commands/cm/stacks/import.d.ts +1 -0
- package/lib/commands/cm/stacks/import.js +39 -12
- package/lib/import/module-importer.js +20 -3
- package/lib/import/modules/assets.d.ts +1 -1
- package/lib/import/modules/assets.js +93 -39
- package/lib/import/modules/content-types.js +76 -31
- package/lib/import/modules/custom-roles.js +95 -19
- package/lib/import/modules/entries.js +128 -57
- package/lib/import/modules/environments.js +48 -14
- package/lib/import/modules/extensions.js +78 -16
- package/lib/import/modules/global-fields.js +85 -20
- package/lib/import/modules/labels.d.ts +4 -4
- package/lib/import/modules/labels.js +60 -18
- package/lib/import/modules/locales.js +63 -20
- package/lib/import/modules/marketplace-apps.js +160 -31
- package/lib/import/modules/personalize.js +33 -7
- package/lib/import/modules/stack.js +5 -0
- package/lib/import/modules/taxonomies.js +52 -13
- package/lib/import/modules/variant-entries.js +21 -3
- package/lib/import/modules/webhooks.js +44 -12
- package/lib/import/modules/workflows.js +65 -21
- package/lib/types/import-config.d.ts +3 -1
- package/lib/types/index.d.ts +22 -0
- package/lib/utils/asset-helper.js +24 -1
- package/lib/utils/backup-handler.js +15 -1
- package/lib/utils/common-helper.js +41 -16
- package/lib/utils/content-type-helper.js +35 -2
- package/lib/utils/entries-helper.js +24 -2
- package/lib/utils/extension-helper.js +35 -1
- package/lib/utils/import-config-handler.js +21 -0
- package/lib/utils/login-handler.js +8 -4
- package/lib/utils/marketplace-app-helper.js +50 -11
- package/lib/utils/taxonomies-helper.js +22 -4
- package/oclif.manifest.json +2 -2
- package/package.json +6 -6
|
@@ -16,6 +16,7 @@ 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 = 'locales';
|
|
19
20
|
this.localeConfig = importConfig.modules.locales;
|
|
20
21
|
this.masterLanguage = importConfig.masterLocale;
|
|
21
22
|
this.masterLanguageConfig = importConfig.modules.masterLocale;
|
|
@@ -32,42 +33,67 @@ class ImportLocales extends base_class_1.default {
|
|
|
32
33
|
this.langUidMapperPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.data), 'mapper', 'languages', 'uid-mapper.json');
|
|
33
34
|
}
|
|
34
35
|
async start() {
|
|
36
|
+
cli_utilities_1.log.debug('Loading locales from file', this.config.context);
|
|
35
37
|
this.languages = utils_1.fsUtil.readFile(path.join(this.langFolderPath, this.localeConfig.fileName));
|
|
36
38
|
if (!this.languages || (0, lodash_1.isEmpty)(this.languages)) {
|
|
37
|
-
|
|
39
|
+
cli_utilities_1.log.info('No languages found to import', this.config.context);
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
42
|
+
cli_utilities_1.log.debug(`Found ${(0, lodash_1.values)(this.languages).length} languages to import`, this.config.context);
|
|
43
|
+
cli_utilities_1.log.debug('Loading source master language configuration', this.config.context);
|
|
40
44
|
this.sourceMasterLanguage = utils_1.fsUtil.readFile(path.join(this.langFolderPath, this.masterLanguageConfig.fileName));
|
|
45
|
+
cli_utilities_1.log.debug('Loaded source master language configuration', this.config.context);
|
|
46
|
+
cli_utilities_1.log.debug('Creating languages mapper directory', this.config.context);
|
|
41
47
|
await utils_1.fileHelper.makeDirectory(this.langMapperPath);
|
|
48
|
+
cli_utilities_1.log.debug('Created languages mapper directory', this.config.context);
|
|
49
|
+
cli_utilities_1.log.debug('Loading existing language UID mappings', this.config.context);
|
|
42
50
|
if (utils_1.fileHelper.fileExistsSync(this.langUidMapperPath)) {
|
|
43
51
|
this.langUidMapper = utils_1.fsUtil.readFile(this.langUidMapperPath) || {};
|
|
52
|
+
const langUidCount = Object.keys(this.langUidMapper || {}).length;
|
|
53
|
+
cli_utilities_1.log.debug(`Loaded existing language UID data: ${langUidCount} items`, this.config.context);
|
|
44
54
|
}
|
|
55
|
+
else {
|
|
56
|
+
cli_utilities_1.log.debug('No existing language UID mappings found', this.config.context);
|
|
57
|
+
}
|
|
58
|
+
cli_utilities_1.log.debug('Checking and updating master locale', this.config.context);
|
|
45
59
|
await this.checkAndUpdateMasterLocale().catch((error) => {
|
|
46
|
-
(0,
|
|
60
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
47
61
|
});
|
|
62
|
+
cli_utilities_1.log.debug('Creating locales', this.config.context);
|
|
48
63
|
await this.createLocales().catch((error) => {
|
|
49
|
-
(0,
|
|
64
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
50
65
|
Promise.reject('Failed to import locales');
|
|
51
66
|
});
|
|
67
|
+
cli_utilities_1.log.debug('Writing failed locales to file', this.config.context);
|
|
52
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);
|
|
53
71
|
await this.updateLocales().catch((error) => {
|
|
54
|
-
(0,
|
|
72
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
55
73
|
Promise.reject('Failed to update locales');
|
|
56
74
|
});
|
|
57
|
-
|
|
75
|
+
cli_utilities_1.log.success('Languages have been imported successfully!', this.config.context);
|
|
58
76
|
}
|
|
59
77
|
async checkAndUpdateMasterLocale() {
|
|
60
|
-
var _a, _b, _c, _d;
|
|
78
|
+
var _a, _b, _c, _d, _e;
|
|
79
|
+
cli_utilities_1.log.debug('Checking and updating master locale', this.config.context);
|
|
61
80
|
let sourceMasterLangDetails = (this.sourceMasterLanguage && Object.values(this.sourceMasterLanguage)) || [];
|
|
81
|
+
cli_utilities_1.log.debug(`Source master language details count: ${sourceMasterLangDetails.length}`, this.config.context);
|
|
62
82
|
if (((_a = sourceMasterLangDetails === null || sourceMasterLangDetails === void 0 ? void 0 : sourceMasterLangDetails[0]) === null || _a === void 0 ? void 0 : _a.code) === ((_b = this.masterLanguage) === null || _b === void 0 ? void 0 : _b.code)) {
|
|
83
|
+
cli_utilities_1.log.debug(`Master locale code matches: ${(_c = this.masterLanguage) === null || _c === void 0 ? void 0 : _c.code}`, this.config.context);
|
|
84
|
+
cli_utilities_1.log.debug('Fetching current master language details from stack', this.config.context);
|
|
63
85
|
let masterLangDetails = await this.stackAPIClient
|
|
64
86
|
.locale(this.masterLanguage['code'])
|
|
65
87
|
.fetch()
|
|
66
88
|
.catch((error) => {
|
|
67
|
-
|
|
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));
|
|
68
91
|
});
|
|
69
|
-
if (((
|
|
70
|
-
((
|
|
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);
|
|
71
97
|
cli_utilities_1.cliux.print('WARNING!!! The master language name for the source and destination is different.', {
|
|
72
98
|
color: 'yellow',
|
|
73
99
|
});
|
|
@@ -79,41 +105,56 @@ class ImportLocales extends base_class_1.default {
|
|
|
79
105
|
name: 'confirmation',
|
|
80
106
|
});
|
|
81
107
|
if (langUpdateConfirmation) {
|
|
108
|
+
cli_utilities_1.log.debug('User confirmed master language name update', this.config.context);
|
|
82
109
|
let langUid = sourceMasterLangDetails[0] && sourceMasterLangDetails[0]['uid'];
|
|
83
110
|
let sourceMasterLanguage = this.sourceMasterLanguage[langUid];
|
|
84
111
|
if (!sourceMasterLanguage) {
|
|
85
|
-
|
|
112
|
+
cli_utilities_1.log.info(`Master language details not found with id ${langUid} to update`, this.config.context);
|
|
86
113
|
}
|
|
114
|
+
cli_utilities_1.log.debug(`Updating master language name: ${sourceMasterLanguage.name}`, this.config.context);
|
|
87
115
|
const langUpdateRequest = this.stackAPIClient.locale(sourceMasterLanguage.code);
|
|
88
116
|
langUpdateRequest.name = sourceMasterLanguage.name;
|
|
89
117
|
await langUpdateRequest.update().catch(function (error) {
|
|
90
|
-
|
|
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));
|
|
91
120
|
});
|
|
92
|
-
|
|
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);
|
|
93
125
|
}
|
|
94
126
|
}
|
|
127
|
+
else {
|
|
128
|
+
cli_utilities_1.log.debug('Master language names match, no update needed', this.config.context);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
cli_utilities_1.log.debug('Master language codes do not match', this.config.context);
|
|
95
133
|
}
|
|
96
134
|
}
|
|
97
135
|
async createLocales() {
|
|
136
|
+
const languagesToCreate = (0, lodash_1.filter)((0, lodash_1.values)(this.languages), (lang) => lang.code !== this.masterLanguage.code);
|
|
137
|
+
cli_utilities_1.log.debug(`Creating ${languagesToCreate.length} locales (excluding master locale)`, this.config.context);
|
|
98
138
|
const onSuccess = ({ response = {}, apiData: { uid, code } = undefined }) => {
|
|
99
139
|
this.langUidMapper[uid] = response.uid;
|
|
100
140
|
this.createdLocales.push((0, lodash_1.pick)(response, [...this.localeConfig.requiredKeys]));
|
|
101
|
-
|
|
141
|
+
cli_utilities_1.log.info(`Created locale: '${code}'`, this.config.context);
|
|
142
|
+
cli_utilities_1.log.debug(`Locale UID mapping: ${uid} → ${response.uid}`, this.config.context);
|
|
102
143
|
utils_1.fsUtil.writeFile(this.langUidMapperPath, this.langUidMapper);
|
|
103
144
|
};
|
|
104
145
|
const onReject = ({ error, apiData: { uid, code } = undefined }) => {
|
|
105
146
|
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 247) {
|
|
106
|
-
|
|
147
|
+
cli_utilities_1.log.info((0, utils_1.formatError)(error), this.config.context);
|
|
107
148
|
}
|
|
108
149
|
else {
|
|
109
|
-
|
|
110
|
-
(0,
|
|
150
|
+
cli_utilities_1.log.error(`Language '${code}' failed to import`, this.config.context);
|
|
151
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.config.context), { code }));
|
|
111
152
|
}
|
|
112
153
|
this.failedLocales.push({ uid, code });
|
|
113
154
|
};
|
|
114
155
|
return await this.makeConcurrentCall({
|
|
115
156
|
processName: 'Import locales',
|
|
116
|
-
apiContent:
|
|
157
|
+
apiContent: languagesToCreate,
|
|
117
158
|
apiParams: {
|
|
118
159
|
reject: onReject.bind(this),
|
|
119
160
|
resolve: onSuccess.bind(this),
|
|
@@ -124,13 +165,15 @@ class ImportLocales extends base_class_1.default {
|
|
|
124
165
|
});
|
|
125
166
|
}
|
|
126
167
|
async updateLocales() {
|
|
168
|
+
cli_utilities_1.log.debug(`Updating ${(0, lodash_1.values)(this.languages).length} locales`, this.config.context);
|
|
127
169
|
const onSuccess = ({ response = {}, apiData: { uid, code } = undefined }) => {
|
|
128
|
-
|
|
170
|
+
cli_utilities_1.log.info(`Updated locale: '${code}'`, this.config.context);
|
|
171
|
+
cli_utilities_1.log.debug(`Locale update completed for: ${code}`, this.config.context);
|
|
129
172
|
utils_1.fsUtil.writeFile(this.langSuccessPath, this.createdLocales);
|
|
130
173
|
};
|
|
131
174
|
const onReject = ({ error, apiData: { uid, code } = undefined }) => {
|
|
132
|
-
|
|
133
|
-
(0,
|
|
175
|
+
cli_utilities_1.log.error(`Language '${code}' failed to update`, this.config.context);
|
|
176
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.config.context), { code }));
|
|
134
177
|
utils_1.fsUtil.writeFile(this.langFailsPath, this.failedLocales);
|
|
135
178
|
};
|
|
136
179
|
return await this.makeConcurrentCall({
|