@contentstack/cli-cm-import 1.5.9 → 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 +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
- package/src/app.js +19 -8
- package/src/lib/import/entries.js +120 -105
- package/src/lib/util/removeReferenceFields.js +2 -2
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
|
|
|
47
47
|
$ csdx COMMAND
|
|
48
48
|
running command...
|
|
49
49
|
$ csdx (--version)
|
|
50
|
-
@contentstack/cli-cm-import/1.5.
|
|
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
|
package/oclif.manifest.json
CHANGED
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.
|
|
4
|
+
"version": "1.5.11",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"bluebird": "^3.7.2",
|
|
13
13
|
"chalk": "^4.1.2",
|
|
14
14
|
"debug": "^4.1.0",
|
|
15
|
+
"fs-extra": "^11.1.1",
|
|
15
16
|
"lodash": "^4.17.20",
|
|
16
17
|
"marked": "^4.0.17",
|
|
17
18
|
"mkdirp": "^1.0.4",
|
|
18
|
-
"ncp": "^2.0.0",
|
|
19
19
|
"promise-limit": "^2.7.0",
|
|
20
20
|
"winston": "^3.7.2"
|
|
21
21
|
},
|
package/src/app.js
CHANGED
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const fs = require('fs');
|
|
8
|
-
const
|
|
8
|
+
const os = require('os');
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const chalk = require('chalk');
|
|
11
|
+
const { copy, copySync, removeSync } = require('fs-extra');
|
|
11
12
|
const util = require('./lib/util/index');
|
|
12
13
|
const login = require('./lib/util/login');
|
|
13
14
|
const { addlogs } = require('./lib/util/log');
|
|
14
15
|
const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
|
|
16
|
+
const { camelCase } = require('lodash')
|
|
15
17
|
|
|
16
18
|
exports.initial = (configData) => {
|
|
17
19
|
return new Promise(async (resolve, reject) => {
|
|
@@ -161,21 +163,30 @@ const createBackup = (backupDirPath, config) => {
|
|
|
161
163
|
if (config.hasOwnProperty('useBackedupDir') && fs.existsSync(config.useBackedupDir)) {
|
|
162
164
|
return resolve(config.useBackedupDir);
|
|
163
165
|
}
|
|
164
|
-
|
|
166
|
+
|
|
165
167
|
if (path.isAbsolute(config.data)) {
|
|
166
|
-
|
|
168
|
+
copy(config.data, backupDirPath, (error) => {
|
|
167
169
|
if (error) {
|
|
168
170
|
return reject(error);
|
|
169
171
|
}
|
|
170
172
|
return resolve(backupDirPath);
|
|
171
173
|
});
|
|
172
174
|
} else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
//handle mac error :- Cannot copy to a subdirectory of itself
|
|
176
|
+
if (config.data === "." || config.data === "./") {
|
|
177
|
+
const tempDestination = `${os.platform() === 'darwin' ? '/private/tmp' : '/tmp'}/${camelCase(backupDirPath)}`;
|
|
178
|
+
copySync(config.data, tempDestination);
|
|
179
|
+
copySync(tempDestination, backupDirPath);
|
|
180
|
+
removeSync(tempDestination);
|
|
177
181
|
return resolve(backupDirPath);
|
|
178
|
-
}
|
|
182
|
+
} else {
|
|
183
|
+
copy(config.data, backupDirPath,(error) => {
|
|
184
|
+
if (error) {
|
|
185
|
+
return reject(error);
|
|
186
|
+
}
|
|
187
|
+
return resolve(backupDirPath);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
179
190
|
}
|
|
180
191
|
});
|
|
181
192
|
};
|
|
@@ -103,7 +103,11 @@ module.exports = class ImportEntries {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
} catch (error) {
|
|
106
|
-
addlogs(
|
|
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
|
|
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: '${
|
|
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
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
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
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
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
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
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
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
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
|
-
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
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
|
|
1172
|
+
addlogs(this.config, `Failed to publish entries. ${util.formatError(error)}`, 'error');
|
|
1158
1173
|
});
|
|
1159
1174
|
});
|
|
1160
1175
|
}
|
|
@@ -4,12 +4,12 @@ const _ = require('lodash');
|
|
|
4
4
|
const removeReferenceFields = (module.exports = async function (schema, flag, stackAPIClient) {
|
|
5
5
|
for (let i = 0; i < schema.length; i++) {
|
|
6
6
|
if (schema[i].data_type === 'group') {
|
|
7
|
-
|
|
7
|
+
removeReferenceFields(schema[i].schema, flag);
|
|
8
8
|
} else if (schema[i].data_type === 'blocks') {
|
|
9
9
|
for (var block in schema[i].blocks) {
|
|
10
10
|
removeReferenceFields(schema[i].blocks[block].schema, flag);
|
|
11
11
|
}
|
|
12
|
-
} else if (schema[i].data_type === 'reference') {
|
|
12
|
+
} else if (schema[i].data_type === 'reference' || schema[i].reference_to ) {
|
|
13
13
|
flag.supressed = true;
|
|
14
14
|
// Check if content-type exists
|
|
15
15
|
// If exists, then no change should be required.
|