@contentstack/cli-cm-import 1.5.10 → 1.5.11

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.5.10 linux-x64 node-v16.20.1
50
+ @contentstack/cli-cm-import/1.5.11 linux-x64 node-v16.20.1
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.10",
2
+ "version": "1.5.11",
3
3
  "commands": {
4
4
  "cm:stacks:import": {
5
5
  "id": "cm:stacks:import",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.5.10",
4
+ "version": "1.5.11",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
@@ -103,7 +103,11 @@ module.exports = class ImportEntries {
103
103
  }
104
104
  }
105
105
  } catch (error) {
106
- addlogs(this.config, `Failed to read the content types to import entries ${util.formatError(error)}`, 'error');
106
+ addlogs(
107
+ this.config,
108
+ `Failed to read the content types to import entries ${util.formatError(error)}`,
109
+ 'error',
110
+ );
107
111
  process.exit(0);
108
112
  }
109
113
  }
@@ -165,7 +169,7 @@ module.exports = class ImportEntries {
165
169
  addlogs(self.config, "Successfully imported '" + lang + "' entries!", 'success');
166
170
  counter++;
167
171
  } else {
168
- addlogs(self.config,`'${lang}' has not been configured for import, thus skipping it`, 'success');
172
+ addlogs(self.config, `'${lang}' has not been configured for import, thus skipping it`, 'success');
169
173
  counter++;
170
174
  }
171
175
  },
@@ -191,7 +195,7 @@ module.exports = class ImportEntries {
191
195
  addlogs(
192
196
  self.config,
193
197
  `Failed to update the field rules for content type '${schema.uid}' ${util.formatError(error)}`,
194
- 'error'
198
+ 'error',
195
199
  );
196
200
  }
197
201
  }
@@ -594,7 +598,7 @@ module.exports = class ImportEntries {
594
598
  addlogs(
595
599
  this.config,
596
600
  `Failed to update the entry ${uid} references while reposting ${util.formatError(error)}`,
597
- 'error'
601
+ 'error',
598
602
  );
599
603
  }
600
604
  });
@@ -675,7 +679,7 @@ module.exports = class ImportEntries {
675
679
  })
676
680
  .catch((error) => {
677
681
  // error while executing entry in batch
678
- addlogs(this.config, `Failed re-post entries at batch no: '${(index + 1)}`, 'error');
682
+ addlogs(this.config, `Failed re-post entries at batch no: '${index + 1}`, 'error');
679
683
  addlogs(this.config, util.formatError(error), 'error');
680
684
  // throw error;
681
685
  });
@@ -694,11 +698,7 @@ module.exports = class ImportEntries {
694
698
  })
695
699
  .catch((error) => {
696
700
  // error while updating entries with references
697
- addlogs(
698
- this.config,
699
- `Failed re-post entries of content type ${ctUid} locale ${lang}`,
700
- 'error',
701
- );
701
+ addlogs(this.config, `Failed re-post entries of content type ${ctUid} locale ${lang}`, 'error');
702
702
  addlogs(this.config, util.formatError(error), 'error');
703
703
  // throw error;
704
704
  });
@@ -1034,105 +1034,119 @@ module.exports = class ImportEntries {
1034
1034
  async (ctUid) => {
1035
1035
  let eFilePath = path.resolve(this.ePath, ctUid, lang + '.json');
1036
1036
  let entries = await helper.readLargeFile(eFilePath);
1037
-
1038
- let eUids = Object.keys(entries);
1039
- let batches = [];
1040
- let batchSize;
1041
-
1042
- if (eUids.length > 0) {
1043
- let entryBatchLimit = this.eConfig.batchLimit || 10;
1044
- batchSize = Math.round(entryBatchLimit / 3);
1045
- // Run entry creation in batches
1046
- for (let i = 0; i < eUids.length; i += batchSize) {
1047
- batches.push(eUids.slice(i, i + batchSize));
1048
- }
1037
+ if (entries === undefined) {
1038
+ addlogs(
1039
+ this.config,
1040
+ `No entries were found for Content type: ${ctUid} in language: ${lang}`,
1041
+ 'info',
1042
+ );
1049
1043
  } else {
1050
- return;
1051
- }
1052
-
1053
- return Promise.map(
1054
- batches,
1055
- async (batch, index) => {
1056
- return Promise.map(
1057
- batch,
1058
- async (eUid) => {
1059
- let entry = entries[eUid];
1060
- let envId = [];
1061
- let locales = [];
1062
- if (entry.publish_details && entry.publish_details.length > 0) {
1063
- _.forEach(entries[eUid].publish_details, (pubObject) => {
1064
- if (
1065
- self.environment.hasOwnProperty(pubObject.environment) &&
1066
- _.indexOf(envId, self.environment[pubObject.environment].name) === -1
1067
- ) {
1068
- envId.push(self.environment[pubObject.environment].name);
1069
- }
1070
- if (pubObject.locale) {
1071
- let idx = _.indexOf(locales, pubObject.locale);
1072
- if (idx === -1) {
1073
- locales.push(pubObject.locale);
1044
+ let eUids = Object.keys(entries);
1045
+ let batches = [];
1046
+ let batchSize;
1047
+
1048
+ if (eUids.length > 0) {
1049
+ let entryBatchLimit = this.eConfig.batchLimit || 10;
1050
+ batchSize = Math.round(entryBatchLimit / 3);
1051
+ // Run entry creation in batches
1052
+ for (let i = 0; i < eUids.length; i += batchSize) {
1053
+ batches.push(eUids.slice(i, i + batchSize));
1054
+ }
1055
+ } else {
1056
+ return;
1057
+ }
1058
+
1059
+ return Promise.map(
1060
+ batches,
1061
+ async (batch, index) => {
1062
+ return Promise.map(
1063
+ batch,
1064
+ async (eUid) => {
1065
+ let entry = entries[eUid];
1066
+ let envId = [];
1067
+ let locales = [];
1068
+ if (entry.publish_details && entry.publish_details.length > 0) {
1069
+ _.forEach(entries[eUid].publish_details, (pubObject) => {
1070
+ if (
1071
+ self.environment.hasOwnProperty(pubObject.environment) &&
1072
+ _.indexOf(envId, self.environment[pubObject.environment].name) === -1
1073
+ ) {
1074
+ envId.push(self.environment[pubObject.environment].name);
1074
1075
  }
1075
- }
1076
- });
1076
+ if (pubObject.locale) {
1077
+ let idx = _.indexOf(locales, pubObject.locale);
1078
+ if (idx === -1) {
1079
+ locales.push(pubObject.locale);
1080
+ }
1081
+ }
1082
+ });
1077
1083
 
1078
- let entryUid = entryMapper[eUid];
1079
- if (entryUid) {
1080
- requestObject.entry.environments = envId;
1081
- requestObject.entry.locales = locales;
1082
- return new Promise((resolveEntryPublished, rejectEntryPublished) => {
1083
- self.stackAPIClient
1084
- .contentType(ctUid)
1085
- .entry(entryUid)
1086
- .publish({ publishDetails: requestObject.entry, locale: lang })
1087
- // eslint-disable-next-line max-nested-callbacks
1088
- .then((result) => {
1089
- // addlogs(this.config, 'Entry ' + eUid + ' published successfully in ' + ctUid + ' content type', 'success')
1090
- addlogs(
1091
- this.config,
1092
- `Entry '${eUid}' published successfully in '${ctUid}' content type`,
1093
- 'success',
1094
- );
1095
- return resolveEntryPublished(result);
1084
+ let entryUid = entryMapper[eUid];
1085
+ if (entryUid) {
1086
+ requestObject.entry.environments = envId;
1087
+ requestObject.entry.locales = locales;
1088
+ return new Promise((resolveEntryPublished, rejectEntryPublished) => {
1089
+ self.stackAPIClient
1090
+ .contentType(ctUid)
1091
+ .entry(entryUid)
1092
+ .publish({ publishDetails: requestObject.entry, locale: lang })
1096
1093
  // eslint-disable-next-line max-nested-callbacks
1097
- })
1098
- .catch((err) => {
1099
- addlogs(
1100
- this.config,
1101
- `failed to publish entry '${eUid}' content type '${ctUid}' ${util.formatError(err)}`,
1102
- 'error'
1103
- );
1104
- return resolveEntryPublished('');
1105
- });
1106
- });
1094
+ .then((result) => {
1095
+ // addlogs(this.config, 'Entry ' + eUid + ' published successfully in ' + ctUid + ' content type', 'success')
1096
+ addlogs(
1097
+ this.config,
1098
+ `Entry '${eUid}' published successfully in '${ctUid}' content type`,
1099
+ 'success',
1100
+ );
1101
+ return resolveEntryPublished(result);
1102
+ // eslint-disable-next-line max-nested-callbacks
1103
+ })
1104
+ .catch((err) => {
1105
+ addlogs(
1106
+ this.config,
1107
+ `failed to publish entry '${eUid}' content type '${ctUid}' ${util.formatError(
1108
+ err,
1109
+ )}`,
1110
+ 'error',
1111
+ );
1112
+ return resolveEntryPublished('');
1113
+ });
1114
+ });
1115
+ }
1116
+ } else {
1117
+ return {};
1107
1118
  }
1108
- } else {
1109
- return {};
1110
- }
1111
- },
1112
- {
1113
- concurrency: 1,
1114
- },
1115
- )
1116
- .then(() => {
1117
- // empty function
1118
- })
1119
- .catch((error) => {
1120
- // error while executing entry in batch
1121
- addlogs(this.config, util.formatError(error), 'error');
1122
- addlogs(this.config, error, 'error');
1123
- });
1124
- },
1125
- {
1126
- concurrency: 1,
1127
- },
1128
- )
1129
- .then(() => {
1130
- // addlogs(this.config, 'Entries published successfully in ' + ctUid + ' content type', 'success')
1131
- addlogs(this.config, `Entries published successfully in '${ctUid}' content type`, 'info');
1132
- })
1133
- .catch((error) => {
1134
- addlogs(this.config, `failed to publish entry in content type '${ctUid}' ${util.formatError(error)}`, 'error');
1135
- });
1119
+ },
1120
+ {
1121
+ concurrency: 1,
1122
+ },
1123
+ )
1124
+ .then(() => {
1125
+ // empty function
1126
+ })
1127
+ .catch((error) => {
1128
+ // error while executing entry in batch
1129
+ addlogs(this.config, util.formatError(error), 'error');
1130
+ addlogs(this.config, error, 'error');
1131
+ });
1132
+ },
1133
+ {
1134
+ concurrency: 1,
1135
+ },
1136
+ )
1137
+ .then(() => {
1138
+ // addlogs(this.config, 'Entries published successfully in ' + ctUid + ' content type', 'success')
1139
+ addlogs(this.config, `Entries published successfully in '${ctUid}' content type`, 'info');
1140
+ })
1141
+ .catch((error) => {
1142
+ console.log(error);
1143
+ addlogs(
1144
+ this.config,
1145
+ `failed to publish entry in content type '${ctUid}' ${util.formatError(error)}`,
1146
+ 'error',
1147
+ );
1148
+ });
1149
+ }
1136
1150
  },
1137
1151
  {
1138
1152
  concurrency: 1,
@@ -1143,6 +1157,7 @@ module.exports = class ImportEntries {
1143
1157
  // addlogs('Published entries successfully in ' +);
1144
1158
  })
1145
1159
  .catch((error) => {
1160
+ console.log(error);
1146
1161
  addlogs(this.config, `Failed to publish few entries in '${lang}' ${util.formatError(error)}`, 'error');
1147
1162
  });
1148
1163
  },
@@ -1154,7 +1169,7 @@ module.exports = class ImportEntries {
1154
1169
  return resolve();
1155
1170
  })
1156
1171
  .catch((error) => {
1157
- addlogs(this.config,`Failed to publish entries. ${util.formatError(error)}`, 'error');
1172
+ addlogs(this.config, `Failed to publish entries. ${util.formatError(error)}`, 'error');
1158
1173
  });
1159
1174
  });
1160
1175
  }