@contentstack/cli-cm-import 1.26.1 → 1.26.3

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 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.26.1 linux-x64 node-v22.17.1
50
+ @contentstack/cli-cm-import/1.26.3 linux-x64 node-v22.18.0
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -10,9 +10,10 @@ class ImportCommand extends cli_command_1.Command {
10
10
  // initialize the importer
11
11
  // start import
12
12
  let backupDir;
13
+ let importConfig;
13
14
  try {
14
15
  const { flags } = await this.parse(ImportCommand);
15
- let importConfig = await (0, utils_1.setupImportConfig)(flags);
16
+ importConfig = await (0, utils_1.setupImportConfig)(flags);
16
17
  // Prepare the context object
17
18
  const context = this.createImportContext(importConfig.apiKey, importConfig.authenticationMethod);
18
19
  importConfig.context = Object.assign({}, context);
@@ -45,10 +46,9 @@ class ImportCommand extends cli_command_1.Command {
45
46
  // Branch not enabled, just the let flow continue
46
47
  }
47
48
  }
48
- // Set backupDir early so it's available in error handling
49
- backupDir = importConfig.backupDir;
50
49
  const moduleImporter = new import_1.ModuleImporter(managementAPIClient, importConfig);
51
50
  const result = await moduleImporter.start();
51
+ backupDir = importConfig.backupDir;
52
52
  if (!(result === null || result === void 0 ? void 0 : result.noSuccessMsg)) {
53
53
  const successMessage = importConfig.stackName
54
54
  ? `Successfully imported the content to the stack named ${importConfig.stackName} with the API key ${importConfig.apiKey} .`
@@ -61,8 +61,8 @@ class ImportCommand extends cli_command_1.Command {
61
61
  catch (error) {
62
62
  (0, cli_utilities_1.handleAndLogError)(error);
63
63
  cli_utilities_1.log.info(`The log has been stored at '${(0, cli_utilities_1.getLogPath)()}'`);
64
- if (backupDir) {
65
- cli_utilities_1.log.info(`The backup content has been stored at '${backupDir}'`);
64
+ if (importConfig === null || importConfig === void 0 ? void 0 : importConfig.backupDir) {
65
+ cli_utilities_1.log.info(`The backup content has been stored at '${importConfig === null || importConfig === void 0 ? void 0 : importConfig.backupDir}'`);
66
66
  }
67
67
  else {
68
68
  cli_utilities_1.log.info('No backup directory was created due to early termination');
@@ -436,7 +436,7 @@ const config = {
436
436
  getEncryptionKeyMaxRetry: 3,
437
437
  // useBackedupDir: '',
438
438
  // backupConcurrency: 10,
439
- onlyTSModules: ['taxonomies', 'personalize', 'variant-entries'],
439
+ onlyTSModules: ['taxonomies', 'personalize', 'variant-entries', 'stack'],
440
440
  auditConfig: {
441
441
  noLog: false,
442
442
  skipConfirm: true,
@@ -61,7 +61,7 @@ class ContentTypesImport extends base_class_1.default {
61
61
  cli_utilities_1.log.debug(`Found ${this.cTs.length} content types to import`, this.importConfig.context);
62
62
  await utils_1.fsUtil.makeDirectory(this.cTsMapperPath);
63
63
  cli_utilities_1.log.debug('Created content types mapper directory', this.importConfig.context);
64
- this.installedExtensions = ((await utils_1.fsUtil.readFile(this.marketplaceAppMapperPath)) || { extension_uid: {} }).extension_uid;
64
+ this.installedExtensions = (utils_1.fsUtil.readFile(this.marketplaceAppMapperPath) || { extension_uid: {} }).extension_uid;
65
65
  cli_utilities_1.log.debug(`Loaded ${(_a = Object.keys(this.installedExtensions)) === null || _a === void 0 ? void 0 : _a.length} installed extensions`, this.importConfig.context);
66
66
  this.taxonomies = utils_1.fsUtil.readFile(this.taxonomiesPath);
67
67
  const taxonomyCount = Object.keys(this.taxonomies || {}).length;
@@ -46,24 +46,24 @@ class EntriesImport extends base_class_1.default {
46
46
  async start() {
47
47
  var _a;
48
48
  try {
49
- this.cTs = utils_1.fsUtil.readFile(path.join(this.cTsPath, 'schema.json'));
49
+ this.cTs = (utils_1.fsUtil.readFile(path.join(this.cTsPath, 'schema.json')) || []);
50
50
  if (!this.cTs || (0, lodash_1.isEmpty)(this.cTs)) {
51
- cli_utilities_1.log.info('No content type found', this.importConfig.context);
51
+ cli_utilities_1.log.warn(`No content types file found at ${path.join(this.cTsPath, 'schema.json')}. Skipping entries import.`, this.importConfig.context);
52
52
  return;
53
53
  }
54
54
  cli_utilities_1.log.debug(`Found ${this.cTs.length} content types for entry import`, this.importConfig.context);
55
- this.installedExtensions = ((await utils_1.fsUtil.readFile(this.marketplaceAppMapperPath)) || { extension_uid: {} }).extension_uid;
55
+ this.installedExtensions = (utils_1.fsUtil.readFile(this.marketplaceAppMapperPath) || { extension_uid: {} }).extension_uid;
56
56
  cli_utilities_1.log.debug('Loaded installed extensions for entry processing', this.importConfig.context);
57
57
  this.assetUidMapper = utils_1.fsUtil.readFile(this.assetUidMapperPath) || {};
58
58
  this.assetUrlMapper = utils_1.fsUtil.readFile(this.assetUrlMapperPath) || {};
59
59
  cli_utilities_1.log.debug(`Loaded asset mappings - UIDs: ${Object.keys(this.assetUidMapper).length}, URLs: ${Object.keys(this.assetUrlMapper).length}`, this.importConfig.context);
60
- this.taxonomies = utils_1.fsUtil.readFile(this.taxonomiesPath);
60
+ this.taxonomies = (utils_1.fsUtil.readFile(this.taxonomiesPath) || {});
61
61
  cli_utilities_1.log.debug('Loaded taxonomy data for entry processing', this.importConfig.context);
62
62
  utils_1.fsUtil.makeDirectory(this.entriesMapperPath);
63
63
  cli_utilities_1.log.debug('Created entries mapper directory', this.importConfig.context);
64
64
  cli_utilities_1.log.info('Preparing content types for entry import', this.importConfig.context);
65
65
  await this.disableMandatoryCTReferences();
66
- this.locales = (0, lodash_1.values)(utils_1.fsUtil.readFile(this.localesPath));
66
+ this.locales = (0, lodash_1.values)((utils_1.fsUtil.readFile(this.localesPath) || []));
67
67
  this.locales.unshift(this.importConfig.master_locale); // adds master locale to the list
68
68
  cli_utilities_1.log.debug(`Processing entries for ${(0, lodash_1.values)(this.locales).length} locales`, this.importConfig.context);
69
69
  //Create Entries
@@ -119,8 +119,14 @@ class EntriesImport extends base_class_1.default {
119
119
  // Publishing entries
120
120
  if (!this.importConfig.skipEntriesPublish) {
121
121
  cli_utilities_1.log.info('Starting entry publishing process', this.importConfig.context);
122
- this.envs = utils_1.fileHelper.readFileSync(this.envPath);
123
- cli_utilities_1.log.debug(`Loaded ${Object.keys(this.envs).length} environments for publishing`, this.importConfig.context);
122
+ this.envs = utils_1.fileHelper.readFileSync(this.envPath) || {};
123
+ if (Object.keys(this.envs).length === 0) {
124
+ cli_utilities_1.log.warn(`No environments file found at ${this.envPath}. Entries will not be published.`, this.importConfig.context);
125
+ return;
126
+ }
127
+ else {
128
+ cli_utilities_1.log.debug(`Loaded ${Object.keys(this.envs).length} environments for publishing`, this.importConfig.context);
129
+ }
124
130
  for (let entryRequestOption of entryRequestOptions) {
125
131
  await this.publishEntries(entryRequestOption).catch((error) => {
126
132
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { cTUid: entryRequestOption.cTUid, locale: entryRequestOption.locale }), `Error in publishing entries of ${entryRequestOption.cTUid} in locale ${entryRequestOption.locale}`);
@@ -137,7 +143,6 @@ class EntriesImport extends base_class_1.default {
137
143
  catch (error) {
138
144
  this.createEntryDataForVariantEntry();
139
145
  (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
140
- throw new Error('Error while importing entries');
141
146
  }
142
147
  }
143
148
  /**
@@ -157,8 +162,7 @@ class EntriesImport extends base_class_1.default {
157
162
  cli_utilities_1.log.debug(`Successfully processed content type: ${uid}`, this.importConfig.context);
158
163
  };
159
164
  const onReject = ({ error, apiData: { uid } }) => {
160
- (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { uid }));
161
- throw new Error(`${uid} content type references removal failed`);
165
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { uid }), `${uid} content type references removal failed`);
162
166
  };
163
167
  return await this.makeConcurrentCall({
164
168
  processName: 'Update content types (removing mandatory references temporarily)',
@@ -587,7 +591,7 @@ class EntriesImport extends base_class_1.default {
587
591
  for (const index in indexer) {
588
592
  cli_utilities_1.log.debug(`Processing reference update chunk ${index} of ${indexerCount} for ${cTUid} in ${locale}`, this.importConfig.context);
589
593
  const chunk = await fs.readChunkFiles.next().catch((error) => {
590
- (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { cTUid, locale }), 'Error');
594
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { cTUid, locale }), 'Failed to load data chunks due to a read error. Ensure the files are accessible and not corrupted.');
591
595
  });
592
596
  if (chunk) {
593
597
  let apiContent = (0, lodash_1.values)(chunk);
@@ -664,7 +668,7 @@ class EntriesImport extends base_class_1.default {
664
668
  cli_utilities_1.log.success(`${uid} content type references updated`, this.importConfig.context);
665
669
  };
666
670
  const onReject = ({ error, apiData: { uid } }) => {
667
- (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { uid }), 'Error');
671
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign(Object.assign({}, this.importConfig.context), { uid }), `Failed to update references of content type '${uid}'`);
668
672
  throw new Error(`Failed to update references of content type ${uid}`);
669
673
  };
670
674
  return await this.makeConcurrentCall({
@@ -724,7 +728,7 @@ class EntriesImport extends base_class_1.default {
724
728
  }
725
729
  async updateFieldRules() {
726
730
  var _a, _b, _c;
727
- let cTsWithFieldRules = utils_1.fsUtil.readFile(path.join(this.cTsPath + '/field_rules_uid.json'));
731
+ let cTsWithFieldRules = (utils_1.fsUtil.readFile(path.join(this.cTsPath + '/field_rules_uid.json')) || []);
728
732
  if (!cTsWithFieldRules || (cTsWithFieldRules === null || cTsWithFieldRules === void 0 ? void 0 : cTsWithFieldRules.length) === 0) {
729
733
  cli_utilities_1.log.debug('No content types with field rules found to update', this.importConfig.context);
730
734
  return;
@@ -732,7 +736,7 @@ class EntriesImport extends base_class_1.default {
732
736
  cli_utilities_1.log.debug(`Found ${cTsWithFieldRules.length} content types with field rules to update`, this.importConfig.context);
733
737
  for (let cTUid of cTsWithFieldRules) {
734
738
  cli_utilities_1.log.debug(`Processing field rules for content type: ${cTUid}`, this.importConfig.context);
735
- const cTs = utils_1.fsUtil.readFile(path.join(this.cTsPath, 'schema.json'));
739
+ const cTs = (utils_1.fsUtil.readFile(path.join(this.cTsPath, 'schema.json')) || []);
736
740
  const contentType = (0, lodash_1.find)(cTs, { uid: cTUid });
737
741
  if (contentType.field_rules) {
738
742
  cli_utilities_1.log.debug(`Found ${contentType.field_rules.length} field rules for content type: ${cTUid}`, this.importConfig.context);
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
4
4
  const node_path_1 = require("node:path");
5
5
  const utils_1 = require("../../utils");
6
6
  const base_class_1 = tslib_1.__importDefault(require("./base-class"));
7
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
7
8
  class ImportStack extends base_class_1.default {
8
9
  constructor({ importConfig, stackAPIClient }) {
9
10
  super({ importConfig, stackAPIClient });
@@ -14,23 +15,22 @@ class ImportStack extends base_class_1.default {
14
15
  }
15
16
  async start() {
16
17
  var _a, _b;
17
- (0, utils_1.log)(this.importConfig, 'Migrating stack...', 'info');
18
- if (utils_1.fileHelper.fileExistsSync(this.envUidMapperPath)) {
19
- this.envUidMapper = utils_1.fsUtil.readFile(this.envUidMapperPath, true);
20
- }
21
- else {
22
- throw new Error('Please run the environments migration first.');
23
- }
24
18
  if (this.importConfig.management_token) {
25
- (0, utils_1.log)(this.importConfig, 'Skipping stack settings import: Operation is not supported when using a management token.', 'info');
26
- (0, utils_1.log)(this.importConfig, 'Successfully imported stack', 'success');
19
+ cli_utilities_1.log.info('Skipping stack settings import: Operation is not supported when using a management token.', this.importConfig.context);
27
20
  return;
28
21
  }
29
22
  if (utils_1.fileHelper.fileExistsSync(this.stackSettingsPath)) {
30
23
  this.stackSettings = utils_1.fsUtil.readFile(this.stackSettingsPath, true);
31
24
  }
32
25
  else {
33
- (0, utils_1.log)(this.importConfig, 'No stack Found!', 'info');
26
+ cli_utilities_1.log.info('No stack setting found!', this.importConfig.context);
27
+ return;
28
+ }
29
+ if (utils_1.fileHelper.fileExistsSync(this.envUidMapperPath)) {
30
+ this.envUidMapper = utils_1.fsUtil.readFile(this.envUidMapperPath, true);
31
+ }
32
+ else {
33
+ cli_utilities_1.log.warn('Skipping stack settings import. Please run the environments migration first.', this.importConfig.context);
34
34
  return;
35
35
  }
36
36
  if (((_a = this.stackSettings) === null || _a === void 0 ? void 0 : _a.live_preview) && ((_b = this.stackSettings) === null || _b === void 0 ? void 0 : _b.live_preview['default-env'])) {
@@ -40,10 +40,10 @@ class ImportStack extends base_class_1.default {
40
40
  }
41
41
  try {
42
42
  await this.stack.addSettings(this.stackSettings);
43
- (0, utils_1.log)(this.importConfig, 'Successfully imported stack', 'success');
43
+ cli_utilities_1.log.success('Successfully imported stack', this.importConfig.context);
44
44
  }
45
45
  catch (error) {
46
- (0, utils_1.log)(this.importConfig, `Stack failed to be imported! ${(0, utils_1.formatError)(error)}`, 'error');
46
+ (0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.importConfig.context));
47
47
  }
48
48
  }
49
49
  }
@@ -290,7 +290,7 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
290
290
  }
291
291
  }
292
292
  if (unmatchedUids.length) {
293
- cli_utilities_1.log.warn(`Found ${unmatchedUids.length} unmatched asset UIDs`);
293
+ cli_utilities_1.log.debug(`Found ${unmatchedUids.length} unmatched asset UIDs`);
294
294
  let unmatchedAssetUids = helper.readFileSync(path.join(assetUidMapperPath, 'unmatched-asset-uids.json'));
295
295
  unmatchedAssetUids = unmatchedAssetUids || {};
296
296
  if (unmatchedAssetUids.hasOwnProperty(data.content_type.uid)) {
@@ -304,7 +304,7 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
304
304
  helper.writeFile(path.join(assetUidMapperPath, 'unmatched-asset-uids.json'));
305
305
  }
306
306
  if (unmatchedUrls.length) {
307
- cli_utilities_1.log.warn(`Found ${unmatchedUrls.length} unmatched asset URLs`);
307
+ cli_utilities_1.log.debug(`Found ${unmatchedUrls.length} unmatched asset URLs`);
308
308
  let unmatchedAssetUrls = helper.readFileSync(path.join(assetUidMapperPath, 'unmatched-asset-urls.json'));
309
309
  unmatchedAssetUrls = unmatchedAssetUrls || {};
310
310
  if (unmatchedAssetUrls.hasOwnProperty(data.content_type.uid)) {
@@ -128,8 +128,7 @@ const removeReferenceFields = async function (schema, flag = { supressed: false
128
128
  catch (error) {
129
129
  // Else warn and modify the schema object.
130
130
  isContentTypeError = true;
131
- cli_utilities_1.log.warn(`Content type does not exist: ${schema[i].reference_to[j]}`);
132
- console.warn(`Content-type ${schema[i].reference_to[j]} does not exist. Removing the field from schema`);
131
+ cli_utilities_1.log.warn(`Content-type ${schema[i].reference_to[j]} does not exist. Removing the field from schema`);
133
132
  }
134
133
  }
135
134
  if (isContentTypeError) {
@@ -238,7 +238,7 @@ const lookupEntries = function (data, mappedUids, uidMapperPath) {
238
238
  }
239
239
  });
240
240
  if (unmapped.length > 0) {
241
- cli_utilities_1.log.warn(`Found ${unmapped.length} unmapped entry references`);
241
+ cli_utilities_1.log.debug(`Found ${unmapped.length} unmapped entry references`);
242
242
  let unmappedUids = fileHelper.readFileSync(path.join(uidMapperPath, 'unmapped-uids.json'));
243
243
  unmappedUids = unmappedUids || {};
244
244
  if (unmappedUids.hasOwnProperty(data.content_type.uid)) {
@@ -69,7 +69,7 @@ const lookupExtension = function (config, schema, preserveStackVersion, installe
69
69
  schema[i].reference_to = global_fields_data[global_fields_key_value];
70
70
  }
71
71
  else {
72
- cli_utilities_1.log.warn(`No mapping found for global field: ${global_fields_key_value}`);
72
+ cli_utilities_1.log.debug(`No mapping found for global field: ${global_fields_key_value}`);
73
73
  }
74
74
  }
75
75
  else if (schema[i].hasOwnProperty('extension_uid')) {
@@ -88,7 +88,7 @@ const lookupExtension = function (config, schema, preserveStackVersion, installe
88
88
  schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
89
89
  }
90
90
  else {
91
- cli_utilities_1.log.warn(`No mapping found for extension: ${extension_key_value}`);
91
+ cli_utilities_1.log.debug(`No mapping found for extension: ${extension_key_value}`);
92
92
  }
93
93
  }
94
94
  }
@@ -111,7 +111,7 @@ const lookupExtension = function (config, schema, preserveStackVersion, installe
111
111
  newPluginUidsArray.push(marketPlaceAppsData.extension_uid[extension_key_value]);
112
112
  }
113
113
  else {
114
- cli_utilities_1.log.warn(`No mapping found for plugin extension: ${extension_key_value}`);
114
+ cli_utilities_1.log.debug(`No mapping found for plugin extension: ${extension_key_value}`);
115
115
  }
116
116
  });
117
117
  cli_utilities_1.log.debug(`Updated plugins array with ${newPluginUidsArray.length} mapped extensions`);
@@ -199,5 +199,5 @@
199
199
  ]
200
200
  }
201
201
  },
202
- "version": "1.26.1"
202
+ "version": "1.26.3"
203
203
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.26.1",
4
+ "version": "1.26.3",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
8
  "@contentstack/cli-audit": "~1.14.0",
9
9
  "@contentstack/cli-command": "~1.6.0",
10
- "@contentstack/cli-utilities": "~1.13.1",
10
+ "@contentstack/cli-utilities": "~1.13.2",
11
11
  "@contentstack/management": "~1.22.0",
12
12
  "@contentstack/cli-variants": "~1.3.0",
13
13
  "@oclif/core": "^4.3.0",