Skip to content

Commit

Permalink
Merge branch 'development' into feat/CS-44350
Browse files Browse the repository at this point in the history
  • Loading branch information
cs-raj committed Mar 15, 2024
2 parents 1c24e85 + 0ab653b commit 0c503d9
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 407 deletions.
568 changes: 184 additions & 384 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
"dependencies": {
"@contentstack/cli-cm-seed": "~1.7.0",
"@contentstack/cli-cm-seed": "~1.7.3",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.6.0",
"inquirer": "8.2.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@contentstack/cli-cm-clone",
"description": "Contentstack stack clone plugin",
"version": "1.10.2",
"version": "1.10.3",
"author": "Contentstack",
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
"@colors/colors": "^1.5.0",
"@contentstack/cli-cm-export": "~1.11.1",
"@contentstack/cli-cm-import": "~1.14.2",
"@contentstack/cli-cm-import": "~1.15.0",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.6.0",
"async": "^3.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.14.2",
"version": "1.15.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
41 changes: 37 additions & 4 deletions packages/contentstack-import/src/import/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export default class EntriesImport extends BaseClass {
private autoCreatedEntries: Record<string, any>[];
private taxonomiesPath: string;
public taxonomies: Record<string, unknown>;
public rteCTs: any;
public rteCTsWithRef: any;

constructor({ importConfig, stackAPIClient }: ModuleClassParams) {
super({ importConfig, stackAPIClient });
Expand Down Expand Up @@ -85,6 +87,8 @@ export default class EntriesImport extends BaseClass {
this.envs = {};
this.autoCreatedEntries = [];
this.failedEntries = [];
this.rteCTs = [];
this.rteCTsWithRef = [];
}

async start(): Promise<any> {
Expand All @@ -100,8 +104,8 @@ export default class EntriesImport extends BaseClass {

this.assetUidMapper = (fsUtil.readFile(this.assetUidMapperPath) as Record<string, any>) || {};
this.assetUrlMapper = (fsUtil.readFile(this.assetUrlMapperPath) as Record<string, any>) || {};
this.taxonomies = (fsUtil.readFile(this.taxonomiesPath) as Record<string, any>);

this.taxonomies = fsUtil.readFile(this.taxonomiesPath) as Record<string, any>;

fsUtil.makeDirectory(this.entriesMapperPath);
await this.disableMandatoryCTReferences();
Expand Down Expand Up @@ -225,6 +229,8 @@ export default class EntriesImport extends BaseClass {
references: false,
jsonRte: false,
jsonRteEmbeddedEntries: false,
rte: false,
rteEmbeddedEntries: false,
};
suppressSchemaReference(contentType.schema, flag);

Expand All @@ -242,6 +248,16 @@ export default class EntriesImport extends BaseClass {
}
}

if (flag.rte) {
this.rteCTs.push(contentType.uid);
if (flag.rteEmbeddedEntries) {
this.rteCTsWithRef.push(contentType.uid);
if (this.refCTs.indexOf(contentType.uid) === -1) {
this.refCTs.push(contentType.uid);
}
}
}

// Check if suppress modified flag
if (flag.suppressed) {
this.modifiedCTs.push(find(this.cTs, { uid: contentType.uid }));
Expand Down Expand Up @@ -415,6 +431,14 @@ export default class EntriesImport extends BaseClass {
if (this.jsonRteCTsWithRef.indexOf(cTUid) > -1) {
entry = removeEntryRefsFromJSONRTE(entry, contentType.schema);
}

if (this.rteCTs.indexOf(cTUid) > -1) {
entry = removeEntryRefsFromJSONRTE(entry, contentType.schema);
}

if (this.rteCTsWithRef.indexOf(cTUid) > -1) {
entry = removeEntryRefsFromJSONRTE(entry, contentType.schema);
}
//will remove term if term doesn't exists in taxonomy
lookUpTerms(contentType?.schema, entry, this.taxonomies, this.importConfig);
// will replace all old asset uid/urls with new ones
Expand Down Expand Up @@ -668,15 +692,24 @@ export default class EntriesImport extends BaseClass {
// Removing temp values
delete entry.sourceEntryFilePath;
delete entry.entryOldUid;
if (this.jsonRteCTs.indexOf(cTUid) > -1) {
if (this.jsonRteCTs.indexOf(cTUid) > -1 || this.rteCTs.indexOf(cTUid) > -1) {
// the entries stored in eSuccessFilePath, have the same uids as the entries from source data
entry = restoreJsonRteEntryRefs(entry, sourceEntry, contentType.schema, {
uidMapper: this.entriesUidMapper,
mappedAssetUids: this.assetUidMapper,
mappedAssetUrls: this.assetUrlMapper,
});
}

entry = lookupAssets(
{
content_type: contentType,
entry: entry,
},
this.assetUidMapper,
this.assetUrlMapper,
path.join(this.entriesPath, cTUid),
this.installedExtensions,
);
entry = lookupEntries(
{
content_type: contentType,
Expand Down
6 changes: 4 additions & 2 deletions packages/contentstack-import/src/utils/content-type-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export const suppressSchemaReference = function (schema: any, flag: any) {
} else if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) {
flag.jsonRte = true;
if (schema[i].field_metadata.embed_entry === true) flag.jsonRteEmbeddedEntries = true;
} else if (schema[i].data_type === 'text' && schema[i].field_metadata.rich_text_type) {
flag.rte = true;
if (schema[i].field_metadata.embed_entry === true) flag.rteEmbeddedEntries = true;
}

if (
Expand Down Expand Up @@ -146,8 +149,7 @@ export const removeReferenceFields = async function (
) {
flag.supressed = true;
schema[i].reference_to = ['sys_assets'];
}
else if (
} else if (
// handling entry references in rte
schema[i].data_type === 'text' &&
schema[i].field_metadata.rich_text_type &&
Expand Down
40 changes: 39 additions & 1 deletion packages/contentstack-import/src/utils/entries-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,22 @@ export const removeEntryRefsFromJSONRTE = (entry: Record<string, any>, ctSchema:
}
break;
}
case 'text': {
if (entry[element.uid] && element.field_metadata.rich_text_type) {
if (element.multiple) {
let rteContent = [];
for (let i = 0; i < entry[element.uid].length; i++) {
rteContent.push('<p></p>');
}
entry[element.uid] = rteContent;
return entry;
} else {
entry[element.uid] = '<p></p>';
return entry;
}
}
break;
}
}
}
return entry;
Expand Down Expand Up @@ -534,11 +550,33 @@ export const restoreJsonRteEntryRefs = (
}
break;
}
case 'text': {
if (entry[element.uid] && element.field_metadata.rich_text_type) {
entry[element.uid] = sourceStackEntry[element.uid];
const matches = Object.keys(uidMapper).filter((uid) => {
if (sourceStackEntry[element.uid].indexOf(uid) !== -1) return uid;
});
if (element.multiple && Array.isArray(entry[element.uid])) {
for (let i = 0; i < matches.length; i++) {
entry[element.uid] = entry[element.uid].map((el: string) => updateUids(el, matches[i], uidMapper));
}
} else {
for (let i = 0; i < matches.length; i++) {
entry[element.uid] = updateUids(entry[element.uid], matches[i], uidMapper);
}
}
}
break;
}
}
}
return entry;
};

function updateUids(str: string, match: string, uidMapper: Record<string, string>) {
return str.replace(new RegExp(match, 'g'), (match: string) => uidMapper[match]);
}

function setDirtyTrue(jsonRteChild: any) {
// also removing uids in this function
if (jsonRteChild.type) {
Expand Down Expand Up @@ -656,4 +694,4 @@ function restoreReferenceInJsonRTE(
}

return jsonRTE;
}
}
4 changes: 2 additions & 2 deletions packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@contentstack/cli-cm-seed",
"description": "create a Stack from existing content types, entries, assets, etc.",
"version": "1.7.2",
"version": "1.7.3",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-cm-import": "~1.14.2",
"@contentstack/cli-cm-import": "~1.15.0",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.6.0",
"inquirer": "8.2.4",
Expand Down
8 changes: 4 additions & 4 deletions packages/contentstack/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli",
"description": "Command-line tool (CLI) to interact with Contentstack",
"version": "1.16.0",
"version": "1.17.0",
"author": "Contentstack",
"bin": {
"csdx": "./bin/run"
Expand All @@ -28,11 +28,11 @@
"@contentstack/cli-cm-branches": "~1.0.23",
"@contentstack/cli-cm-bulk-publish": "~1.4.3",
"@contentstack/cli-cm-export": "~1.11.1",
"@contentstack/cli-cm-clone": "~1.10.1",
"@contentstack/cli-cm-clone": "~1.10.3",
"@contentstack/cli-cm-export-to-csv": "~1.7.0",
"@contentstack/cli-cm-import": "~1.14.2",
"@contentstack/cli-cm-import": "~1.15.0",
"@contentstack/cli-cm-migrate-rte": "~1.4.15",
"@contentstack/cli-cm-seed": "~1.7.2",
"@contentstack/cli-cm-seed": "~1.7.3",
"@contentstack/cli-command": "~1.2.17",
"@contentstack/cli-config": "~1.6.3",
"@contentstack/cli-launch": "~1.0.17",
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0c503d9

Please sign in to comment.