@contentstack/cli-cm-import 1.14.2 → 1.15.0
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/lib/import/module-importer.js +1 -0
- package/lib/import/modules/entries.d.ts +2 -0
- package/lib/import/modules/entries.js +24 -1
- package/lib/types/default-config.d.ts +1 -0
- package/lib/utils/asset-helper.js +3 -2
- package/lib/utils/content-type-helper.js +5 -0
- package/lib/utils/entries-helper.js +38 -0
- package/oclif.manifest.json +1 -1
- package/package.json +4 -4
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.
|
|
50
|
+
@contentstack/cli-cm-import/1.15.0 linux-x64 node-v18.19.1
|
|
51
51
|
$ csdx --help [COMMAND]
|
|
52
52
|
USAGE
|
|
53
53
|
$ csdx COMMAND
|
|
@@ -99,6 +99,7 @@ class ModuleImporter {
|
|
|
99
99
|
const basePath = (0, path_1.resolve)(this.importConfig.backupDir, 'logs', 'audit');
|
|
100
100
|
const auditConfig = this.importConfig.auditConfig;
|
|
101
101
|
auditConfig.config.basePath = basePath;
|
|
102
|
+
auditConfig.config.branch = this.importConfig.branchName;
|
|
102
103
|
try {
|
|
103
104
|
const args = [
|
|
104
105
|
'--data-dir',
|
|
@@ -36,6 +36,8 @@ export default class EntriesImport extends BaseClass {
|
|
|
36
36
|
private autoCreatedEntries;
|
|
37
37
|
private taxonomiesPath;
|
|
38
38
|
taxonomies: Record<string, unknown>;
|
|
39
|
+
rteCTs: any;
|
|
40
|
+
rteCTsWithRef: any;
|
|
39
41
|
constructor({ importConfig, stackAPIClient }: ModuleClassParams);
|
|
40
42
|
start(): Promise<any>;
|
|
41
43
|
disableMandatoryCTReferences(): Promise<void>;
|
|
@@ -37,6 +37,8 @@ class EntriesImport extends base_class_1.default {
|
|
|
37
37
|
this.envs = {};
|
|
38
38
|
this.autoCreatedEntries = [];
|
|
39
39
|
this.failedEntries = [];
|
|
40
|
+
this.rteCTs = [];
|
|
41
|
+
this.rteCTsWithRef = [];
|
|
40
42
|
}
|
|
41
43
|
async start() {
|
|
42
44
|
var _a;
|
|
@@ -150,6 +152,8 @@ class EntriesImport extends base_class_1.default {
|
|
|
150
152
|
references: false,
|
|
151
153
|
jsonRte: false,
|
|
152
154
|
jsonRteEmbeddedEntries: false,
|
|
155
|
+
rte: false,
|
|
156
|
+
rteEmbeddedEntries: false,
|
|
153
157
|
};
|
|
154
158
|
(0, utils_1.suppressSchemaReference)(contentType.schema, flag);
|
|
155
159
|
if (flag.references) {
|
|
@@ -164,6 +168,15 @@ class EntriesImport extends base_class_1.default {
|
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
}
|
|
171
|
+
if (flag.rte) {
|
|
172
|
+
this.rteCTs.push(contentType.uid);
|
|
173
|
+
if (flag.rteEmbeddedEntries) {
|
|
174
|
+
this.rteCTsWithRef.push(contentType.uid);
|
|
175
|
+
if (this.refCTs.indexOf(contentType.uid) === -1) {
|
|
176
|
+
this.refCTs.push(contentType.uid);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
167
180
|
// Check if suppress modified flag
|
|
168
181
|
if (flag.suppressed) {
|
|
169
182
|
this.modifiedCTs.push((0, lodash_1.find)(this.cTs, { uid: contentType.uid }));
|
|
@@ -318,6 +331,12 @@ class EntriesImport extends base_class_1.default {
|
|
|
318
331
|
if (this.jsonRteCTsWithRef.indexOf(cTUid) > -1) {
|
|
319
332
|
entry = (0, utils_1.removeEntryRefsFromJSONRTE)(entry, contentType.schema);
|
|
320
333
|
}
|
|
334
|
+
if (this.rteCTs.indexOf(cTUid) > -1) {
|
|
335
|
+
entry = (0, utils_1.removeEntryRefsFromJSONRTE)(entry, contentType.schema);
|
|
336
|
+
}
|
|
337
|
+
if (this.rteCTsWithRef.indexOf(cTUid) > -1) {
|
|
338
|
+
entry = (0, utils_1.removeEntryRefsFromJSONRTE)(entry, contentType.schema);
|
|
339
|
+
}
|
|
321
340
|
//will remove term if term doesn't exists in taxonomy
|
|
322
341
|
(0, utils_1.lookUpTerms)(contentType === null || contentType === void 0 ? void 0 : contentType.schema, entry, this.taxonomies, this.importConfig);
|
|
323
342
|
// will replace all old asset uid/urls with new ones
|
|
@@ -536,7 +555,7 @@ class EntriesImport extends base_class_1.default {
|
|
|
536
555
|
// Removing temp values
|
|
537
556
|
delete entry.sourceEntryFilePath;
|
|
538
557
|
delete entry.entryOldUid;
|
|
539
|
-
if (this.jsonRteCTs.indexOf(cTUid) > -1) {
|
|
558
|
+
if (this.jsonRteCTs.indexOf(cTUid) > -1 || this.rteCTs.indexOf(cTUid) > -1) {
|
|
540
559
|
// the entries stored in eSuccessFilePath, have the same uids as the entries from source data
|
|
541
560
|
entry = (0, utils_1.restoreJsonRteEntryRefs)(entry, sourceEntry, contentType.schema, {
|
|
542
561
|
uidMapper: this.entriesUidMapper,
|
|
@@ -544,6 +563,10 @@ class EntriesImport extends base_class_1.default {
|
|
|
544
563
|
mappedAssetUrls: this.assetUrlMapper,
|
|
545
564
|
});
|
|
546
565
|
}
|
|
566
|
+
entry = (0, utils_1.lookupAssets)({
|
|
567
|
+
content_type: contentType,
|
|
568
|
+
entry: entry,
|
|
569
|
+
}, this.assetUidMapper, this.assetUrlMapper, path.join(this.entriesPath, cTUid), this.installedExtensions);
|
|
547
570
|
entry = (0, utils_1.lookupEntries)({
|
|
548
571
|
content_type: contentType,
|
|
549
572
|
entry,
|
|
@@ -11,6 +11,7 @@ let _ = require('lodash');
|
|
|
11
11
|
let { marked } = require('marked');
|
|
12
12
|
let helper = require('./file-helper');
|
|
13
13
|
const MAX_RETRY_LIMIT = 5;
|
|
14
|
+
const escapeRegExp = (str) => str.replace(/[*+?^${}()|[\]\\]/g, '\\$&');
|
|
14
15
|
function validate(req) {
|
|
15
16
|
if (typeof req !== 'object') {
|
|
16
17
|
throw new Error(`Invalid params passed for request\n${JSON.stringify(arguments)}`);
|
|
@@ -234,8 +235,8 @@ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidM
|
|
|
234
235
|
assetUrls.forEach(function (assetUrl) {
|
|
235
236
|
let mappedAssetUrl = mappedAssetUrls[assetUrl];
|
|
236
237
|
if (typeof mappedAssetUrl !== 'undefined') {
|
|
237
|
-
const sanitizedUrl = (
|
|
238
|
-
const escapedMappedUrl = (
|
|
238
|
+
const sanitizedUrl = escapeRegExp(assetUrl).replace(/\.\./g, '\\$&');
|
|
239
|
+
const escapedMappedUrl = escapeRegExp(mappedAssetUrl).replace(/\.\./g, '\\$&');
|
|
239
240
|
entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl);
|
|
240
241
|
matchedUrls.push(mappedAssetUrl);
|
|
241
242
|
}
|
|
@@ -68,6 +68,11 @@ const suppressSchemaReference = function (schema, flag) {
|
|
|
68
68
|
if (schema[i].field_metadata.embed_entry === true)
|
|
69
69
|
flag.jsonRteEmbeddedEntries = true;
|
|
70
70
|
}
|
|
71
|
+
else if (schema[i].data_type === 'text' && schema[i].field_metadata.rich_text_type) {
|
|
72
|
+
flag.rte = true;
|
|
73
|
+
if (schema[i].field_metadata.embed_entry === true)
|
|
74
|
+
flag.rteEmbeddedEntries = true;
|
|
75
|
+
}
|
|
71
76
|
if ((schema[i].hasOwnProperty('mandatory') && schema[i].mandatory) ||
|
|
72
77
|
(schema[i].hasOwnProperty('unique') && schema[i].unique)) {
|
|
73
78
|
if (schema[i].uid !== 'title') {
|
|
@@ -418,6 +418,21 @@ const removeEntryRefsFromJSONRTE = (entry, ctSchema = []) => {
|
|
|
418
418
|
}
|
|
419
419
|
break;
|
|
420
420
|
}
|
|
421
|
+
case 'text': {
|
|
422
|
+
if (entry[element.uid] && element.field_metadata.rich_text_type) {
|
|
423
|
+
if (element.multiple) {
|
|
424
|
+
let rteContent = [];
|
|
425
|
+
for (let i = 0; i < entry[element.uid].length; i++) {
|
|
426
|
+
rteContent.push('<p></p>');
|
|
427
|
+
}
|
|
428
|
+
entry[element.uid] = rteContent;
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
entry[element.uid] = '<p></p>';
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
421
436
|
}
|
|
422
437
|
}
|
|
423
438
|
return entry;
|
|
@@ -525,11 +540,34 @@ const restoreJsonRteEntryRefs = (entry, sourceStackEntry, ctSchema = [], { uidMa
|
|
|
525
540
|
}
|
|
526
541
|
break;
|
|
527
542
|
}
|
|
543
|
+
case 'text': {
|
|
544
|
+
if (entry[element.uid] && element.field_metadata.rich_text_type) {
|
|
545
|
+
entry[element.uid] = sourceStackEntry[element.uid];
|
|
546
|
+
const matches = Object.keys(uidMapper).filter((uid) => {
|
|
547
|
+
if (sourceStackEntry[element.uid].indexOf(uid) !== -1)
|
|
548
|
+
return uid;
|
|
549
|
+
});
|
|
550
|
+
if (element.multiple && Array.isArray(entry[element.uid])) {
|
|
551
|
+
for (let i = 0; i < matches.length; i++) {
|
|
552
|
+
entry[element.uid] = entry[element.uid].map((el) => updateUids(el, matches[i], uidMapper));
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
for (let i = 0; i < matches.length; i++) {
|
|
557
|
+
entry[element.uid] = updateUids(entry[element.uid], matches[i], uidMapper);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
528
563
|
}
|
|
529
564
|
}
|
|
530
565
|
return entry;
|
|
531
566
|
};
|
|
532
567
|
exports.restoreJsonRteEntryRefs = restoreJsonRteEntryRefs;
|
|
568
|
+
function updateUids(str, match, uidMapper) {
|
|
569
|
+
return str.replace(new RegExp(match, 'g'), (match) => uidMapper[match]);
|
|
570
|
+
}
|
|
533
571
|
function setDirtyTrue(jsonRteChild) {
|
|
534
572
|
// also removing uids in this function
|
|
535
573
|
if (jsonRteChild.type) {
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.15.0",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-audit": "~1.5.
|
|
8
|
+
"@contentstack/cli-audit": "~1.5.1",
|
|
9
9
|
"@contentstack/cli-command": "~1.2.16",
|
|
10
10
|
"@contentstack/cli-utilities": "~1.6.0",
|
|
11
11
|
"@contentstack/management": "~1.15.3",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@types/mocha": "^8.2.2",
|
|
35
35
|
"@types/node": "^14.14.32",
|
|
36
36
|
"@types/sinon": "^10.0.2",
|
|
37
|
-
"@types/tar": "^
|
|
37
|
+
"@types/tar": "^6.1.3",
|
|
38
38
|
"@types/uuid": "^9.0.7",
|
|
39
39
|
"@typescript-eslint/eslint-plugin": "^5.48.2",
|
|
40
40
|
"chai": "^4.2.0",
|
|
@@ -99,4 +99,4 @@
|
|
|
99
99
|
}
|
|
100
100
|
},
|
|
101
101
|
"repository": "https://github.com/contentstack/cli"
|
|
102
|
-
}
|
|
102
|
+
}
|