Skip to content

Commit

Permalink
Merge pull request #993 from contentstack/release/12171
Browse files Browse the repository at this point in the history
Release/12171
  • Loading branch information
abhinav-from-contentstack authored Aug 23, 2023
2 parents c005a13 + 63413c7 commit 5ab00e4
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 31 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/contentstack-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-auth/1.3.12 darwin-arm64 node-v18.11.0
@contentstack/cli-auth/1.3.12 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bootstrap/1.4.14 darwin-arm64 node-v18.11.0
@contentstack/cli-cm-bootstrap/1.4.14 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.0.10 darwin-arm64 node-v18.11.0
@contentstack/cli-cm-branches/1.0.10 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bulk-publish/1.3.10 darwin-arm64 node-v18.11.0
@contentstack/cli-cm-bulk-publish/1.3.10 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-clone/1.4.15 darwin-arm64 node-v18.11.0
@contentstack/cli-cm-clone/1.4.15 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-config/1.4.10 darwin-arm64 node-v18.11.0
@contentstack/cli-config/1.4.10 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-export/1.8.0 darwin-arm64 node-v18.11.0
@contentstack/cli-cm-export/1.8.0 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import/1.8.0 darwin-arm64 node-v18.11.0
@contentstack/cli-cm-import/1.8.1 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
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.8.0",
"version": "1.8.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
21 changes: 14 additions & 7 deletions packages/contentstack-import/src/import/modules-js/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ module.exports = class ImportEntries {
} else {
log(
this.config,
`Failed to create an entry '${eUid}' ${formatError(error)} Title of the failed entry: '${
entries[eUid].title
}'`,
`Failed to create an entry '${eUid}' ${formatError(
error,
)} Title of the failed entry: '${entries[eUid].title}'`,
'error',
);
}
Expand Down Expand Up @@ -498,15 +498,15 @@ module.exports = class ImportEntries {
return resolve();
})
.catch((error) => {
let title = JSON.parse(error?.request?.data ||"{}").entry?.title
let title = JSON.parse(error?.request?.data || '{}').entry?.title;
addlogs(
this.config,
chalk.red(
"Failed to create entries in '" +
lang +
"' language. " +
'Title of the failed entry: ' +
`'${title||""}'`,
`'${title || ''}'`,
),
'error',
);
Expand Down Expand Up @@ -991,9 +991,9 @@ module.exports = class ImportEntries {
if (schema.field_rules) {
let fieldRuleLength = schema.field_rules.length;
const fieldDatatypeMap = {};
for (let i = 0; i < schema.schema.length ; i++) {
for (let i = 0; i < schema.schema.length; i++) {
const field = schema.schema[i].uid;
fieldDatatypeMap[field] = schema.schema[i].data_type;
fieldDatatypeMap[field] = schema.schema[i].data_type;
}
for (let k = 0; k < fieldRuleLength; k++) {
let fieldRuleConditionLength = schema.field_rules[k].conditions.length;
Expand Down Expand Up @@ -1218,13 +1218,17 @@ module.exports = class ImportEntries {
break;
}
case 'json': {
const structuredPTag = '{"type":"p","attrs":{},"children":[{"text":""}]}';
if (entry[element.uid] && element.field_metadata.rich_text_type) {
if (element.multiple) {
entry[element.uid] = entry[element.uid].map((jsonRteData) => {
// repeated code from else block, will abstract later
let entryReferences = jsonRteData.children.filter((e) => this.doEntryReferencesExist(e));
if (entryReferences.length > 0) {
jsonRteData.children = jsonRteData.children.filter((e) => !this.doEntryReferencesExist(e));
if (jsonRteData.children.length === 0) {
jsonRteData.children.push(JSON.parse(structuredPTag));
}
return jsonRteData; // return jsonRteData without entry references
} else {
return jsonRteData; // return jsonRteData as it is, because there are no entry references
Expand All @@ -1236,6 +1240,9 @@ module.exports = class ImportEntries {
entry[element.uid].children = entry[element.uid].children.filter(
(e) => !this.doEntryReferencesExist(e),
);
if (entry[element.uid].children.length === 0) {
entry[element.uid].children.push(JSON.parse(structuredPTag));
}
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion packages/contentstack-import/src/utils/asset-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export const lookupAssets = function (
) {
parent.push(schema[i].uid);
findFileUrls(schema[i], entryToFind, assetUrls);
if (schema[i].field_metadata.rich_text_type) {
findAssetIdsFromHtmlRte(entryToFind, schema[i]);
}
parent.pop();
}
if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
Expand Down Expand Up @@ -145,6 +148,15 @@ export const lookupAssets = function (
});
}

function findAssetIdsFromHtmlRte(entryObj: any, ctSchema: any) {
const regex = /<img asset_uid=\\"([^"]+)\\"/g;
let match;
const entry = JSON.stringify(entryObj);
while ((match = regex.exec(entry)) !== null) {
assetUids.push(match[1]);
}
}

function findAssetIdsFromJsonRte(entryObj: any, ctSchema: any) {
for (const element of ctSchema) {
switch (element.data_type) {
Expand Down Expand Up @@ -350,7 +362,8 @@ function findFileUrls(schema: any, _entry: any, assetUrls: any) {
);
while ((markdownMatch = markdownRegEx.exec(text)) !== null) {
if (markdownMatch && typeof markdownMatch[0] === 'string') {
assetUrls.push(markdownMatch[0]);
let assetUrl = markdownMatch[0].replace(/\\/g, '');
assetUrls.push(assetUrl);
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions packages/contentstack-import/src/utils/content-type-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const removeReferenceFields = async function (
for (var block in schema[i].blocks) {
await removeReferenceFields(schema[i].blocks[block].schema, flag, stackAPIClient);
}
} else if (schema[i].data_type === 'reference' || schema[i].reference_to) {
} else if (schema[i].data_type === 'reference') {
flag.supressed = true;
// Check if content-type exists
// If exists, then no change should be required.
Expand Down Expand Up @@ -128,7 +128,15 @@ export const removeReferenceFields = async function (
});
}
}
return true;
} else if (
// handling entry references in json rte
schema[i].data_type === 'json' &&
schema[i].field_metadata.allow_json_rte &&
schema[i].field_metadata.embed_entry &&
schema[i].reference_to.length > 1
) {
flag.supressed = true;
schema[i].reference_to = ['sys_assets'];
} else if (
// handling entry references in json rte
schema[i].data_type === 'json' &&
Expand All @@ -138,7 +146,6 @@ export const removeReferenceFields = async function (
) {
flag.supressed = true;
schema[i].reference_to = ['sys_assets'];
return true;
}
}
};
7 changes: 7 additions & 0 deletions packages/contentstack-import/src/utils/entries-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,17 @@ export const removeEntryRefsFromJSONRTE = (entry: Record<string, any>, ctSchema:
break;
}
case 'json': {
const structuredPTag = '{"type":"p","attrs":{},"children":[{"text":""}]}';
if (entry[element.uid] && element.field_metadata.rich_text_type) {
if (element.multiple) {
entry[element.uid] = entry[element.uid].map((jsonRteData: any) => {
// repeated code from else block, will abstract later
let entryReferences = jsonRteData.children.filter((e: any) => doEntryReferencesExist(e));
if (entryReferences.length > 0) {
jsonRteData.children = jsonRteData.children.filter((e: any) => !doEntryReferencesExist(e));
if (jsonRteData.children.length === 0) { // empty children array are no longer acceptable by the API, a default structure must be there
jsonRteData.children.push(JSON.parse(structuredPTag));
}
return jsonRteData; // return jsonRteData without entry references
} else {
return jsonRteData; // return jsonRteData as it is, because there are no entry references
Expand All @@ -389,6 +393,9 @@ export const removeEntryRefsFromJSONRTE = (entry: Record<string, any>, ctSchema:
let entryReferences = entry[element.uid].children.filter((e: any) => doEntryReferencesExist(e));
if (entryReferences.length > 0) {
entry[element.uid].children = entry[element.uid].children.filter((e: any) => !doEntryReferencesExist(e));
if (entry[element.uid].children.length === 0) {
entry[element.uid].children.push(JSON.parse(structuredPTag));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-launch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-launch
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-launch/1.0.10 darwin-arm64 node-v18.11.0
@contentstack/cli-launch/1.0.10 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-migrate-rte/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-migrate-rte
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-migrate-rte/1.4.10 darwin-arm64 node-v18.11.0
@contentstack/cli-cm-migrate-rte/1.4.10 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $ npm install -g @contentstack/cli-migration
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-migration/1.3.10 darwin-arm64 node-v18.11.0
@contentstack/cli-migration/1.3.10 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli/1.8.0 darwin-arm64 node-v18.11.0
@contentstack/cli/1.8.1 darwin-arm64 node-v20.3.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 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.8.0",
"version": "1.8.1",
"author": "Contentstack",
"bin": {
"csdx": "./bin/run"
Expand All @@ -28,7 +28,7 @@
"@contentstack/cli-cm-clone": "~1.4.15",
"@contentstack/cli-cm-export": "~1.8.0",
"@contentstack/cli-cm-export-to-csv": "~1.3.12",
"@contentstack/cli-cm-import": "~1.8.0",
"@contentstack/cli-cm-import": "~1.8.1",
"@contentstack/cli-cm-migrate-rte": "~1.4.10",
"@contentstack/cli-cm-seed": "~1.4.14",
"@contentstack/cli-command": "~1.2.11",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

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

0 comments on commit 5ab00e4

Please sign in to comment.