@contentstack/cli-cm-import 1.28.3 → 1.29.0
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 +1 -1
- package/lib/import/modules/base-class.d.ts +1 -0
- package/lib/import/modules/base-class.js +3 -1
- package/lib/import/modules/locales.js +1 -1
- package/lib/import/modules/taxonomies.d.ts +23 -4
- package/lib/import/modules/taxonomies.js +172 -62
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
|
|
|
47
47
|
$ csdx COMMAND
|
|
48
48
|
running command...
|
|
49
49
|
$ csdx (--version)
|
|
50
|
-
@contentstack/cli-cm-import/1.
|
|
50
|
+
@contentstack/cli-cm-import/1.29.0 linux-x64 node-v22.21.1
|
|
51
51
|
$ csdx --help [COMMAND]
|
|
52
52
|
USAGE
|
|
53
53
|
$ csdx COMMAND
|
|
@@ -9,6 +9,7 @@ export type ApiOptions = {
|
|
|
9
9
|
url?: string;
|
|
10
10
|
entity: ApiModuleType;
|
|
11
11
|
apiData?: Record<any, any> | any;
|
|
12
|
+
queryParam?: Record<any, any>;
|
|
12
13
|
resolve: (value: any) => Promise<void> | void;
|
|
13
14
|
reject: (error: any) => Promise<void> | void;
|
|
14
15
|
additionalInfo?: Record<any, any>;
|
|
@@ -292,7 +292,9 @@ class BaseClass {
|
|
|
292
292
|
if (!apiData || !apiData.filePath) {
|
|
293
293
|
return Promise.resolve();
|
|
294
294
|
}
|
|
295
|
-
|
|
295
|
+
const importParams = { taxonomy: apiData.filePath };
|
|
296
|
+
const importQueryParam = apiOptions.queryParam || {};
|
|
297
|
+
return this.stack.taxonomy(uid).import(importParams, importQueryParam).then(onSuccess).catch(onReject);
|
|
296
298
|
default:
|
|
297
299
|
return Promise.resolve();
|
|
298
300
|
}
|
|
@@ -114,7 +114,7 @@ class ImportLocales extends base_class_1.default {
|
|
|
114
114
|
cli_utilities_1.log.debug(`Updating master language name: ${sourceMasterLanguage.name}`, this.config.context);
|
|
115
115
|
const langUpdateRequest = this.stackAPIClient.locale(sourceMasterLanguage.code);
|
|
116
116
|
langUpdateRequest.name = sourceMasterLanguage.name;
|
|
117
|
-
await langUpdateRequest.update().catch(
|
|
117
|
+
await langUpdateRequest.update().catch((error) => {
|
|
118
118
|
cli_utilities_1.log.debug('Error updating master language name', this.config.context);
|
|
119
119
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context));
|
|
120
120
|
});
|
|
@@ -10,6 +10,8 @@ export default class ImportTaxonomies extends BaseClass {
|
|
|
10
10
|
private termsMapperDirPath;
|
|
11
11
|
private termsSuccessPath;
|
|
12
12
|
private termsFailsPath;
|
|
13
|
+
private localesFilePath;
|
|
14
|
+
private isLocaleBasedStructure;
|
|
13
15
|
createdTaxonomies: Record<string, unknown>;
|
|
14
16
|
failedTaxonomies: Record<string, unknown>;
|
|
15
17
|
createdTerms: Record<string, Record<string, unknown>>;
|
|
@@ -26,17 +28,34 @@ export default class ImportTaxonomies extends BaseClass {
|
|
|
26
28
|
* @async
|
|
27
29
|
* @returns {Promise<any>} Promise<any>
|
|
28
30
|
*/
|
|
29
|
-
importTaxonomies(
|
|
31
|
+
importTaxonomies({ apiContent, localeCode }: {
|
|
32
|
+
apiContent: any[];
|
|
33
|
+
localeCode?: string;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
importTaxonomiesLegacy(): Promise<void>;
|
|
36
|
+
importTaxonomiesByLocale(): Promise<void>;
|
|
37
|
+
handleSuccess(apiData: any, locale?: string): void;
|
|
38
|
+
handleFailure(error: any, apiData: any, locale?: string): void;
|
|
30
39
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @param {ApiOptions} apiOptions
|
|
33
|
-
* @
|
|
40
|
+
*
|
|
41
|
+
* @param {ApiOptions} apiOptions
|
|
42
|
+
* @param {?string} [localeCode]
|
|
43
|
+
* @returns {ApiOptions}
|
|
34
44
|
*/
|
|
35
45
|
serializeTaxonomy(apiOptions: ApiOptions): ApiOptions;
|
|
46
|
+
loadTaxonomyFile(filePath: string, context: string): Record<string, unknown> | undefined;
|
|
47
|
+
findTaxonomyFilePath(taxonomyUID: string): string | undefined;
|
|
48
|
+
findTaxonomyInLocaleFolders(taxonomyUID: string): string | undefined;
|
|
49
|
+
loadAvailableLocales(): Record<string, string>;
|
|
36
50
|
/**
|
|
37
51
|
* create taxonomies success and fail in (mapper/taxonomies)
|
|
38
52
|
* create terms success and fail in (mapper/taxonomies/terms)
|
|
39
53
|
* @method createSuccessAndFailedFile
|
|
40
54
|
*/
|
|
41
55
|
createSuccessAndFailedFile(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Detect if locale-based folder structure exists and scan taxonomies by locale
|
|
58
|
+
* @returns {boolean} true if locale-based structure detected, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
detectAndScanLocaleStructure(): boolean;
|
|
42
61
|
}
|
|
@@ -10,6 +10,7 @@ const utils_1 = require("../../utils");
|
|
|
10
10
|
class ImportTaxonomies extends base_class_1.default {
|
|
11
11
|
constructor({ importConfig, stackAPIClient }) {
|
|
12
12
|
super({ importConfig, stackAPIClient });
|
|
13
|
+
this.isLocaleBasedStructure = false;
|
|
13
14
|
this.createdTaxonomies = {};
|
|
14
15
|
this.failedTaxonomies = {};
|
|
15
16
|
this.createdTerms = {};
|
|
@@ -23,6 +24,7 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
23
24
|
this.taxFailsPath = (0, node_path_1.join)(this.taxonomiesMapperDirPath, 'fails.json');
|
|
24
25
|
this.termsSuccessPath = (0, node_path_1.join)(this.termsMapperDirPath, 'success.json');
|
|
25
26
|
this.termsFailsPath = (0, node_path_1.join)(this.termsMapperDirPath, 'fails.json');
|
|
27
|
+
this.localesFilePath = (0, node_path_1.join)(importConfig.backupDir, importConfig.modules.locales.dirName, importConfig.modules.locales.fileName);
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* @method start
|
|
@@ -46,10 +48,21 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
46
48
|
await utils_1.fsUtil.makeDirectory(this.taxonomiesMapperDirPath);
|
|
47
49
|
await utils_1.fsUtil.makeDirectory(this.termsMapperDirPath);
|
|
48
50
|
cli_utilities_1.log.debug('Created taxonomies and terms mapper directories', this.importConfig.context);
|
|
49
|
-
// Step 3
|
|
50
|
-
cli_utilities_1.log.debug('
|
|
51
|
-
|
|
52
|
-
//Step 4
|
|
51
|
+
// Step 3: Check if locale-based structure exists and scan taxonomies by locale
|
|
52
|
+
cli_utilities_1.log.debug('Checking for locale-based folder structure', this.importConfig.context);
|
|
53
|
+
this.isLocaleBasedStructure = this.detectAndScanLocaleStructure();
|
|
54
|
+
// Step 4 import taxonomies
|
|
55
|
+
if (this.isLocaleBasedStructure) {
|
|
56
|
+
cli_utilities_1.log.debug('Detected locale-based folder structure for taxonomies', this.importConfig.context);
|
|
57
|
+
cli_utilities_1.log.debug('Starting taxonomies import', this.importConfig.context);
|
|
58
|
+
await this.importTaxonomiesByLocale();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
cli_utilities_1.log.debug('Starting taxonomies import', this.importConfig.context);
|
|
62
|
+
await this.importTaxonomiesLegacy();
|
|
63
|
+
cli_utilities_1.log.debug('Using legacy folder structure for taxonomies', this.importConfig.context);
|
|
64
|
+
}
|
|
65
|
+
//Step 5 create taxonomy & related terms success & failure file
|
|
53
66
|
cli_utilities_1.log.debug('Creating success and failure files', this.importConfig.context);
|
|
54
67
|
this.createSuccessAndFailedFile();
|
|
55
68
|
cli_utilities_1.log.success('Taxonomies imported successfully!', this.importConfig.context);
|
|
@@ -60,50 +73,9 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
60
73
|
* @async
|
|
61
74
|
* @returns {Promise<any>} Promise<any>
|
|
62
75
|
*/
|
|
63
|
-
async importTaxonomies() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
cli_utilities_1.log.info('No Taxonomies Found!', this.importConfig.context);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const apiContent = (0, values_1.default)(this.taxonomies);
|
|
70
|
-
cli_utilities_1.log.debug(`Starting to import ${apiContent.length} taxonomies`, this.importConfig.context);
|
|
71
|
-
const onSuccess = ({ apiData }) => {
|
|
72
|
-
var _a, _b;
|
|
73
|
-
const taxonomyUID = (_a = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _a === void 0 ? void 0 : _a.uid;
|
|
74
|
-
const taxonomyName = (_b = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _b === void 0 ? void 0 : _b.name;
|
|
75
|
-
const termsCount = Object.keys((apiData === null || apiData === void 0 ? void 0 : apiData.terms) || {}).length;
|
|
76
|
-
this.createdTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
|
|
77
|
-
this.createdTerms[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.terms;
|
|
78
|
-
cli_utilities_1.log.success(`Taxonomy '${taxonomyUID}' imported successfully!`, this.importConfig.context);
|
|
79
|
-
cli_utilities_1.log.debug(`Created taxonomy '${taxonomyName}' with ${termsCount} terms`, this.importConfig.context);
|
|
80
|
-
cli_utilities_1.log.debug(`Taxonomy details: ${JSON.stringify({ uid: taxonomyUID, name: taxonomyName, termsCount })}`, this.importConfig.context);
|
|
81
|
-
};
|
|
82
|
-
const onReject = ({ error, apiData }) => {
|
|
83
|
-
var _a, _b, _c, _d;
|
|
84
|
-
const taxonomyUID = (_a = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _a === void 0 ? void 0 : _a.uid;
|
|
85
|
-
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
|
-
if ((error === null || error === void 0 ? void 0 : error.status) === 409 && (error === null || error === void 0 ? void 0 : error.statusText) === 'Conflict') {
|
|
88
|
-
cli_utilities_1.log.info(`Taxonomy '${taxonomyUID}' already exists!`, this.importConfig.context);
|
|
89
|
-
cli_utilities_1.log.debug(`Adding existing taxonomy '${taxonomyUID}' to created list`, this.importConfig.context);
|
|
90
|
-
this.createdTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
|
|
91
|
-
this.createdTerms[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.terms;
|
|
92
|
-
}
|
|
93
|
-
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
|
-
this.failedTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
|
|
103
|
-
this.failedTerms[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.terms;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
cli_utilities_1.log.debug(`Using concurrency limit: ${this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1}`, this.importConfig.context);
|
|
76
|
+
async importTaxonomies({ apiContent, localeCode }) {
|
|
77
|
+
const onSuccess = ({ apiData }) => this.handleSuccess(apiData, localeCode);
|
|
78
|
+
const onReject = ({ error, apiData }) => this.handleFailure(error, apiData, localeCode);
|
|
107
79
|
await this.makeConcurrentCall({
|
|
108
80
|
apiContent,
|
|
109
81
|
processName: 'import taxonomies',
|
|
@@ -113,35 +85,157 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
113
85
|
resolve: onSuccess,
|
|
114
86
|
entity: 'import-taxonomy',
|
|
115
87
|
includeParamOnCompletion: true,
|
|
88
|
+
queryParam: {
|
|
89
|
+
locale: localeCode,
|
|
90
|
+
},
|
|
116
91
|
},
|
|
117
92
|
concurrencyLimit: this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1,
|
|
118
93
|
}, undefined, false);
|
|
119
|
-
|
|
94
|
+
}
|
|
95
|
+
async importTaxonomiesLegacy() {
|
|
96
|
+
const apiContent = (0, values_1.default)(this.taxonomies);
|
|
97
|
+
await this.importTaxonomies({
|
|
98
|
+
apiContent,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async importTaxonomiesByLocale() {
|
|
102
|
+
const locales = this.loadAvailableLocales();
|
|
103
|
+
const apiContent = (0, values_1.default)(this.taxonomies);
|
|
104
|
+
for (const localeCode of Object.keys(locales)) {
|
|
105
|
+
await this.importTaxonomies({
|
|
106
|
+
apiContent,
|
|
107
|
+
localeCode,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
handleSuccess(apiData, locale) {
|
|
112
|
+
const { taxonomy, terms } = apiData || {};
|
|
113
|
+
const taxonomyUID = taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.uid;
|
|
114
|
+
const taxonomyName = taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.name;
|
|
115
|
+
const termsCount = Object.keys(terms || {}).length;
|
|
116
|
+
this.createdTaxonomies[taxonomyUID] = taxonomy;
|
|
117
|
+
this.createdTerms[taxonomyUID] = terms;
|
|
118
|
+
cli_utilities_1.log.success(`Taxonomy '${taxonomyUID}' imported successfully${locale ? ` for locale: ${locale}` : ''}!`, this.importConfig.context);
|
|
119
|
+
cli_utilities_1.log.debug(`Created taxonomy '${taxonomyName}' with ${termsCount} terms${locale ? ` for locale: ${locale}` : ''}`, this.importConfig.context);
|
|
120
|
+
}
|
|
121
|
+
handleFailure(error, apiData, locale) {
|
|
122
|
+
var _a, _b, _c;
|
|
123
|
+
const taxonomyUID = (_a = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _a === void 0 ? void 0 : _a.uid;
|
|
124
|
+
if ((error === null || error === void 0 ? void 0 : error.status) === 409 && (error === null || error === void 0 ? void 0 : error.statusText) === 'Conflict') {
|
|
125
|
+
cli_utilities_1.log.info(`Taxonomy '${taxonomyUID}' already exists${locale ? ` for locale: ${locale}` : ''}!`, this.importConfig.context);
|
|
126
|
+
this.createdTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
|
|
127
|
+
this.createdTerms[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.terms;
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const errMsg = (error === null || error === void 0 ? void 0 : error.errorMessage) || ((_b = error === null || error === void 0 ? void 0 : error.errors) === null || _b === void 0 ? void 0 : _b.taxonomy) || ((_c = error === null || error === void 0 ? void 0 : error.errors) === null || _c === void 0 ? void 0 : _c.term) || (error === null || error === void 0 ? void 0 : error.message);
|
|
131
|
+
if (errMsg) {
|
|
132
|
+
cli_utilities_1.log.error(`Taxonomy '${taxonomyUID}' failed to import${locale ? ` for locale: ${locale}` : ''}! ${errMsg}`, this.importConfig.context);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { taxonomyUID, locale }), `Taxonomy '${taxonomyUID}' failed`);
|
|
136
|
+
}
|
|
137
|
+
this.failedTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
|
|
138
|
+
this.failedTerms[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.terms;
|
|
120
139
|
}
|
|
121
140
|
/**
|
|
122
|
-
*
|
|
123
|
-
* @param {ApiOptions} apiOptions
|
|
124
|
-
* @
|
|
141
|
+
*
|
|
142
|
+
* @param {ApiOptions} apiOptions
|
|
143
|
+
* @param {?string} [localeCode]
|
|
144
|
+
* @returns {ApiOptions}
|
|
125
145
|
*/
|
|
126
146
|
serializeTaxonomy(apiOptions) {
|
|
127
|
-
const { apiData } = apiOptions;
|
|
147
|
+
const { apiData, queryParam: { locale }, } = apiOptions;
|
|
128
148
|
const taxonomyUID = apiData === null || apiData === void 0 ? void 0 : apiData.uid;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
149
|
+
if (!taxonomyUID) {
|
|
150
|
+
cli_utilities_1.log.debug('No taxonomy UID provided for serialization', this.importConfig.context);
|
|
151
|
+
apiOptions.apiData = undefined;
|
|
152
|
+
return apiOptions;
|
|
153
|
+
}
|
|
154
|
+
const context = locale ? ` for locale: ${locale}` : '';
|
|
155
|
+
cli_utilities_1.log.debug(`Serializing taxonomy: ${taxonomyUID}${context}`, this.importConfig.context);
|
|
156
|
+
// Determine file path - if locale is provided, use it directly, otherwise search
|
|
157
|
+
const filePath = locale
|
|
158
|
+
? (0, node_path_1.join)(this.taxonomiesFolderPath, locale, `${taxonomyUID}.json`)
|
|
159
|
+
: this.findTaxonomyFilePath(taxonomyUID);
|
|
160
|
+
if (!filePath || !utils_1.fileHelper.fileExistsSync(filePath)) {
|
|
161
|
+
cli_utilities_1.log.debug(`Taxonomy file not found for: ${taxonomyUID}${context}`, this.importConfig.context);
|
|
162
|
+
apiOptions.apiData = undefined;
|
|
163
|
+
return apiOptions;
|
|
164
|
+
}
|
|
165
|
+
const taxonomyDetails = this.loadTaxonomyFile(filePath, locale || 'auto-detected');
|
|
166
|
+
if (taxonomyDetails) {
|
|
135
167
|
const termCount = Object.keys((taxonomyDetails === null || taxonomyDetails === void 0 ? void 0 : taxonomyDetails.terms) || {}).length;
|
|
136
|
-
cli_utilities_1.log.debug(`Taxonomy has ${termCount} term entries`, this.importConfig.context);
|
|
137
|
-
apiOptions.apiData = {
|
|
168
|
+
cli_utilities_1.log.debug(`Taxonomy has ${termCount} term entries${context}`, this.importConfig.context);
|
|
169
|
+
apiOptions.apiData = {
|
|
170
|
+
filePath,
|
|
171
|
+
taxonomy: taxonomyDetails === null || taxonomyDetails === void 0 ? void 0 : taxonomyDetails.taxonomy,
|
|
172
|
+
terms: taxonomyDetails === null || taxonomyDetails === void 0 ? void 0 : taxonomyDetails.terms,
|
|
173
|
+
};
|
|
138
174
|
}
|
|
139
175
|
else {
|
|
140
|
-
cli_utilities_1.log.debug(`File does not exist for taxonomy: ${taxonomyUID}`, this.importConfig.context);
|
|
141
176
|
apiOptions.apiData = undefined;
|
|
142
177
|
}
|
|
143
178
|
return apiOptions;
|
|
144
179
|
}
|
|
180
|
+
loadTaxonomyFile(filePath, context) {
|
|
181
|
+
if (!utils_1.fileHelper.fileExistsSync(filePath)) {
|
|
182
|
+
cli_utilities_1.log.debug(`File does not exist: ${filePath}`, this.importConfig.context);
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const taxonomyDetails = utils_1.fsUtil.readFile(filePath, true);
|
|
187
|
+
cli_utilities_1.log.debug(`Successfully loaded taxonomy from: ${context}`, this.importConfig.context);
|
|
188
|
+
return taxonomyDetails;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
cli_utilities_1.log.debug(`Error loading taxonomy file: ${filePath}`, this.importConfig.context);
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
findTaxonomyFilePath(taxonomyUID) {
|
|
196
|
+
if (this.isLocaleBasedStructure) {
|
|
197
|
+
// For locale-based structure, search in locale folders
|
|
198
|
+
return this.findTaxonomyInLocaleFolders(taxonomyUID);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
// For legacy structure, only check the root folder
|
|
202
|
+
const legacyPath = (0, node_path_1.join)(this.taxonomiesFolderPath, `${taxonomyUID}.json`);
|
|
203
|
+
return utils_1.fileHelper.fileExistsSync(legacyPath) ? legacyPath : undefined;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
findTaxonomyInLocaleFolders(taxonomyUID) {
|
|
207
|
+
const locales = this.loadAvailableLocales();
|
|
208
|
+
for (const localeCode of Object.keys(locales)) {
|
|
209
|
+
const filePath = (0, node_path_1.join)(this.taxonomiesFolderPath, localeCode, `${taxonomyUID}.json`);
|
|
210
|
+
if (utils_1.fileHelper.fileExistsSync(filePath)) {
|
|
211
|
+
return filePath;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
loadAvailableLocales() {
|
|
217
|
+
var _a, _b;
|
|
218
|
+
if (!utils_1.fileHelper.fileExistsSync(this.localesFilePath)) {
|
|
219
|
+
cli_utilities_1.log.debug('No locales file found', this.importConfig.context);
|
|
220
|
+
return {};
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
const localesData = utils_1.fsUtil.readFile(this.localesFilePath, true);
|
|
224
|
+
const locales = {};
|
|
225
|
+
locales[(_a = this.importConfig.master_locale) === null || _a === void 0 ? void 0 : _a.code] = (_b = this.importConfig.master_locale) === null || _b === void 0 ? void 0 : _b.code;
|
|
226
|
+
for (const [code, locale] of Object.entries(localesData)) {
|
|
227
|
+
if (locale === null || locale === void 0 ? void 0 : locale.code) {
|
|
228
|
+
locales[locale.code] = code;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
cli_utilities_1.log.debug(`Loaded ${Object.keys(locales).length} locales from file`, this.importConfig.context);
|
|
232
|
+
return locales;
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
cli_utilities_1.log.debug('Error loading locales file', this.importConfig.context);
|
|
236
|
+
return {};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
145
239
|
/**
|
|
146
240
|
* create taxonomies success and fail in (mapper/taxonomies)
|
|
147
241
|
* create terms success and fail in (mapper/taxonomies/terms)
|
|
@@ -173,5 +267,21 @@ class ImportTaxonomies extends base_class_1.default {
|
|
|
173
267
|
cli_utilities_1.log.debug(`Written failed terms for ${failedTermsCount} taxonomies to file: ${this.termsFailsPath}`, this.importConfig.context);
|
|
174
268
|
}
|
|
175
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Detect if locale-based folder structure exists and scan taxonomies by locale
|
|
272
|
+
* @returns {boolean} true if locale-based structure detected, false otherwise
|
|
273
|
+
*/
|
|
274
|
+
detectAndScanLocaleStructure() {
|
|
275
|
+
var _a;
|
|
276
|
+
const masterLocaleCode = ((_a = this.importConfig.master_locale) === null || _a === void 0 ? void 0 : _a.code) || 'en-us';
|
|
277
|
+
const masterLocaleFolder = (0, node_path_1.join)(this.taxonomiesFolderPath, masterLocaleCode);
|
|
278
|
+
// Check if master locale folder exists (indicates new locale-based structure)
|
|
279
|
+
if (!utils_1.fileHelper.fileExistsSync(masterLocaleFolder)) {
|
|
280
|
+
cli_utilities_1.log.debug('No locale-based folder structure detected', this.importConfig.context);
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
cli_utilities_1.log.debug('Locale-based folder structure detected', this.importConfig.context);
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
176
286
|
}
|
|
177
287
|
exports.default = ImportTaxonomies;
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.29.0",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-audit": "~1.
|
|
8
|
+
"@contentstack/cli-audit": "~1.16.0",
|
|
9
9
|
"@contentstack/cli-command": "~1.6.1",
|
|
10
10
|
"@contentstack/cli-utilities": "~1.14.4",
|
|
11
11
|
"@contentstack/management": "~1.22.0",
|