@contentstack/cli-cm-import-setup 1.7.0 → 1.7.2

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Contentstack
3
+ Copyright (c) 2026 Contentstack
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import-setup
47
47
  $ csdx COMMAND
48
48
  running command...
49
49
  $ csdx (--version)
50
- @contentstack/cli-cm-import-setup/1.7.0 linux-x64 node-v22.21.1
50
+ @contentstack/cli-cm-import-setup/1.7.2 linux-x64 node-v22.21.1
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -8,9 +8,13 @@ const utils_1 = require("../../../utils");
8
8
  const import_1 = require("../../../import");
9
9
  class ImportSetupCommand extends cli_command_1.Command {
10
10
  async run() {
11
+ var _a, _b;
11
12
  try {
12
13
  const { flags } = await this.parse(ImportSetupCommand);
13
14
  let importSetupConfig = await (0, utils_1.setupImportConfig)(flags);
15
+ // Prepare the context object
16
+ (0, cli_utilities_1.createLogContext)(((_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.command) || 'cm:stacks:import-setup', importSetupConfig.apiKey, cli_utilities_1.configHandler.get('authenticationMethod'));
17
+ importSetupConfig.context = { module: '' };
14
18
  // Note setting host to create cma client
15
19
  importSetupConfig.host = this.cmaHost;
16
20
  importSetupConfig.region = this.region;
@@ -18,11 +22,11 @@ class ImportSetupCommand extends cli_command_1.Command {
18
22
  const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(importSetupConfig);
19
23
  const importSetup = new import_1.ImportSetup(importSetupConfig, managementAPIClient);
20
24
  await importSetup.start();
21
- (0, utils_1.log)(importSetupConfig, `Backup folder and mapper files have been successfully created for the stack using the API key ${importSetupConfig.apiKey}.`, 'success');
22
- (0, utils_1.log)(importSetupConfig, `The backup folder has been created at '${(0, cli_utilities_1.pathValidator)(node_path_1.default.join(importSetupConfig.backupDir))}'.`, 'success');
25
+ cli_utilities_1.log.success(`Backup folder and mapper files have been successfully created for the stack using the API key ${importSetupConfig.apiKey}.`, importSetupConfig.context);
26
+ cli_utilities_1.log.success(`The backup folder has been created at '${(0, cli_utilities_1.pathValidator)(node_path_1.default.join(importSetupConfig.backupDir))}'.`, importSetupConfig.context);
23
27
  }
24
28
  catch (error) {
25
- (0, utils_1.log)({ data: '' }, `Failed to create the backup folder and mapper files: ${(0, cli_utilities_1.formatError)(error)}`, 'error');
29
+ (0, cli_utilities_1.handleAndLogError)(error);
26
30
  }
27
31
  }
28
32
  }
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const utils_1 = require("../utils");
27
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
27
28
  class ImportSetup {
28
29
  constructor(config, managementAPIClient) {
29
30
  this.dependencyTree = {};
@@ -71,8 +72,10 @@ class ImportSetup {
71
72
  */
72
73
  async runModuleImports() {
73
74
  var _a;
75
+ cli_utilities_1.log.debug('Starting module imports', { modules: Object.keys(this.dependencyTree) });
74
76
  for (const moduleName in this.dependencyTree) {
75
77
  try {
78
+ cli_utilities_1.log.debug(`Importing module: ${moduleName}`, { moduleName, dependencies: this.dependencyTree[moduleName] });
76
79
  const modulePath = `./modules/${moduleName}`;
77
80
  const { default: ModuleClass } = await (_a = modulePath, Promise.resolve().then(() => __importStar(require(_a))));
78
81
  const modulePayload = {
@@ -82,12 +85,14 @@ class ImportSetup {
82
85
  };
83
86
  const moduleInstance = new ModuleClass(modulePayload);
84
87
  await moduleInstance.start();
88
+ cli_utilities_1.log.debug(`Module ${moduleName} imported successfully`);
85
89
  }
86
90
  catch (error) {
87
- (0, utils_1.log)(this.config, `Error occurred while importing '${moduleName}'`, 'error');
91
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.config.context), { moduleName }), `Error occurred while importing '${moduleName}'`);
88
92
  throw error;
89
93
  }
90
94
  }
95
+ cli_utilities_1.log.debug('All module imports completed');
91
96
  }
92
97
  /**
93
98
  * Start the import setup process
@@ -102,16 +107,21 @@ class ImportSetup {
102
107
  this.config.stackName = stackDetails.name;
103
108
  this.config.org_uid = stackDetails.org_uid;
104
109
  }
110
+ cli_utilities_1.log.debug('Creating backup directory');
105
111
  const backupDir = await (0, utils_1.backupHandler)(this.config);
106
112
  if (backupDir) {
107
113
  this.config.backupDir = backupDir;
114
+ cli_utilities_1.log.debug('Backup directory created', { backupDir });
108
115
  }
116
+ cli_utilities_1.log.debug('Setting up branch configuration');
109
117
  await (0, utils_1.setupBranchConfig)(this.config, this.stackAPIClient);
118
+ cli_utilities_1.log.debug('Branch configuration completed', { branchName: this.config.branchName });
110
119
  await this.generateDependencyTree();
111
120
  await this.runModuleImports();
121
+ cli_utilities_1.log.debug('Import setup process completed successfully');
112
122
  }
113
123
  catch (error) {
114
- console.log(error);
124
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), 'Import setup failed');
115
125
  throw error;
116
126
  }
117
127
  }
@@ -9,6 +9,7 @@ const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
9
9
  class AssetImportSetup extends base_setup_1.default {
10
10
  constructor({ config, stackAPIClient, dependencies }) {
11
11
  super({ config, stackAPIClient, dependencies });
12
+ this.initializeContext('assets');
12
13
  this.assetsFolderPath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'assets');
13
14
  this.assetsFilePath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'assets', 'assets.json');
14
15
  this.assetsConfig = config.modules.assets;
@@ -28,11 +29,16 @@ class AssetImportSetup extends base_setup_1.default {
28
29
  async start() {
29
30
  try {
30
31
  utils_1.fsUtil.makeDirectory(this.mapperDirPath);
32
+ cli_utilities_1.log.debug('Mapper directory created', { mapperDirPath: this.mapperDirPath });
31
33
  await this.fetchAndMapAssets();
32
- (0, utils_1.log)(this.config, `The required setup files for the asset have been generated successfully.`, 'success');
34
+ cli_utilities_1.log.debug('Asset mapping completed', {
35
+ mappedCount: Object.keys(this.assetUidMapper).length,
36
+ duplicateCount: Object.keys(this.duplicateAssets).length
37
+ });
38
+ cli_utilities_1.log.success(`The required setup files for the asset have been generated successfully.`);
33
39
  }
34
40
  catch (error) {
35
- (0, utils_1.log)(this.config, `Error occurred while generating the asset mapper: ${(0, cli_utilities_1.formatError)(error)}.`, 'error');
41
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), 'Error occurred while generating the asset mapper');
36
42
  }
37
43
  }
38
44
  /**
@@ -41,6 +47,7 @@ class AssetImportSetup extends base_setup_1.default {
41
47
  * @returns {Promise<void>} Promise<void>
42
48
  */
43
49
  async fetchAndMapAssets() {
50
+ cli_utilities_1.log.debug('Starting asset fetch and mapping', { assetsFolderPath: this.assetsFolderPath });
44
51
  const processName = 'mapping assets';
45
52
  const indexFileName = 'assets.json';
46
53
  const basePath = this.assetsFolderPath;
@@ -51,26 +58,25 @@ class AssetImportSetup extends base_setup_1.default {
51
58
  if (items.length === 1) {
52
59
  this.assetUidMapper[uid] = items[0].uid;
53
60
  this.assetUrlMapper[url] = items[0].url;
54
- (0, utils_1.log)(this.config, `Mapped asset successfully: '${title}'`, 'info');
61
+ cli_utilities_1.log.info(`Mapped asset successfully: '${title}'`);
55
62
  }
56
63
  else if (items.length > 1) {
57
64
  this.duplicateAssets[uid] = items.map((asset) => {
58
65
  return { uid: asset.uid, title: asset.title, url: asset.url };
59
66
  });
60
- (0, utils_1.log)(this.config, `Multiple assets found with the title '${title}'.`, 'info');
67
+ cli_utilities_1.log.info(`Multiple assets found with the title '${title}'.`);
61
68
  }
62
69
  else {
63
- (0, utils_1.log)(this.config, `Asset with title '${title}' not found in the stack!`, 'info');
70
+ cli_utilities_1.log.info(`Asset with title '${title}' not found in the stack!`);
64
71
  }
65
72
  };
66
73
  const onReject = ({ error, apiData: { title } = undefined }) => {
67
- (0, utils_1.log)(this.config, `Failed to map the asset '${title}'.`, 'error');
68
- (0, utils_1.log)(this.config, (0, cli_utilities_1.formatError)(error), 'error');
74
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), `Failed to map the asset '${title}'`);
69
75
  };
70
76
  /* eslint-disable @typescript-eslint/no-unused-vars, guard-for-in */
71
77
  for (const index in indexer) {
72
78
  const chunk = await fs.readChunkFiles.next().catch((error) => {
73
- (0, utils_1.log)(this.config, error, 'error');
79
+ cli_utilities_1.log.error(String(error), { error });
74
80
  });
75
81
  if (chunk) {
76
82
  let apiContent = (0, lodash_1.orderBy)((0, lodash_1.values)(chunk), '_version');
@@ -95,7 +101,7 @@ class AssetImportSetup extends base_setup_1.default {
95
101
  }
96
102
  if (!(0, lodash_1.isEmpty)(this.duplicateAssets)) {
97
103
  utils_1.fsUtil.writeFile(this.duplicateAssetPath, this.duplicateAssets);
98
- (0, utils_1.log)(this.config, `Duplicate asset files are stored at: ${this.duplicateAssetPath}.`, 'info');
104
+ cli_utilities_1.log.info(`Duplicate asset files are stored at: ${this.duplicateAssetPath}.`);
99
105
  }
100
106
  }
101
107
  }
@@ -1,9 +1,15 @@
1
- import { ApiOptions, CustomPromiseHandler, EnvType, ImportConfig, ModuleClassParams } from '../../types';
1
+ import { ApiOptions, CustomPromiseHandler, EnvType, ImportConfig, ModuleClassParams, Modules } from '../../types';
2
2
  export default class BaseImportSetup {
3
3
  config: ImportConfig;
4
4
  stackAPIClient: ModuleClassParams['stackAPIClient'];
5
5
  dependencies: ModuleClassParams['dependencies'];
6
6
  constructor({ config, stackAPIClient, dependencies }: ModuleClassParams);
7
+ /**
8
+ * Set the module name in context directly
9
+ * @param module - Module name to set
10
+ * @returns {void}
11
+ */
12
+ protected initializeContext(module?: Modules): void;
7
13
  setupDependencies(): Promise<void>;
8
14
  /**
9
15
  * @method delay
@@ -23,18 +23,30 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- const utils_1 = require("../../utils");
27
26
  const lodash_1 = require("lodash");
27
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
28
28
  class BaseImportSetup {
29
29
  constructor({ config, stackAPIClient, dependencies }) {
30
30
  this.config = config;
31
31
  this.stackAPIClient = stackAPIClient;
32
32
  this.dependencies = dependencies;
33
33
  }
34
+ /**
35
+ * Set the module name in context directly
36
+ * @param module - Module name to set
37
+ * @returns {void}
38
+ */
39
+ initializeContext(module) {
40
+ if (this.config.context && module) {
41
+ this.config.context.module = module;
42
+ }
43
+ }
34
44
  async setupDependencies() {
35
45
  var _a;
46
+ cli_utilities_1.log.debug('Setting up dependencies', { dependencies: this.dependencies });
36
47
  for (const moduleName of this.dependencies) {
37
48
  try {
49
+ cli_utilities_1.log.debug(`Importing dependency module: ${moduleName}`);
38
50
  const modulePath = `./${moduleName}`;
39
51
  const { default: ModuleClass } = await (_a = modulePath, Promise.resolve().then(() => __importStar(require(_a))));
40
52
  const modulePayload = {
@@ -43,9 +55,10 @@ class BaseImportSetup {
43
55
  };
44
56
  const moduleInstance = new ModuleClass(modulePayload);
45
57
  await moduleInstance.start();
58
+ cli_utilities_1.log.debug(`Dependency module ${moduleName} imported successfully`);
46
59
  }
47
60
  catch (error) {
48
- (0, utils_1.log)(this.config, `Error importing '${moduleName}': ${error.message}`, 'error');
61
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), `Error importing '${moduleName}'`);
49
62
  }
50
63
  }
51
64
  }
@@ -121,7 +134,7 @@ class BaseImportSetup {
121
134
  // info: Batch No. 20 of import assets is complete
122
135
  if (currentIndexer)
123
136
  batchMsg += `Current chunk processing is (${currentIndexer}/${indexerCount})`;
124
- (0, utils_1.log)(this.config, `Batch No. (${batchNo}/${totelBatches}) of ${processName} is complete`, 'success');
137
+ cli_utilities_1.log.success(`Batch No. (${batchNo}/${totelBatches}) of ${processName} is complete`);
125
138
  }
126
139
  // if (this.config.modules.assets.displayExecutionTime) {
127
140
  // console.log(
@@ -1,19 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const utils_1 = require("../../utils");
5
4
  const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
6
  class ContentTypesImportSetup extends base_setup_1.default {
7
7
  constructor(options) {
8
8
  super(options);
9
+ this.initializeContext('content-types');
9
10
  }
10
11
  async start() {
11
12
  try {
12
13
  await this.setupDependencies();
13
- (0, utils_1.log)(this.config, `The required setup files for content types have been generated successfully.`, 'success');
14
+ cli_utilities_1.log.success(`The required setup files for content types have been generated successfully.`);
14
15
  }
15
16
  catch (error) {
16
- (0, utils_1.log)(this.config, `Error occurred while generating the content type mapper: ${error.message}.`, 'error');
17
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), 'Error occurred while generating the content type mapper');
17
18
  }
18
19
  }
19
20
  }
@@ -1,19 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const utils_1 = require("../../utils");
5
4
  const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
6
  class EntriesImportSetup extends base_setup_1.default {
7
7
  constructor(options) {
8
8
  super(options);
9
+ this.initializeContext('entries');
9
10
  }
10
11
  async start() {
11
12
  try {
12
13
  await this.setupDependencies();
13
- (0, utils_1.log)(this.config, `The required setup files for entries have been generated successfully.`, 'success');
14
+ cli_utilities_1.log.success(`The required setup files for entries have been generated successfully.`);
14
15
  }
15
16
  catch (error) {
16
- (0, utils_1.log)(this.config, `Error occurred while generating the entry mapper: ${error.message}.`, 'error');
17
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), 'Error occurred while generating the entry mapper');
17
18
  }
18
19
  }
19
20
  }
@@ -9,7 +9,7 @@ export default class ExtensionImportSetup {
9
9
  private mapperDirPath;
10
10
  private extensionsFolderPath;
11
11
  private extUidMapperPath;
12
- constructor({ config, stackAPIClient }: ModuleClassParams);
12
+ constructor({ config, stackAPIClient, dependencies }: ModuleClassParams);
13
13
  /**
14
14
  * Start the extension import setup
15
15
  * This method reads the extensions from the content folder and generates a mapper file
@@ -5,8 +5,11 @@ const path_1 = require("path");
5
5
  const lodash_1 = require("lodash");
6
6
  const cli_utilities_1 = require("@contentstack/cli-utilities");
7
7
  class ExtensionImportSetup {
8
- constructor({ config, stackAPIClient }) {
8
+ constructor({ config, stackAPIClient, dependencies }) {
9
9
  this.config = config;
10
+ if (this.config.context) {
11
+ this.config.context.module = 'extensions';
12
+ }
10
13
  this.stackAPIClient = stackAPIClient;
11
14
  this.extensionsFilePath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'extensions', 'extensions.json');
12
15
  this.extensionsConfig = config.modules.extensions;
@@ -20,6 +23,10 @@ class ExtensionImportSetup {
20
23
  */
21
24
  async start() {
22
25
  try {
26
+ if (!utils_1.fileHelper.fileExistsSync(this.extensionsFilePath)) {
27
+ cli_utilities_1.log.info('No extensions found in the content folder.');
28
+ return;
29
+ }
23
30
  const extensions = await utils_1.fsUtil.readFile(this.extensionsFilePath);
24
31
  if (!(0, lodash_1.isEmpty)(extensions)) {
25
32
  // 2. Create mapper directory
@@ -28,20 +35,20 @@ class ExtensionImportSetup {
28
35
  for (const extension of Object.values(extensions)) {
29
36
  const targetExtension = await this.getExtension(extension);
30
37
  if (!targetExtension) {
31
- (0, utils_1.log)(this.config, `Extension with the title '${extension.title}' not found in the stack.`, 'info');
38
+ cli_utilities_1.log.info(`Extension with the title '${extension.title}' not found in the stack.`);
32
39
  continue;
33
40
  }
34
41
  this.extensionMapper[extension.uid] = targetExtension.uid;
35
42
  }
36
43
  await utils_1.fsUtil.writeFile(this.extUidMapperPath, this.extensionMapper);
37
- (0, utils_1.log)(this.config, `The required setup files for extensions have been generated successfully.`, 'success');
44
+ cli_utilities_1.log.success(`The required setup files for extensions have been generated successfully.`);
38
45
  }
39
46
  else {
40
- (0, utils_1.log)(this.config, 'No extensions found in the content folder.', 'info');
47
+ cli_utilities_1.log.info('No extensions found in the content folder.');
41
48
  }
42
49
  }
43
50
  catch (error) {
44
- (0, utils_1.log)(this.config, `Error occurred while generating the extension mapper: ${(0, cli_utilities_1.formatError)(error)}.`, 'error');
51
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), 'Error occurred while generating the extension mapper');
45
52
  }
46
53
  }
47
54
  async getExtension(extension) {
@@ -1,19 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const utils_1 = require("../../utils");
5
4
  const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
5
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
6
6
  class GlobalFieldsImportSetup extends base_setup_1.default {
7
7
  constructor(options) {
8
8
  super(options);
9
+ this.initializeContext('global-fields');
9
10
  }
10
11
  async start() {
11
12
  try {
12
13
  await this.setupDependencies();
13
- (0, utils_1.log)(this.config, `The required setup files for global fields have been generated successfully.`, 'success');
14
+ cli_utilities_1.log.success(`The required setup files for global fields have been generated successfully.`);
14
15
  }
15
16
  catch (error) {
16
- (0, utils_1.log)(this.config, `Error occurred while generating the global field mapper: ${error.message}.`, 'error');
17
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), 'Error occurred while generating the global field mapper');
17
18
  }
18
19
  }
19
20
  }
@@ -14,7 +14,7 @@ export default class marketplaceAppImportSetup {
14
14
  marketplaceAppPath: string;
15
15
  nodeCrypto: NodeCrypto;
16
16
  appSdk: ContentstackMarketplaceClient;
17
- constructor({ config, stackAPIClient }: ModuleClassParams);
17
+ constructor({ config, stackAPIClient, dependencies }: ModuleClassParams);
18
18
  /**
19
19
  * Start the marketplaceApp import setup
20
20
  * This method reads the marketplaceApps from the content folder and generates a mapper file
@@ -5,8 +5,11 @@ const path_1 = require("path");
5
5
  const lodash_1 = require("lodash");
6
6
  const cli_utilities_1 = require("@contentstack/cli-utilities");
7
7
  class marketplaceAppImportSetup {
8
- constructor({ config, stackAPIClient }) {
8
+ constructor({ config, stackAPIClient, dependencies }) {
9
9
  this.config = config;
10
+ if (this.config.context) {
11
+ this.config.context.module = 'marketplace-apps';
12
+ }
10
13
  this.stackAPIClient = stackAPIClient;
11
14
  this.marketplaceAppsFilePath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'marketplace_apps', 'marketplace_apps.json');
12
15
  this.marketplaceAppsConfig = config.modules['marketplace-apps'];
@@ -20,6 +23,10 @@ class marketplaceAppImportSetup {
20
23
  */
21
24
  async start() {
22
25
  try {
26
+ if (!utils_1.fileHelper.fileExistsSync(this.marketplaceAppsFilePath)) {
27
+ cli_utilities_1.log.info('No Marketplace apps found in the content folder.');
28
+ return;
29
+ }
23
30
  const sourceMarketplaceApps = await utils_1.fsUtil.readFile(this.marketplaceAppsFilePath);
24
31
  if (!(0, lodash_1.isEmpty)(sourceMarketplaceApps)) {
25
32
  utils_1.fsUtil.makeDirectory(this.marketplaceAppsUidMapperPath); // Use fsUtil
@@ -30,14 +37,14 @@ class marketplaceAppImportSetup {
30
37
  const targetMarketplaceApps = await this.getMarketplaceApps();
31
38
  this.createMapper(sourceMarketplaceApps, targetMarketplaceApps);
32
39
  await utils_1.fsUtil.writeFile((0, path_1.join)(this.marketplaceAppsUidMapperPath, 'uid-mapping.json'), this.marketplaceAppMapper);
33
- (0, utils_1.log)(this.config, `The required setup files for Marketplace apps have been generated successfully.`, 'success');
40
+ cli_utilities_1.log.success(`The required setup files for Marketplace apps have been generated successfully.`);
34
41
  }
35
42
  else {
36
- (0, utils_1.log)(this.config, 'No Marketplace apps found in the content folder.', 'info');
43
+ cli_utilities_1.log.info('No Marketplace apps found in the content folder.');
37
44
  }
38
45
  }
39
46
  catch (error) {
40
- (0, utils_1.log)(this.config, `Error occurred while generating the Marketplace app mapper: ${error.message}.`, 'error');
47
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), 'Error occurred while generating the Marketplace app mapper');
41
48
  }
42
49
  }
43
50
  async getMarketplaceApps() {
@@ -81,7 +88,7 @@ class marketplaceAppImportSetup {
81
88
  });
82
89
  }
83
90
  else {
84
- (0, utils_1.log)(this.config, `No matching Marketplace app found in the target stack with name ${sourceAppName}`, 'info');
91
+ cli_utilities_1.log.info(`No matching Marketplace app found in the target stack with name ${sourceAppName}`);
85
92
  }
86
93
  });
87
94
  }
@@ -16,7 +16,7 @@ export default class TaxonomiesImportSetup {
16
16
  taxonomiesMapper: Record<string, unknown>;
17
17
  termsMapper: Record<string, unknown>;
18
18
  masterLocaleFilePath: string;
19
- constructor({ config, stackAPIClient }: ModuleClassParams);
19
+ constructor({ config, stackAPIClient, dependencies }: ModuleClassParams);
20
20
  /**
21
21
  * Start the taxonomies import setup
22
22
  * This method reads the taxonomies from the content folder and generates a mapper file
@@ -7,12 +7,15 @@ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
7
7
  const utils_1 = require("../../utils");
8
8
  const cli_utilities_1 = require("@contentstack/cli-utilities");
9
9
  class TaxonomiesImportSetup {
10
- constructor({ config, stackAPIClient }) {
10
+ constructor({ config, stackAPIClient, dependencies }) {
11
11
  var _a, _b, _c;
12
12
  this.isLocaleBasedStructure = false;
13
13
  this.taxonomiesMapper = {};
14
14
  this.termsMapper = {};
15
15
  this.config = config;
16
+ if (this.config.context) {
17
+ this.config.context.module = 'taxonomies';
18
+ }
16
19
  this.stackAPIClient = stackAPIClient;
17
20
  this.taxonomiesFolderPath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'taxonomies');
18
21
  this.taxonomiesFilePath = (0, path_1.join)(this.taxonomiesFolderPath, 'taxonomies.json');
@@ -41,11 +44,11 @@ class TaxonomiesImportSetup {
41
44
  utils_1.fsUtil.makeDirectory(this.taxonomiesMapperDirPath);
42
45
  utils_1.fsUtil.makeDirectory(this.termsMapperDirPath);
43
46
  if (this.isLocaleBasedStructure) {
44
- (0, utils_1.log)(this.config, 'Detected locale-based folder structure for taxonomies', 'info');
47
+ cli_utilities_1.log.info('Detected locale-based folder structure for taxonomies');
45
48
  await this.setupTaxonomiesByLocale(taxonomies);
46
49
  }
47
50
  else {
48
- (0, utils_1.log)(this.config, 'Using legacy folder structure for taxonomies', 'info');
51
+ cli_utilities_1.log.info('Using legacy folder structure for taxonomies');
49
52
  await this.setupTaxonomiesLegacy(taxonomies);
50
53
  }
51
54
  if (this.taxonomiesMapper !== undefined && !(0, isEmpty_1.default)(this.taxonomiesMapper)) {
@@ -54,14 +57,14 @@ class TaxonomiesImportSetup {
54
57
  if (this.termsMapper !== undefined && !(0, isEmpty_1.default)(this.termsMapper)) {
55
58
  utils_1.fsUtil.writeFile(this.termsSuccessPath, this.termsMapper);
56
59
  }
57
- (0, utils_1.log)(this.config, `The required setup files for taxonomies have been generated successfully.`, 'success');
60
+ cli_utilities_1.log.success(`The required setup files for taxonomies have been generated successfully.`);
58
61
  }
59
62
  else {
60
- (0, utils_1.log)(this.config, 'No taxonomies found in the content folder.', 'info');
63
+ cli_utilities_1.log.info('No taxonomies found in the content folder.');
61
64
  }
62
65
  }
63
66
  catch (error) {
64
- (0, utils_1.log)(this.config, `Error generating taxonomies mapper: ${error.message}`, 'error');
67
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.config.context), 'Error generating taxonomies mapper');
65
68
  }
66
69
  }
67
70
  /**
@@ -71,19 +74,19 @@ class TaxonomiesImportSetup {
71
74
  for (const taxonomy of Object.values(taxonomies)) {
72
75
  let targetTaxonomy = await this.getTaxonomies(taxonomy);
73
76
  if (!targetTaxonomy) {
74
- (0, utils_1.log)(this.config, `Taxonomies with uid '${taxonomy.uid}' not found in the stack!`, 'info');
77
+ cli_utilities_1.log.info(`Taxonomies with uid '${taxonomy.uid}' not found in the stack!`);
75
78
  continue;
76
79
  }
77
80
  targetTaxonomy = this.sanitizeTaxonomyAttribs(targetTaxonomy);
78
81
  this.taxonomiesMapper[taxonomy.uid] = targetTaxonomy;
79
82
  const terms = await this.getAllTermsOfTaxonomy(targetTaxonomy);
80
83
  if (Array.isArray(terms) && terms.length > 0) {
81
- (0, utils_1.log)(this.config, `Terms found for taxonomy '${taxonomy.uid}', processing...`, 'info');
84
+ cli_utilities_1.log.info(`Terms found for taxonomy '${taxonomy.uid}', processing...`);
82
85
  const sanitizedTerms = this.sanitizeTermsAttribs(terms);
83
86
  this.termsMapper[taxonomy.uid] = sanitizedTerms;
84
87
  }
85
88
  else {
86
- (0, utils_1.log)(this.config, `No terms found for taxonomy '${taxonomy.uid}', skipping...`, 'info');
89
+ cli_utilities_1.log.info(`No terms found for taxonomy '${taxonomy.uid}', skipping...`);
87
90
  }
88
91
  }
89
92
  }
@@ -94,12 +97,12 @@ class TaxonomiesImportSetup {
94
97
  async setupTaxonomiesByLocale(taxonomies) {
95
98
  const locales = this.loadAvailableLocales();
96
99
  for (const localeCode of Object.keys(locales)) {
97
- (0, utils_1.log)(this.config, `Processing taxonomies for locale: ${localeCode}`, 'info');
100
+ cli_utilities_1.log.info(`Processing taxonomies for locale: ${localeCode}`);
98
101
  for (const taxonomy of Object.values(taxonomies)) {
99
102
  // Query target stack for this taxonomy in this locale
100
103
  let targetTaxonomy = await this.getTaxonomies(taxonomy, localeCode);
101
104
  if (!targetTaxonomy) {
102
- (0, utils_1.log)(this.config, `Taxonomy '${taxonomy.uid}' not found in target stack for locale: ${localeCode}`, 'info');
105
+ cli_utilities_1.log.info(`Taxonomy '${taxonomy.uid}' not found in target stack for locale: ${localeCode}`);
103
106
  continue;
104
107
  }
105
108
  targetTaxonomy = this.sanitizeTaxonomyAttribs(targetTaxonomy);
@@ -108,12 +111,12 @@ class TaxonomiesImportSetup {
108
111
  this.taxonomiesMapper[taxonomy.uid] = targetTaxonomy;
109
112
  const terms = await this.getAllTermsOfTaxonomy(targetTaxonomy, localeCode);
110
113
  if (Array.isArray(terms) && terms.length > 0) {
111
- (0, utils_1.log)(this.config, `Terms found for taxonomy '${taxonomy.uid} for locale: ${localeCode}', processing...`, 'info');
114
+ cli_utilities_1.log.info(`Terms found for taxonomy '${taxonomy.uid} for locale: ${localeCode}', processing...`);
112
115
  const sanitizedTerms = this.sanitizeTermsAttribs(terms);
113
116
  this.termsMapper[taxonomy.uid] = sanitizedTerms;
114
117
  }
115
118
  else {
116
- (0, utils_1.log)(this.config, `No terms found for taxonomy '${taxonomy.uid} for locale: ${localeCode}', skipping...`, 'info');
119
+ cli_utilities_1.log.info(`No terms found for taxonomy '${taxonomy.uid} for locale: ${localeCode}', skipping...`);
117
120
  }
118
121
  }
119
122
  }
@@ -127,10 +130,10 @@ class TaxonomiesImportSetup {
127
130
  const masterLocaleFolder = (0, path_1.join)(this.taxonomiesFolderPath, masterLocaleCode);
128
131
  // Check if master locale folder exists (indicates new locale-based structure)
129
132
  if (!utils_1.fileHelper.fileExistsSync(masterLocaleFolder)) {
130
- (0, utils_1.log)(this.config, 'No locale-based folder structure detected', 'info');
133
+ cli_utilities_1.log.info('No locale-based folder structure detected');
131
134
  return false;
132
135
  }
133
- (0, utils_1.log)(this.config, 'Locale-based folder structure detected', 'info');
136
+ cli_utilities_1.log.info('Locale-based folder structure detected');
134
137
  return true;
135
138
  }
136
139
  /**
@@ -147,17 +150,17 @@ class TaxonomiesImportSetup {
147
150
  // The file contains an object with UID as key, extract the code
148
151
  const firstLocale = Object.values(masterLocaleData)[0];
149
152
  if (firstLocale === null || firstLocale === void 0 ? void 0 : firstLocale.code) {
150
- (0, utils_1.log)(this.config, `Master locale loaded from file: ${firstLocale.code}`, 'info');
153
+ cli_utilities_1.log.info(`Master locale loaded from file: ${firstLocale.code}`);
151
154
  return firstLocale.code;
152
155
  }
153
156
  }
154
157
  catch (error) {
155
- (0, utils_1.log)(this.config, 'Error reading master-locale.json, using fallback', 'warn');
158
+ cli_utilities_1.log.warn('Error reading master-locale.json, using fallback', { error });
156
159
  }
157
160
  }
158
161
  // Fallback to config or default
159
162
  const fallbackCode = ((_a = this.config.master_locale) === null || _a === void 0 ? void 0 : _a.code) || 'en-us';
160
- (0, utils_1.log)(this.config, `Using fallback master locale: ${fallbackCode}`, 'info');
163
+ cli_utilities_1.log.info(`Using fallback master locale: ${fallbackCode}`);
161
164
  return fallbackCode;
162
165
  }
163
166
  /**
@@ -171,7 +174,7 @@ class TaxonomiesImportSetup {
171
174
  locales[masterLocaleCode] = masterLocaleCode;
172
175
  // Then load additional locales from locales.json if it exists
173
176
  if (!utils_1.fileHelper.fileExistsSync(this.localesFilePath)) {
174
- (0, utils_1.log)(this.config, 'No locales file found, using only master locale', 'info');
177
+ cli_utilities_1.log.info('No locales file found, using only master locale');
175
178
  return locales;
176
179
  }
177
180
  try {
@@ -181,11 +184,11 @@ class TaxonomiesImportSetup {
181
184
  locales[locale.code] = locale.code;
182
185
  }
183
186
  }
184
- (0, utils_1.log)(this.config, `Loaded ${Object.keys(locales).length} locales (1 master + ${Object.keys(locales).length - 1} additional)`, 'info');
187
+ cli_utilities_1.log.info(`Loaded ${Object.keys(locales).length} locales (1 master + ${Object.keys(locales).length - 1} additional)`);
185
188
  return locales;
186
189
  }
187
190
  catch (error) {
188
- (0, utils_1.log)(this.config, 'Error loading locales file, using only master locale', 'error');
191
+ cli_utilities_1.log.error('Error loading locales file, using only master locale', { error });
189
192
  return locales;
190
193
  }
191
194
  }
@@ -267,11 +270,10 @@ class TaxonomiesImportSetup {
267
270
  const taxInfo = taxonomyUid ? ` (${taxonomyUid}${context})` : '';
268
271
  if ((err === null || err === void 0 ? void 0 : err.errorMessage) || (err === null || err === void 0 ? void 0 : err.message)) {
269
272
  const errorMsg = (err === null || err === void 0 ? void 0 : err.errorMessage) || ((_a = err === null || err === void 0 ? void 0 : err.errors) === null || _a === void 0 ? void 0 : _a.taxonomy) || ((_b = err === null || err === void 0 ? void 0 : err.errors) === null || _b === void 0 ? void 0 : _b.term) || (err === null || err === void 0 ? void 0 : err.message);
270
- (0, utils_1.log)(this.config, `${errorMsg}${taxInfo}`, 'error');
273
+ cli_utilities_1.log.error(`${errorMsg}${taxInfo}`, { error: err, taxonomyUid, locale });
271
274
  }
272
275
  else {
273
- (0, utils_1.log)(this.config, `Error fetching taxonomy data${taxInfo}!`, 'error');
274
- (0, utils_1.log)(this.config, err, 'error');
276
+ cli_utilities_1.log.error(`Error fetching taxonomy data${taxInfo}!`, { error: err, taxonomyUid, locale });
275
277
  }
276
278
  }
277
279
  }
@@ -1,4 +1,4 @@
1
- import { Modules } from '.';
1
+ import { Modules, Context } from '.';
2
2
  import DefaultConfig from './default-config';
3
3
  export interface ExternalConfig {
4
4
  source_stack?: string;
@@ -9,6 +9,7 @@ export interface ExternalConfig {
9
9
  password?: string;
10
10
  }
11
11
  export default interface ImportConfig extends DefaultConfig, ExternalConfig {
12
+ context?: Context;
12
13
  cliLogsPath?: string;
13
14
  contentDir: string;
14
15
  data: string;
@@ -114,3 +114,6 @@ export type TaxonomyQueryParams = {
114
114
  depth?: number;
115
115
  locale?: string;
116
116
  };
117
+ export interface Context {
118
+ module: string;
119
+ }
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateBranch = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
- const utils_1 = require("../utils");
6
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
7
  const validateBranch = async (stackAPIClient, config, branch) => {
8
8
  return new Promise(async (resolve, reject) => {
9
9
  try {
10
10
  const data = await stackAPIClient.branch(branch).fetch();
11
11
  if (data && typeof data === 'object') {
12
12
  if (data.error_message) {
13
- (0, utils_1.log)(config, chalk_1.default.red(data.error_message), 'error');
14
- (0, utils_1.log)(config, chalk_1.default.red('No branch found with the name ' + branch), 'error');
13
+ cli_utilities_1.log.error(chalk_1.default.red(data.error_message), { error: data.error_message });
14
+ cli_utilities_1.log.error(chalk_1.default.red('No branch found with the name ' + branch), { branch });
15
15
  reject({ message: 'No branch found with the name ' + branch, error: data.error_message });
16
16
  }
17
17
  else {
@@ -23,7 +23,7 @@ const validateBranch = async (stackAPIClient, config, branch) => {
23
23
  }
24
24
  }
25
25
  catch (error) {
26
- (0, utils_1.log)(config, chalk_1.default.red('No branch found with the name ' + branch), 'error');
26
+ cli_utilities_1.log.error(chalk_1.default.red('No branch found with the name ' + branch), { error, branch });
27
27
  reject({ message: 'No branch found with the name ' + branch, error });
28
28
  }
29
29
  });
@@ -58,7 +58,7 @@ const readLargeFile = function (filePath, opts) {
58
58
  resolve(data);
59
59
  });
60
60
  parseStream.on('error', function (error) {
61
- console.log('error', error);
61
+ cli_utilities_1.log.error(`Error reading large file: ${error.message}`, { error, filePath });
62
62
  reject(error);
63
63
  });
64
64
  readStream.pipe(parseStream);
@@ -23,7 +23,7 @@ const setupConfig = async (importCmdFlags) => {
23
23
  config.contentDir = (0, cli_utilities_1.sanitizePath)(importCmdFlags['data'] || importCmdFlags['data-dir'] || config.data || (await (0, interactive_1.askContentDir)()));
24
24
  const pattern = /[*$%#<>{}!&?]/g;
25
25
  if (pattern.test(config.contentDir)) {
26
- cli_utilities_1.cliux.print(`\nPlease add a directory path without any of the special characters: (*,&,{,},[,],$,%,<,>,?,!)`, {
26
+ cli_utilities_1.cliux.print(`\nPlease enter a directory path without special characters: (*,&,{,},[,],$,%,<,>,?,!)`, {
27
27
  color: 'yellow',
28
28
  });
29
29
  config.contentDir = (0, cli_utilities_1.sanitizePath)(await (0, interactive_1.askContentDir)());
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Contentstack Export
3
- * Copyright (c) 2024 Contentstack LLC
3
+ * Copyright (c) 2026 Contentstack LLC
4
4
  * MIT Licensed
5
5
  */
6
6
  import { ImportConfig } from '../types';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /*!
3
3
  * Contentstack Export
4
- * Copyright (c) 2024 Contentstack LLC
4
+ * Copyright (c) 2026 Contentstack LLC
5
5
  * MIT Licensed
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Contentstack Import
3
- * Copyright (c) 2024 Contentstack LLC
3
+ * Copyright (c) 2026 Contentstack LLC
4
4
  * MIT Licensed
5
5
  */
6
6
  import { ImportConfig } from '../types';
@@ -4,11 +4,10 @@
4
4
  /* eslint-disable no-empty */
5
5
  /*!
6
6
  * Contentstack Import
7
- * Copyright (c) 2024 Contentstack LLC
7
+ * Copyright (c) 2026 Contentstack LLC
8
8
  * MIT Licensed
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- const logger_1 = require("./logger");
12
11
  const cli_utilities_1 = require("@contentstack/cli-utilities");
13
12
  const login = async (config) => {
14
13
  const client = await (0, cli_utilities_1.managementSDKClient)(config);
@@ -21,7 +20,7 @@ const login = async (config) => {
21
20
  authtoken: config.authtoken,
22
21
  'X-User-Agent': 'contentstack-export/v',
23
22
  };
24
- (0, logger_1.log)(config, 'Contentstack account authenticated successfully!', 'success');
23
+ cli_utilities_1.log.success('Contentstack account authenticated successfully!');
25
24
  return config;
26
25
  }
27
26
  else {
@@ -40,10 +39,10 @@ const login = async (config) => {
40
39
  var _a;
41
40
  let errorstack_key = (_a = error === null || error === void 0 ? void 0 : error.errors) === null || _a === void 0 ? void 0 : _a.api_key;
42
41
  if (errorstack_key) {
43
- (0, logger_1.log)(config, 'Stack Api key ' + errorstack_key[0] + 'Please enter valid Key', 'error');
42
+ cli_utilities_1.log.error('Stack Api key ' + errorstack_key[0] + 'Please enter valid Key', { error });
44
43
  throw error;
45
44
  }
46
- (0, logger_1.log)(config, error === null || error === void 0 ? void 0 : error.errorMessage, 'error');
45
+ cli_utilities_1.log.error((error === null || error === void 0 ? void 0 : error.errorMessage) || 'Unknown error', { error });
47
46
  throw error;
48
47
  });
49
48
  config.destinationStackName = stack.name;
@@ -25,7 +25,7 @@ const setupBranchConfig = async (config, stackAPIClient) => {
25
25
  }
26
26
  }
27
27
  catch (error) {
28
- cli_utilities_1.log.debug('Failed to fetch branches', { error });
28
+ cli_utilities_1.log.error('Failed to fetch branches', { error });
29
29
  }
30
30
  };
31
31
  exports.setupBranchConfig = setupBranchConfig;
@@ -88,5 +88,5 @@
88
88
  ]
89
89
  }
90
90
  },
91
- "version": "1.7.0"
91
+ "version": "1.7.2"
92
92
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import-setup",
3
3
  "description": "Contentstack CLI plugin to setup the mappers and configurations for the import command",
4
- "version": "1.7.0",
4
+ "version": "1.7.2",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "~1.6.1",
9
- "@contentstack/cli-utilities": "~1.14.4",
8
+ "@contentstack/cli-command": "~1.7.1",
9
+ "@contentstack/cli-utilities": "~1.16.0",
10
10
  "@oclif/core": "^4.3.0",
11
11
  "big-json": "^3.2.0",
12
12
  "chalk": "^4.1.2",