@contentstack/cli-cm-import 2.0.0-beta.5 → 2.0.0-beta.7

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.
@@ -5,6 +5,7 @@ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
5
5
  const values_1 = tslib_1.__importDefault(require("lodash/values"));
6
6
  const node_path_1 = require("node:path");
7
7
  const cli_utilities_1 = require("@contentstack/cli-utilities");
8
+ const constants_1 = require("../../constants");
8
9
  const utils_1 = require("../../utils");
9
10
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
10
11
  class ImportEnvironments extends base_class_1.default {
@@ -13,11 +14,11 @@ class ImportEnvironments extends base_class_1.default {
13
14
  this.importConfig.context.module = utils_1.MODULE_CONTEXTS.ENVIRONMENTS;
14
15
  this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.ENVIRONMENTS];
15
16
  this.environmentsConfig = importConfig.modules.environments;
16
- this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'environments');
17
+ this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.ENVIRONMENTS);
17
18
  this.environmentsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.environmentsConfig.dirName);
18
- this.envUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
19
- this.envSuccessPath = (0, node_path_1.join)(this.mapperDirPath, 'success.json');
20
- this.envFailsPath = (0, node_path_1.join)(this.mapperDirPath, 'fails.json');
19
+ this.envUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.UID_MAPPING);
20
+ this.envSuccessPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.SUCCESS);
21
+ this.envFailsPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.FAILS);
21
22
  this.envFailed = [];
22
23
  this.envSuccess = [];
23
24
  this.envUidMapper = {};
@@ -39,8 +40,7 @@ class ImportEnvironments extends base_class_1.default {
39
40
  progress.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.ENVIRONMENTS_IMPORT].IMPORTING);
40
41
  await this.importEnvironments();
41
42
  await this.processImportResults();
42
- this.completeProgress(true);
43
- cli_utilities_1.log.success('Environments have been imported successfully!', this.importConfig.context);
43
+ this.completeProgressWithMessage();
44
44
  }
45
45
  catch (error) {
46
46
  this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Environments import failed');
@@ -6,6 +6,7 @@ const values_1 = tslib_1.__importDefault(require("lodash/values"));
6
6
  const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
7
7
  const node_path_1 = require("node:path");
8
8
  const cli_utilities_1 = require("@contentstack/cli-utilities");
9
+ const constants_1 = require("../../constants");
9
10
  const utils_1 = require("../../utils");
10
11
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
11
12
  class ImportExtensions extends base_class_1.default {
@@ -14,12 +15,12 @@ class ImportExtensions extends base_class_1.default {
14
15
  this.importConfig.context.module = utils_1.MODULE_CONTEXTS.EXTENSIONS;
15
16
  this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.EXTENSIONS];
16
17
  this.extensionsConfig = importConfig.modules.extensions;
17
- this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'extensions');
18
+ this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.EXTENSIONS);
18
19
  this.extensionsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.extensionsConfig.dirName);
19
- this.extUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
20
- this.extSuccessPath = (0, node_path_1.join)(this.mapperDirPath, 'success.json');
21
- this.extFailsPath = (0, node_path_1.join)(this.mapperDirPath, 'fails.json');
22
- this.extPendingPath = (0, node_path_1.join)(this.mapperDirPath, 'pending_extensions.js');
20
+ this.extUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.UID_MAPPING);
21
+ this.extSuccessPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.SUCCESS);
22
+ this.extFailsPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.FAILS);
23
+ this.extPendingPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.PENDING_EXTENSIONS);
23
24
  this.extFailed = [];
24
25
  this.extSuccess = [];
25
26
  this.existingExtensions = [];
@@ -60,8 +61,7 @@ class ImportExtensions extends base_class_1.default {
60
61
  progress.completeProcess(utils_1.PROCESS_NAMES.EXTENSIONS_REPLACE_EXISTING, true);
61
62
  }
62
63
  await this.processExtensionResults();
63
- this.completeProgress(true);
64
- cli_utilities_1.log.success('Extensions have been imported successfully!', this.importConfig.context);
64
+ this.completeProgressWithMessage();
65
65
  }
66
66
  catch (error) {
67
67
  this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Create failed');
@@ -10,6 +10,7 @@ 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 constants_1 = require("../../constants");
13
14
  const utils_1 = require("../../utils");
14
15
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
15
16
  const global_field_helper_1 = require("../../utils/global-field-helper");
@@ -27,13 +28,13 @@ class ImportGlobalFields extends base_class_1.default {
27
28
  this.pendingGFs = [];
28
29
  this.existingGFs = [];
29
30
  this.reqConcurrency = this.gFsConfig.writeConcurrency || this.config.writeConcurrency;
30
- this.gFsMapperPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'mapper', 'global_fields');
31
+ this.gFsMapperPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.GLOBAL_FIELDS);
31
32
  this.gFsFolderPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), (0, cli_utilities_1.sanitizePath)(this.gFsConfig.dirName));
32
- this.gFsFailsPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'mapper', 'global_fields', 'fails.json');
33
- this.gFsSuccessPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'mapper', 'global_fields', 'success.json');
34
- this.gFsUidMapperPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'mapper', 'global_fields', 'uid-mapping.json');
35
- this.gFsPendingPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'mapper', 'global_fields', 'pending_global_fields.js');
36
- this.marketplaceAppMapperPath = path.join((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'mapper', 'marketplace_apps', 'uid-mapping.json');
33
+ this.gFsFailsPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.GLOBAL_FIELDS, constants_1.PATH_CONSTANTS.FILES.FAILS);
34
+ this.gFsSuccessPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.GLOBAL_FIELDS, constants_1.PATH_CONSTANTS.FILES.SUCCESS);
35
+ this.gFsUidMapperPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.GLOBAL_FIELDS, constants_1.PATH_CONSTANTS.FILES.UID_MAPPING);
36
+ this.gFsPendingPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.GLOBAL_FIELDS, constants_1.PATH_CONSTANTS.FILES.PENDING_GLOBAL_FIELDS);
37
+ this.marketplaceAppMapperPath = path.join((0, cli_utilities_1.sanitizePath)(this.config.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.MARKETPLACE_APPS, constants_1.PATH_CONSTANTS.FILES.UID_MAPPING);
37
38
  }
38
39
  /**
39
40
  * @method start
@@ -76,8 +77,7 @@ class ImportGlobalFields extends base_class_1.default {
76
77
  progress.completeProcess(utils_1.PROCESS_NAMES.GLOBAL_FIELDS_REPLACE_EXISTING, true);
77
78
  }
78
79
  await this.processGlobalFieldResults();
79
- this.completeProgress(true);
80
- cli_utilities_1.log.success('Global fields import has been completed!', this.importConfig.context);
80
+ this.completeProgressWithMessage();
81
81
  }
82
82
  catch (error) {
83
83
  this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Global fields import failed');
@@ -6,6 +6,7 @@ const node_path_1 = require("node:path");
6
6
  const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
7
7
  const values_1 = tslib_1.__importDefault(require("lodash/values"));
8
8
  const cli_utilities_1 = require("@contentstack/cli-utilities");
9
+ const constants_1 = require("../../constants");
9
10
  const utils_1 = require("../../utils");
10
11
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
11
12
  class ImportLabels extends base_class_1.default {
@@ -14,11 +15,11 @@ class ImportLabels extends base_class_1.default {
14
15
  this.importConfig.context.module = utils_1.MODULE_CONTEXTS.LABELS;
15
16
  this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.LABELS];
16
17
  this.labelsConfig = importConfig.modules.labels;
17
- this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'labels');
18
+ this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.LABELS);
18
19
  this.labelsFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.labelsConfig.dirName);
19
- this.labelUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
20
- this.createdLabelPath = (0, node_path_1.join)(this.mapperDirPath, 'success.json');
21
- this.labelFailsPath = (0, node_path_1.join)(this.mapperDirPath, 'fails.json');
20
+ this.labelUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.UID_MAPPING);
21
+ this.createdLabelPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.SUCCESS);
22
+ this.labelFailsPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.FAILS);
22
23
  this.labels = {};
23
24
  this.failedLabel = [];
24
25
  this.createdLabel = [];
@@ -55,8 +56,7 @@ class ImportLabels extends base_class_1.default {
55
56
  await this.updateLabels();
56
57
  progress.completeProcess(utils_1.PROCESS_NAMES.LABELS_UPDATE, true);
57
58
  this.processLabelResults();
58
- this.completeProgress(true);
59
- cli_utilities_1.log.success('Labels have been imported successfully!', this.importConfig.context);
59
+ this.completeProgressWithMessage();
60
60
  }
61
61
  catch (error) {
62
62
  this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Labels import failed');
@@ -10,6 +10,7 @@ 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 constants_1 = require("../../constants");
13
14
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
14
15
  const utils_1 = require("../../utils");
15
16
  class ImportLocales extends base_class_1.default {
@@ -27,11 +28,11 @@ class ImportLocales extends base_class_1.default {
27
28
  this.createdLocales = [];
28
29
  this.failedLocales = [];
29
30
  this.reqConcurrency = this.localeConfig.writeConcurrency || this.config.writeConcurrency;
30
- this.langMapperPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'mapper', 'languages');
31
+ this.langMapperPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.LANGUAGES);
31
32
  this.langFolderPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), (0, cli_utilities_1.sanitizePath)(this.localeConfig.dirName));
32
- this.langFailsPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'mapper', 'languages', 'fails.json');
33
- this.langSuccessPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'mapper', 'languages', 'success.json');
34
- this.langUidMapperPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'mapper', 'languages', 'uid-mapper.json');
33
+ this.langFailsPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.LANGUAGES, constants_1.PATH_CONSTANTS.FILES.FAILS);
34
+ this.langSuccessPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.LANGUAGES, constants_1.PATH_CONSTANTS.FILES.SUCCESS);
35
+ this.langUidMapperPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.config.backupDir), constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.LANGUAGES, constants_1.PATH_CONSTANTS.FILES.UID_MAPPER);
35
36
  }
36
37
  async start() {
37
38
  try {
@@ -49,8 +50,7 @@ class ImportLocales extends base_class_1.default {
49
50
  cli_utilities_1.log.debug('Writing failed locales to file', this.config.context);
50
51
  utils_1.fsUtil.writeFile(this.langFailsPath, this.failedLocales);
51
52
  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);
53
+ this.completeProgressWithMessage({ context: this.config.context });
54
54
  }
55
55
  catch (error) {
56
56
  this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Locales import failed');
@@ -13,6 +13,7 @@ const filter_1 = tslib_1.__importDefault(require("lodash/filter"));
13
13
  const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
14
14
  const toLower_1 = tslib_1.__importDefault(require("lodash/toLower"));
15
15
  const cli_utilities_1 = require("@contentstack/cli-utilities");
16
+ const constants_1 = require("../../constants");
16
17
  const interactive_1 = require("../../utils/interactive");
17
18
  const utils_1 = require("../../utils");
18
19
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
@@ -22,9 +23,9 @@ class ImportMarketplaceApps extends base_class_1.default {
22
23
  this.importConfig.context.module = utils_1.MODULE_CONTEXTS.MARKETPLACE_APPS;
23
24
  this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.MARKETPLACE_APPS];
24
25
  this.marketPlaceAppConfig = importConfig.modules.marketplace_apps;
25
- this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'marketplace_apps');
26
+ this.mapperDirPath = (0, node_path_1.join)(this.importConfig.backupDir, constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.MARKETPLACE_APPS);
26
27
  this.marketPlaceFolderPath = (0, node_path_1.join)(this.importConfig.backupDir, this.marketPlaceAppConfig.dirName);
27
- this.marketPlaceUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, 'uid-mapping.json');
28
+ this.marketPlaceUidMapperPath = (0, node_path_1.join)(this.mapperDirPath, constants_1.PATH_CONSTANTS.FILES.UID_MAPPING);
28
29
  this.appNameMapping = {};
29
30
  this.appUidMapping = {};
30
31
  this.appOriginalName = undefined;
@@ -85,8 +86,7 @@ class ImportMarketplaceApps extends base_class_1.default {
85
86
  .updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.INSTALL_APPS].INSTALLING, utils_1.PROCESS_NAMES.INSTALL_APPS);
86
87
  await this.importMarketplaceApps();
87
88
  progress.completeProcess(utils_1.PROCESS_NAMES.INSTALL_APPS, true);
88
- this.completeProgress(true);
89
- cli_utilities_1.log.success('Marketplace apps have been imported successfully!', this.importConfig.context);
89
+ this.completeProgressWithMessage();
90
90
  }
91
91
  catch (error) {
92
92
  this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Marketplace apps import failed');
@@ -46,8 +46,7 @@ class ImportPersonalize extends base_class_1.default {
46
46
  else {
47
47
  cli_utilities_1.log.debug('No personalize modules configured for processing', this.config.context);
48
48
  }
49
- this.completeProgress(true);
50
- cli_utilities_1.log.success('Personalize import completed successfully', this.config.context);
49
+ this.completeProgressWithMessage();
51
50
  }
52
51
  catch (error) {
53
52
  this.personalizeConfig.importData = false; // Stop personalize import if project creation fails
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const node_path_1 = require("node:path");
5
5
  const cli_utilities_1 = require("@contentstack/cli-utilities");
6
+ const constants_1 = require("../../constants");
6
7
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
7
8
  const utils_1 = require("../../utils");
8
9
  class ImportStack extends base_class_1.default {
@@ -12,8 +13,8 @@ class ImportStack extends base_class_1.default {
12
13
  this.envUidMapper = {};
13
14
  this.importConfig.context.module = utils_1.MODULE_CONTEXTS.STACK;
14
15
  this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.STACK];
15
- this.stackSettingsPath = (0, node_path_1.join)(this.importConfig.backupDir, 'stack', 'settings.json');
16
- this.envUidMapperPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'environments', 'uid-mapping.json');
16
+ this.stackSettingsPath = (0, node_path_1.join)(this.importConfig.backupDir, constants_1.PATH_CONSTANTS.CONTENT_DIRS.STACK, constants_1.PATH_CONSTANTS.FILES.SETTINGS);
17
+ this.envUidMapperPath = (0, node_path_1.join)(this.importConfig.backupDir, constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.ENVIRONMENTS, constants_1.PATH_CONSTANTS.FILES.UID_MAPPING);
17
18
  }
18
19
  /**
19
20
  * @method start
@@ -35,8 +36,7 @@ class ImportStack extends base_class_1.default {
35
36
  progress.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.STACK_IMPORT].IMPORTING);
36
37
  cli_utilities_1.log.info('Starting stack settings import process', this.importConfig.context);
37
38
  await this.importStackSettings();
38
- this.completeProgress(true);
39
- cli_utilities_1.log.success('Stack settings imported successfully!', this.importConfig.context);
39
+ this.completeProgressWithMessage();
40
40
  }
41
41
  catch (error) {
42
42
  this.completeProgress(false, 'Stack settings import failed');
@@ -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,13 +28,34 @@ export default class ImportTaxonomies extends BaseClass {
26
28
  * @async
27
29
  * @returns {Promise<any>} Promise<any>
28
30
  */
29
- importTaxonomies(): Promise<any>;
31
+ importTaxonomies({ apiContent, localeCode }: {
32
+ apiContent: any[];
33
+ localeCode?: string;
34
+ }): Promise<void>;
30
35
  /**
31
- * @method serializeTaxonomiesData
36
+ * Import taxonomies using legacy structure (taxonomies/{uid}.json)
37
+ */
38
+ importTaxonomiesLegacy(): Promise<void>;
39
+ /**
40
+ * Import taxonomies using locale-based structure (taxonomies/{locale}/{uid}.json)
41
+ */
42
+ importTaxonomiesByLocale(): Promise<void>;
43
+ handleSuccess(apiData: any, locale?: string): void;
44
+ handleFailure(error: any, apiData: any, locale?: string): void;
45
+ /**
46
+ * @method serializeTaxonomy
32
47
  * @param {ApiOptions} apiOptions ApiOptions
33
48
  * @returns {ApiOptions} ApiOptions
34
49
  */
35
- serializeTaxonomiesData(apiOptions: ApiOptions): ApiOptions;
50
+ serializeTaxonomy(apiOptions: ApiOptions): ApiOptions;
51
+ loadTaxonomyFile(filePath: string): Record<string, unknown> | undefined;
52
+ findTaxonomyFilePath(taxonomyUID: string): string | undefined;
53
+ findTaxonomyInLocaleFolders(taxonomyUID: string): string | undefined;
54
+ loadAvailableLocales(): Record<string, string>;
55
+ /**
56
+ * Detect if locale-based folder structure exists (taxonomies/{locale}/{uid}.json)
57
+ */
58
+ detectAndScanLocaleStructure(): boolean;
36
59
  /**
37
60
  * create taxonomies success and fail in (mapper/taxonomies)
38
61
  * create terms success and fail in (mapper/taxonomies/terms)
@@ -5,11 +5,13 @@ const node_path_1 = require("node:path");
5
5
  const values_1 = tslib_1.__importDefault(require("lodash/values"));
6
6
  const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
7
7
  const cli_utilities_1 = require("@contentstack/cli-utilities");
8
+ const constants_1 = require("../../constants");
8
9
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
9
10
  const utils_1 = require("../../utils");
10
11
  class ImportTaxonomies extends base_class_1.default {
11
12
  constructor({ importConfig, stackAPIClient }) {
12
13
  super({ importConfig, stackAPIClient });
14
+ this.isLocaleBasedStructure = false;
13
15
  this.createdTaxonomies = {};
14
16
  this.failedTaxonomies = {};
15
17
  this.createdTerms = {};
@@ -17,13 +19,14 @@ class ImportTaxonomies extends base_class_1.default {
17
19
  this.importConfig.context.module = utils_1.MODULE_CONTEXTS.TAXONOMIES;
18
20
  this.currentModuleName = utils_1.MODULE_NAMES[utils_1.MODULE_CONTEXTS.TAXONOMIES];
19
21
  this.taxonomiesConfig = importConfig.modules.taxonomies;
20
- this.taxonomiesMapperDirPath = (0, node_path_1.join)(importConfig.backupDir, 'mapper', 'taxonomies');
21
- this.termsMapperDirPath = (0, node_path_1.join)(this.taxonomiesMapperDirPath, 'terms');
22
- this.taxonomiesFolderPath = (0, node_path_1.join)(importConfig.backupDir, this.taxonomiesConfig.dirName);
23
- this.taxSuccessPath = (0, node_path_1.join)(this.taxonomiesMapperDirPath, 'success.json');
24
- this.taxFailsPath = (0, node_path_1.join)(this.taxonomiesMapperDirPath, 'fails.json');
25
- this.termsSuccessPath = (0, node_path_1.join)(this.termsMapperDirPath, 'success.json');
26
- this.termsFailsPath = (0, node_path_1.join)(this.termsMapperDirPath, 'fails.json');
22
+ this.taxonomiesMapperDirPath = (0, node_path_1.join)(importConfig.backupDir, constants_1.PATH_CONSTANTS.MAPPER, constants_1.PATH_CONSTANTS.MAPPER_MODULES.TAXONOMIES);
23
+ this.termsMapperDirPath = (0, node_path_1.join)(this.taxonomiesMapperDirPath, constants_1.PATH_CONSTANTS.MAPPER_MODULES.TAXONOMY_TERMS);
24
+ this.taxonomiesFolderPath = (0, node_path_1.join)(importConfig.contentDir, this.taxonomiesConfig.dirName);
25
+ this.taxSuccessPath = (0, node_path_1.join)(this.taxonomiesMapperDirPath, constants_1.PATH_CONSTANTS.FILES.SUCCESS);
26
+ this.taxFailsPath = (0, node_path_1.join)(this.taxonomiesMapperDirPath, constants_1.PATH_CONSTANTS.FILES.FAILS);
27
+ this.termsSuccessPath = (0, node_path_1.join)(this.termsMapperDirPath, constants_1.PATH_CONSTANTS.FILES.SUCCESS);
28
+ this.termsFailsPath = (0, node_path_1.join)(this.termsMapperDirPath, constants_1.PATH_CONSTANTS.FILES.FAILS);
29
+ this.localesFilePath = (0, node_path_1.join)(importConfig.backupDir, importConfig.modules.locales.dirName, importConfig.modules.locales.fileName);
27
30
  }
28
31
  /**
29
32
  * @method start
@@ -37,14 +40,22 @@ class ImportTaxonomies extends base_class_1.default {
37
40
  cli_utilities_1.log.info('No taxonomies found to import', this.importConfig.context);
38
41
  return;
39
42
  }
40
- const progress = this.createSimpleProgress(this.currentModuleName, taxonomiesCount);
41
43
  await this.prepareMapperDirectories();
44
+ // Check if locale-based structure exists before import
45
+ this.isLocaleBasedStructure = this.detectAndScanLocaleStructure();
46
+ const progress = this.createSimpleProgress(this.currentModuleName, taxonomiesCount);
42
47
  progress.updateStatus(utils_1.PROCESS_STATUS[utils_1.PROCESS_NAMES.TAXONOMIES_IMPORT].IMPORTING);
43
48
  cli_utilities_1.log.debug('Starting taxonomies import', this.importConfig.context);
44
- await this.importTaxonomies();
49
+ if (this.isLocaleBasedStructure) {
50
+ cli_utilities_1.log.debug('Detected locale-based folder structure for taxonomies', this.importConfig.context);
51
+ await this.importTaxonomiesByLocale();
52
+ }
53
+ else {
54
+ cli_utilities_1.log.debug('Using legacy folder structure for taxonomies', this.importConfig.context);
55
+ await this.importTaxonomiesLegacy();
56
+ }
45
57
  this.createSuccessAndFailedFile();
46
- this.completeProgress(true);
47
- cli_utilities_1.log.success('Taxonomies imported successfully!', this.importConfig.context);
58
+ this.completeProgressWithMessage();
48
59
  }
49
60
  catch (error) {
50
61
  this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Taxonomies import failed');
@@ -57,83 +68,189 @@ class ImportTaxonomies extends base_class_1.default {
57
68
  * @async
58
69
  * @returns {Promise<any>} Promise<any>
59
70
  */
60
- async importTaxonomies() {
61
- cli_utilities_1.log.debug('Validating taxonomies data', this.importConfig.context);
62
- if (this.taxonomies === undefined || (0, isEmpty_1.default)(this.taxonomies)) {
63
- cli_utilities_1.log.info('No Taxonomies Found!', this.importConfig.context);
71
+ async importTaxonomies({ apiContent, localeCode }) {
72
+ if (!apiContent || (apiContent === null || apiContent === void 0 ? void 0 : apiContent.length) === 0) {
73
+ cli_utilities_1.log.debug('No taxonomies to import', this.importConfig.context);
64
74
  return;
65
75
  }
66
- const apiContent = (0, values_1.default)(this.taxonomies);
67
- cli_utilities_1.log.debug(`Starting to import ${apiContent.length} taxonomies`, this.importConfig.context);
68
- const onSuccess = ({ apiData }) => {
69
- var _a, _b, _c;
70
- const taxonomyUID = (_a = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _a === void 0 ? void 0 : _a.uid;
71
- const taxonomyName = (_b = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _b === void 0 ? void 0 : _b.name;
72
- const termsCount = Object.keys((apiData === null || apiData === void 0 ? void 0 : apiData.terms) || {}).length;
73
- this.createdTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
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);
76
- cli_utilities_1.log.success(`Taxonomy '${taxonomyUID}' imported successfully!`, this.importConfig.context);
77
- cli_utilities_1.log.debug(`Taxonomy '${taxonomyName}' imported with ${termsCount} terms successfully!`, this.importConfig.context);
78
- };
79
- const onReject = ({ error, apiData }) => {
80
- var _a, _b, _c, _d;
81
- const taxonomyUID = (_a = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _a === void 0 ? void 0 : _a.uid;
82
- const taxonomyName = (_b = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _b === void 0 ? void 0 : _b.name;
83
- if ((error === null || error === void 0 ? void 0 : error.status) === 409 && (error === null || error === void 0 ? void 0 : error.statusText) === 'Conflict') {
84
- cli_utilities_1.log.info(`Taxonomy '${taxonomyUID}' already exists!`, this.importConfig.context);
85
- cli_utilities_1.log.debug(`Adding existing taxonomy '${taxonomyUID}' to created list`, this.importConfig.context);
86
- this.createdTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
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);
89
- }
90
- else {
91
- this.failedTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
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`);
95
- }
96
- };
97
- cli_utilities_1.log.debug(`Using concurrency limit: ${this.importConfig.fetchConcurrency || 2}`, this.importConfig.context);
76
+ const onSuccess = ({ apiData }) => this.handleSuccess(apiData, localeCode);
77
+ const onReject = ({ error, apiData }) => this.handleFailure(error, apiData, localeCode);
98
78
  await this.makeConcurrentCall({
99
79
  apiContent,
100
80
  processName: 'import taxonomies',
101
81
  apiParams: {
102
- serializeData: this.serializeTaxonomiesData.bind(this),
82
+ serializeData: this.serializeTaxonomy.bind(this),
103
83
  reject: onReject,
104
84
  resolve: onSuccess,
105
85
  entity: 'import-taxonomy',
106
86
  includeParamOnCompletion: true,
87
+ queryParam: {
88
+ locale: localeCode,
89
+ },
107
90
  },
108
91
  concurrencyLimit: this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1,
109
92
  }, undefined, false);
110
- cli_utilities_1.log.debug('Taxonomies import process completed', this.importConfig.context);
111
93
  }
112
94
  /**
113
- * @method serializeTaxonomiesData
95
+ * Import taxonomies using legacy structure (taxonomies/{uid}.json)
96
+ */
97
+ async importTaxonomiesLegacy() {
98
+ const apiContent = (0, values_1.default)(this.taxonomies);
99
+ await this.importTaxonomies({ apiContent });
100
+ }
101
+ /**
102
+ * Import taxonomies using locale-based structure (taxonomies/{locale}/{uid}.json)
103
+ */
104
+ async importTaxonomiesByLocale() {
105
+ const locales = this.loadAvailableLocales();
106
+ const apiContent = (0, values_1.default)(this.taxonomies);
107
+ for (const localeCode of Object.keys(locales)) {
108
+ await this.importTaxonomies({ apiContent, localeCode });
109
+ }
110
+ }
111
+ handleSuccess(apiData, locale) {
112
+ var _a;
113
+ const { taxonomy, terms } = apiData || {};
114
+ const taxonomyUID = taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.uid;
115
+ const taxonomyName = taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.name;
116
+ const termsCount = Object.keys(terms || {}).length;
117
+ this.createdTaxonomies[taxonomyUID] = taxonomy;
118
+ this.createdTerms[taxonomyUID] = terms;
119
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `taxonomy: ${taxonomyName || taxonomyUID}`, null, utils_1.PROCESS_NAMES.TAXONOMIES_IMPORT);
120
+ cli_utilities_1.log.success(`Taxonomy '${taxonomyUID}' imported successfully${locale ? ` for locale: ${locale}` : ''}!`, this.importConfig.context);
121
+ cli_utilities_1.log.debug(`Created taxonomy '${taxonomyName}' with ${termsCount} terms${locale ? ` for locale: ${locale}` : ''}`, this.importConfig.context);
122
+ }
123
+ handleFailure(error, apiData, locale) {
124
+ var _a, _b, _c, _d, _e, _f;
125
+ const taxonomyUID = (_a = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _a === void 0 ? void 0 : _a.uid;
126
+ const taxonomyName = (_b = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy) === null || _b === void 0 ? void 0 : _b.name;
127
+ if ((error === null || error === void 0 ? void 0 : error.status) === 409 && (error === null || error === void 0 ? void 0 : error.statusText) === 'Conflict') {
128
+ (_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(true, null, `taxonomy: ${taxonomyName || taxonomyUID} (already exists)`, utils_1.PROCESS_NAMES.TAXONOMIES_IMPORT);
129
+ cli_utilities_1.log.info(`Taxonomy '${taxonomyUID}' already exists ${locale ? ` for locale: ${locale}` : ''}!`, this.importConfig.context);
130
+ this.createdTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
131
+ this.createdTerms[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.terms;
132
+ return;
133
+ }
134
+ const errMsg = (error === null || error === void 0 ? void 0 : error.errorMessage) || ((_d = error === null || error === void 0 ? void 0 : error.errors) === null || _d === void 0 ? void 0 : _d.taxonomy) || ((_e = error === null || error === void 0 ? void 0 : error.errors) === null || _e === void 0 ? void 0 : _e.term) || (error === null || error === void 0 ? void 0 : error.message);
135
+ (_f = this.progressManager) === null || _f === void 0 ? void 0 : _f.tick(false, `taxonomy: ${taxonomyName || taxonomyUID}`, errMsg || 'Failed to import taxonomy', utils_1.PROCESS_NAMES.TAXONOMIES_IMPORT);
136
+ if (errMsg) {
137
+ cli_utilities_1.log.error(`Taxonomy '${taxonomyUID}' failed to import${locale ? ` for locale: ${locale}` : ''}! ${errMsg}`, this.importConfig.context);
138
+ }
139
+ else {
140
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { taxonomyUID, locale }), `Taxonomy '${taxonomyUID}' failed`);
141
+ }
142
+ this.failedTaxonomies[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.taxonomy;
143
+ this.failedTerms[taxonomyUID] = apiData === null || apiData === void 0 ? void 0 : apiData.terms;
144
+ }
145
+ /**
146
+ * @method serializeTaxonomy
114
147
  * @param {ApiOptions} apiOptions ApiOptions
115
148
  * @returns {ApiOptions} ApiOptions
116
149
  */
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;
122
- const filePath = (0, node_path_1.join)(this.taxonomiesFolderPath, `${taxonomyUID}.json`);
123
- cli_utilities_1.log.debug(`Looking for taxonomy file: ${filePath}`, this.importConfig.context);
124
- if (utils_1.fileHelper.fileExistsSync(filePath)) {
125
- const taxonomyDetails = utils_1.fsUtil.readFile(filePath, true);
126
- cli_utilities_1.log.debug(`Successfully loaded taxonomy details from ${filePath}`, this.importConfig.context);
150
+ serializeTaxonomy(apiOptions) {
151
+ const { apiData, queryParam: { locale }, } = apiOptions;
152
+ const taxonomyUID = apiData === null || apiData === void 0 ? void 0 : apiData.uid;
153
+ if (!taxonomyUID) {
154
+ cli_utilities_1.log.debug('No taxonomy UID provided for serialization', this.importConfig.context);
155
+ apiOptions.apiData = undefined;
156
+ return apiOptions;
157
+ }
158
+ const context = locale ? ` for locale: ${locale}` : '';
159
+ cli_utilities_1.log.debug(`Serializing taxonomy: ${taxonomyUID}${context}`, this.importConfig.context);
160
+ // Determine file path - if locale is provided, use it directly, otherwise search
161
+ const filePath = locale
162
+ ? (0, node_path_1.join)(this.taxonomiesFolderPath, locale, `${taxonomyUID}.json`)
163
+ : this.findTaxonomyFilePath(taxonomyUID);
164
+ if (!filePath || !utils_1.fileHelper.fileExistsSync(filePath)) {
165
+ cli_utilities_1.log.debug(`Taxonomy file not found for: ${taxonomyUID}${context}`, this.importConfig.context);
166
+ apiOptions.apiData = undefined;
167
+ return apiOptions;
168
+ }
169
+ const taxonomyDetails = this.loadTaxonomyFile(filePath);
170
+ if (taxonomyDetails) {
127
171
  const termCount = Object.keys((taxonomyDetails === null || taxonomyDetails === void 0 ? void 0 : taxonomyDetails.terms) || {}).length;
128
- cli_utilities_1.log.debug(`Taxonomy has ${termCount} term entries`, this.importConfig.context);
129
- apiOptions.apiData = { filePath, taxonomy: taxonomyDetails === null || taxonomyDetails === void 0 ? void 0 : taxonomyDetails.taxonomy, terms: taxonomyDetails === null || taxonomyDetails === void 0 ? void 0 : taxonomyDetails.terms };
172
+ cli_utilities_1.log.debug(`Taxonomy has ${termCount} term entries${context}`, this.importConfig.context);
173
+ apiOptions.apiData = {
174
+ filePath,
175
+ taxonomy: taxonomyDetails === null || taxonomyDetails === void 0 ? void 0 : taxonomyDetails.taxonomy,
176
+ terms: taxonomyDetails === null || taxonomyDetails === void 0 ? void 0 : taxonomyDetails.terms,
177
+ };
130
178
  }
131
179
  else {
132
- cli_utilities_1.log.debug(`File does not exist for taxonomy: ${taxonomyUID}`, this.importConfig.context);
133
180
  apiOptions.apiData = undefined;
134
181
  }
135
182
  return apiOptions;
136
183
  }
184
+ loadTaxonomyFile(filePath) {
185
+ if (!utils_1.fileHelper.fileExistsSync(filePath)) {
186
+ cli_utilities_1.log.debug(`File does not exist: ${filePath}`, this.importConfig.context);
187
+ return undefined;
188
+ }
189
+ try {
190
+ const taxonomyDetails = utils_1.fsUtil.readFile(filePath, true);
191
+ cli_utilities_1.log.debug(`Successfully loaded taxonomy from: ${filePath}`, this.importConfig.context);
192
+ return taxonomyDetails;
193
+ }
194
+ catch (error) {
195
+ cli_utilities_1.log.debug(`Error loading taxonomy file: ${filePath}`, this.importConfig.context);
196
+ return undefined;
197
+ }
198
+ }
199
+ findTaxonomyFilePath(taxonomyUID) {
200
+ if (this.isLocaleBasedStructure) {
201
+ return this.findTaxonomyInLocaleFolders(taxonomyUID);
202
+ }
203
+ const legacyPath = (0, node_path_1.join)(this.taxonomiesFolderPath, `${taxonomyUID}.json`);
204
+ return utils_1.fileHelper.fileExistsSync(legacyPath) ? legacyPath : undefined;
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;
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
+ const masterCode = ((_a = this.importConfig.master_locale) === null || _a === void 0 ? void 0 : _a.code) || 'en-us';
226
+ locales[masterCode] = masterCode;
227
+ for (const [, locale] of Object.entries(localesData || {})) {
228
+ if (locale === null || locale === void 0 ? void 0 : locale.code) {
229
+ locales[locale.code] = locale.code;
230
+ }
231
+ }
232
+ cli_utilities_1.log.debug(`Loaded ${Object.keys(locales).length} locales from file`, this.importConfig.context);
233
+ return locales;
234
+ }
235
+ catch (error) {
236
+ cli_utilities_1.log.debug('Error loading locales file', this.importConfig.context);
237
+ return {};
238
+ }
239
+ }
240
+ /**
241
+ * Detect if locale-based folder structure exists (taxonomies/{locale}/{uid}.json)
242
+ */
243
+ detectAndScanLocaleStructure() {
244
+ var _a;
245
+ const masterLocaleCode = ((_a = this.importConfig.master_locale) === null || _a === void 0 ? void 0 : _a.code) || 'en-us';
246
+ const masterLocaleFolder = (0, node_path_1.join)(this.taxonomiesFolderPath, masterLocaleCode);
247
+ if (!utils_1.fileHelper.fileExistsSync(masterLocaleFolder)) {
248
+ cli_utilities_1.log.debug('No locale-based folder structure detected', this.importConfig.context);
249
+ return false;
250
+ }
251
+ cli_utilities_1.log.debug('Locale-based folder structure detected', this.importConfig.context);
252
+ return true;
253
+ }
137
254
  /**
138
255
  * create taxonomies success and fail in (mapper/taxonomies)
139
256
  * create terms success and fail in (mapper/taxonomies/terms)