@contentstack/cli-cm-import 1.8.0 → 1.8.1
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.8.
|
|
50
|
+
@contentstack/cli-cm-import/1.8.1 linux-x64 node-v18.17.1
|
|
51
51
|
$ csdx --help [COMMAND]
|
|
52
52
|
USAGE
|
|
53
53
|
$ csdx COMMAND
|
|
@@ -395,12 +395,12 @@ module.exports = class ImportEntries {
|
|
|
395
395
|
})
|
|
396
396
|
.catch((error) => {
|
|
397
397
|
var _a, _b;
|
|
398
|
-
let title = (_b = JSON.parse(((_a = error === null || error === void 0 ? void 0 : error.request) === null || _a === void 0 ? void 0 : _a.data) ||
|
|
398
|
+
let title = (_b = JSON.parse(((_a = error === null || error === void 0 ? void 0 : error.request) === null || _a === void 0 ? void 0 : _a.data) || '{}').entry) === null || _b === void 0 ? void 0 : _b.title;
|
|
399
399
|
addlogs(this.config, chalk.red("Failed to create entries in '" +
|
|
400
400
|
lang +
|
|
401
401
|
"' language. " +
|
|
402
402
|
'Title of the failed entry: ' +
|
|
403
|
-
`'${title ||
|
|
403
|
+
`'${title || ''}'`), 'error');
|
|
404
404
|
return reject(error);
|
|
405
405
|
});
|
|
406
406
|
});
|
|
@@ -990,6 +990,7 @@ module.exports = class ImportEntries {
|
|
|
990
990
|
break;
|
|
991
991
|
}
|
|
992
992
|
case 'json': {
|
|
993
|
+
const structuredPTag = '{"type":"p","attrs":{},"children":[{"text":""}]}';
|
|
993
994
|
if (entry[element.uid] && element.field_metadata.rich_text_type) {
|
|
994
995
|
if (element.multiple) {
|
|
995
996
|
entry[element.uid] = entry[element.uid].map((jsonRteData) => {
|
|
@@ -997,6 +998,9 @@ module.exports = class ImportEntries {
|
|
|
997
998
|
let entryReferences = jsonRteData.children.filter((e) => this.doEntryReferencesExist(e));
|
|
998
999
|
if (entryReferences.length > 0) {
|
|
999
1000
|
jsonRteData.children = jsonRteData.children.filter((e) => !this.doEntryReferencesExist(e));
|
|
1001
|
+
if (jsonRteData.children.length === 0) {
|
|
1002
|
+
jsonRteData.children.push(JSON.parse(structuredPTag));
|
|
1003
|
+
}
|
|
1000
1004
|
return jsonRteData; // return jsonRteData without entry references
|
|
1001
1005
|
}
|
|
1002
1006
|
else {
|
|
@@ -1008,6 +1012,9 @@ module.exports = class ImportEntries {
|
|
|
1008
1012
|
let entryReferences = entry[element.uid].children.filter((e) => this.doEntryReferencesExist(e));
|
|
1009
1013
|
if (entryReferences.length > 0) {
|
|
1010
1014
|
entry[element.uid].children = entry[element.uid].children.filter((e) => !this.doEntryReferencesExist(e));
|
|
1015
|
+
if (entry[element.uid].children.length === 0) {
|
|
1016
|
+
entry[element.uid].children.push(JSON.parse(structuredPTag));
|
|
1017
|
+
}
|
|
1011
1018
|
}
|
|
1012
1019
|
}
|
|
1013
1020
|
}
|
|
@@ -75,6 +75,9 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
|
|
|
75
75
|
(schema[i].field_metadata.markdown || schema[i].field_metadata.rich_text_type)) {
|
|
76
76
|
parent.push(schema[i].uid);
|
|
77
77
|
findFileUrls(schema[i], entryToFind, assetUrls);
|
|
78
|
+
if (schema[i].field_metadata.rich_text_type) {
|
|
79
|
+
findAssetIdsFromHtmlRte(entryToFind, schema[i]);
|
|
80
|
+
}
|
|
78
81
|
parent.pop();
|
|
79
82
|
}
|
|
80
83
|
if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
|
|
@@ -131,6 +134,14 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
|
|
|
131
134
|
return row;
|
|
132
135
|
});
|
|
133
136
|
}
|
|
137
|
+
function findAssetIdsFromHtmlRte(entryObj, ctSchema) {
|
|
138
|
+
const regex = /<img asset_uid=\\"([^"]+)\\"/g;
|
|
139
|
+
let match;
|
|
140
|
+
const entry = JSON.stringify(entryObj);
|
|
141
|
+
while ((match = regex.exec(entry)) !== null) {
|
|
142
|
+
assetUids.push(match[1]);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
134
145
|
function findAssetIdsFromJsonRte(entryObj, ctSchema) {
|
|
135
146
|
for (const element of ctSchema) {
|
|
136
147
|
switch (element.data_type) {
|
|
@@ -329,7 +340,8 @@ function findFileUrls(schema, _entry, assetUrls) {
|
|
|
329
340
|
markdownRegEx = new RegExp('(https://(assets|(eu-|azure-na-|azure-eu-)?images).contentstack.(io|com)/v3/assets/(.*?)/(.*?)/(.*?)/(.*?)(?="))', 'g');
|
|
330
341
|
while ((markdownMatch = markdownRegEx.exec(text)) !== null) {
|
|
331
342
|
if (markdownMatch && typeof markdownMatch[0] === 'string') {
|
|
332
|
-
|
|
343
|
+
let assetUrl = markdownMatch[0].replace(/\\/g, '');
|
|
344
|
+
assetUrls.push(assetUrl);
|
|
333
345
|
}
|
|
334
346
|
}
|
|
335
347
|
}
|
|
@@ -89,7 +89,7 @@ const removeReferenceFields = async function (schema, flag = { supressed: false
|
|
|
89
89
|
await (0, exports.removeReferenceFields)(schema[i].blocks[block].schema, flag, stackAPIClient);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
else if (schema[i].data_type === 'reference'
|
|
92
|
+
else if (schema[i].data_type === 'reference') {
|
|
93
93
|
flag.supressed = true;
|
|
94
94
|
// Check if content-type exists
|
|
95
95
|
// If exists, then no change should be required.
|
|
@@ -128,7 +128,15 @@ const removeReferenceFields = async function (schema, flag = { supressed: false
|
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
}
|
|
132
|
+
else if (
|
|
133
|
+
// handling entry references in json rte
|
|
134
|
+
schema[i].data_type === 'json' &&
|
|
135
|
+
schema[i].field_metadata.allow_json_rte &&
|
|
136
|
+
schema[i].field_metadata.embed_entry &&
|
|
137
|
+
schema[i].reference_to.length > 1) {
|
|
138
|
+
flag.supressed = true;
|
|
139
|
+
schema[i].reference_to = ['sys_assets'];
|
|
132
140
|
}
|
|
133
141
|
else if (
|
|
134
142
|
// handling entry references in json rte
|
|
@@ -138,7 +146,6 @@ const removeReferenceFields = async function (schema, flag = { supressed: false
|
|
|
138
146
|
schema[i].reference_to.length > 1) {
|
|
139
147
|
flag.supressed = true;
|
|
140
148
|
schema[i].reference_to = ['sys_assets'];
|
|
141
|
-
return true;
|
|
142
149
|
}
|
|
143
150
|
}
|
|
144
151
|
};
|
|
@@ -372,6 +372,7 @@ const removeEntryRefsFromJSONRTE = (entry, ctSchema) => {
|
|
|
372
372
|
break;
|
|
373
373
|
}
|
|
374
374
|
case 'json': {
|
|
375
|
+
const structuredPTag = '{"type":"p","attrs":{},"children":[{"text":""}]}';
|
|
375
376
|
if (entry[element.uid] && element.field_metadata.rich_text_type) {
|
|
376
377
|
if (element.multiple) {
|
|
377
378
|
entry[element.uid] = entry[element.uid].map((jsonRteData) => {
|
|
@@ -379,6 +380,9 @@ const removeEntryRefsFromJSONRTE = (entry, ctSchema) => {
|
|
|
379
380
|
let entryReferences = jsonRteData.children.filter((e) => doEntryReferencesExist(e));
|
|
380
381
|
if (entryReferences.length > 0) {
|
|
381
382
|
jsonRteData.children = jsonRteData.children.filter((e) => !doEntryReferencesExist(e));
|
|
383
|
+
if (jsonRteData.children.length === 0) { // empty children array are no longer acceptable by the API, a default structure must be there
|
|
384
|
+
jsonRteData.children.push(JSON.parse(structuredPTag));
|
|
385
|
+
}
|
|
382
386
|
return jsonRteData; // return jsonRteData without entry references
|
|
383
387
|
}
|
|
384
388
|
else {
|
|
@@ -390,6 +394,9 @@ const removeEntryRefsFromJSONRTE = (entry, ctSchema) => {
|
|
|
390
394
|
let entryReferences = entry[element.uid].children.filter((e) => doEntryReferencesExist(e));
|
|
391
395
|
if (entryReferences.length > 0) {
|
|
392
396
|
entry[element.uid].children = entry[element.uid].children.filter((e) => !doEntryReferencesExist(e));
|
|
397
|
+
if (entry[element.uid].children.length === 0) {
|
|
398
|
+
entry[element.uid].children.push(JSON.parse(structuredPTag));
|
|
399
|
+
}
|
|
393
400
|
}
|
|
394
401
|
}
|
|
395
402
|
}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED