Skip to content

Commit

Permalink
Merge pull request #1209 from contentstack/staging-to-dev
Browse files Browse the repository at this point in the history
Merge staging to development
  • Loading branch information
aman19K authored Dec 11, 2023
2 parents c5aa573 + 5ccf2af commit 6384050
Show file tree
Hide file tree
Showing 14 changed files with 283 additions and 183 deletions.
18 changes: 9 additions & 9 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-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.18 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-branches/1.0.19 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-branches",
"description": "Contentstack CLI plugin to do branches operations",
"version": "1.0.18",
"version": "1.0.19",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
18 changes: 10 additions & 8 deletions packages/contentstack-branches/src/utils/entry-create-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,17 @@ export function entryCreateScript(contentType) {
try {
compareFilteredProperties.length !== 0 &&
compareFilteredProperties.forEach(async (entryDetails) => {
entryDetails = updateAssetDetailsInEntries(entryDetails);
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }).catch(error => {
throw error;
});
if(createdEntry){
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails }).catch(error => {
throw error;
});
if(createdEntry){
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
await updateEntry(createdEntry, entryDetails);
}
await updateEntry(createdEntry, entryDetails);
}
});
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,56 +494,70 @@ export function entryCreateUpdateScript(contentType) {
}
try {
if (contentType.options.singleton) {
compareBranchEntries.items.map(async (el) => {
if (contentType?.options?.singleton) {
compareBranchEntries?.items?.map(async (el) => {
let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove);
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (baseBranchEntries && baseBranchEntries.items.length) {
let baseEntryUid = baseBranchEntries.items[0].uid;
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (baseBranchEntries && baseBranchEntries.items.length) {
let baseEntryUid = baseBranchEntries.items[0].uid;
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);
if (flag.references) {
await updateReferences(entryDetails, baseBranchEntries.items[0], references);
}
await updateEntry(entry, entryDetails);
} else {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });
if (flag.references) {
await updateReferences(entryDetails, baseBranchEntries.items[0], references);
}
await updateEntry(entry, entryDetails);
} else {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
await updateEntry(createdEntry, entryDetails);
}
await updateEntry(createdEntry, entryDetails);
}
});
} else {
let compareMap = new Map(converter(compareBranchEntries.items));
let baseMap = new Map(converter(baseBranchEntries.items));
//NOTE: Filter distinct entries from the base and compare branches according to their titles.
//TODO: Need to discuss this approach and replace it with uid condition
let arr = uniquelyConcatenateArrays(Array.from(compareMap.keys()), Array.from(baseMap.keys()));
arr.map(async (el) => {
let entryDetails = deleteUnwantedKeysFromObject(compareMap.get(el), keysToRemove);
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (compareMap.get(el) && !baseMap.get(el)) {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
//NOTE: In the compare branch, entry must exist. Condition of deleted entry not handled
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (compareMap.get(el) && !baseMap.get(el)) {
let createdEntry = await stackSDKInstance
.contentType('${contentType}')
.entry()
.create({ entry: entryDetails })
.catch(err => {
(err?.errorMessage || err?.message) ? err?.errorMessage || err?.message : 'Something went wrong!'
})
if(createdEntry){
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
await updateEntry(createdEntry, entryDetails);
}
} else if (compareMap.get(el) && baseMap.get(el)) {
let baseEntry = baseMap.get(el);
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid);
if (flag.references) {
await updateReferences(entryDetails, baseEntry, references);
}
await updateEntry(createdEntry, entryDetails);
} else if (compareMap.get(el) && baseMap.get(el)) {
let baseEntry = baseMap.get(el);
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid);
if (flag.references) {
await updateReferences(entryDetails, baseEntry, references);
await updateEntry(entry, entryDetails);
}
await updateEntry(entry, entryDetails);
}
});
}
Expand Down
86 changes: 50 additions & 36 deletions packages/contentstack-branches/src/utils/entry-update-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,56 +491,70 @@ export function entryUpdateScript(contentType) {
}
try {
if (contentType.options.singleton) {
compareBranchEntries.items.map(async (el) => {
if (contentType?.options?.singleton) {
compareBranchEntries?.items?.map(async (el) => {
let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove);
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (baseBranchEntries && baseBranchEntries.items.length) {
let baseEntryUid = baseBranchEntries.items[0].uid;
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (baseBranchEntries && baseBranchEntries.items.length) {
let baseEntryUid = baseBranchEntries.items[0].uid;
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);
if (flag.references) {
await updateReferences(entryDetails, baseBranchEntries.items[0], references);
}
await updateEntry(entry, entryDetails);
} else {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });
if (flag.references) {
await updateReferences(entryDetails, baseBranchEntries.items[0], references);
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
await updateEntry(createdEntry, entryDetails);
}
await updateEntry(entry, entryDetails);
} else {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
await updateEntry(createdEntry, entryDetails);
}
});
} else {
let compareMap = new Map(converter(compareBranchEntries.items));
let baseMap = new Map(converter(baseBranchEntries.items));
//NOTE: Filter distinct entries from the base and compare branches according to their titles.
//TODO: Need to discuss this approach and replace it with uid approach
let arr = uniquelyConcatenateArrays(Array.from(compareMap.keys()), Array.from(baseMap.keys()));
arr.map(async (el) => {
let entryDetails = deleteUnwantedKeysFromObject(compareMap.get(el), keysToRemove);
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (compareMap.get(el) && !baseMap.get(el)) {
let createdEntry = await stackSDKInstance.contentType('${contentType}').entry().create({ entry: entryDetails });
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
await updateEntry(createdEntry, entryDetails);
} else if (compareMap.get(el) && baseMap.get(el)) {
let baseEntry = baseMap.get(el);
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid);
//NOTE: In the compare branch, entry must exist. Condition of deleted entry not handled
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (compareMap.get(el) && !baseMap.get(el)) {
let createdEntry = await stackSDKInstance
.contentType('${contentType}')
.entry()
.create({ entry: entryDetails })
.catch(err => {
(err?.errorMessage || err?.message) ? err?.errorMessage || err?.message : 'Something went wrong!'
})
if (flag.references) {
await updateReferences(entryDetails, baseEntry, references);
if(createdEntry){
if (flag.references) {
await updateReferences(entryDetails, createdEntry, references);
}
await updateEntry(createdEntry, entryDetails);
}
} else if (compareMap.get(el) && baseMap.get(el)) {
let baseEntry = baseMap.get(el);
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid);
if (flag.references) {
await updateReferences(entryDetails, baseEntry, references);
}
await updateEntry(entry, entryDetails);
}
await updateEntry(entry, entryDetails);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export default class ImportCommand extends Command {
'success',
);
} catch (error) {
trace(error, 'error', true);
log({ data: backupDir } as ImportConfig, `Failed to import stack content - ${formatError(error)}`, 'error');
log(
{ data: backupDir } as ImportConfig,
Expand Down
16 changes: 8 additions & 8 deletions packages/contentstack-import/src/import/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as path from 'path';
import { isEmpty, values, cloneDeep, find, indexOf, forEach } from 'lodash';
import { ContentType, FsUtility } from '@contentstack/cli-utilities';
import { FsUtility } from '@contentstack/cli-utilities';
import {
fsUtil,
log,
Expand Down Expand Up @@ -125,7 +125,7 @@ export default class EntriesImport extends BaseClass {
await fileHelper.writeLargeFile(path.join(this.entriesMapperPath, 'uid-mapping.json'), this.entriesUidMapper); // TBD: manages mapper in one file, should find an alternative
fsUtil.writeFile(path.join(this.entriesMapperPath, 'failed-entries.json'), this.failedEntries);

if (this.autoCreatedEntries.length > 0) {
if (this.autoCreatedEntries?.length > 0) {
log(this.importConfig, 'Removing entries from master language which got created by default', 'info');
await this.removeAutoCreatedEntries().catch((error) => {
log(
Expand Down Expand Up @@ -528,8 +528,7 @@ export default class EntriesImport extends BaseClass {

async replaceEntriesHandler({
apiParams,
element: entry,
isLastRequest,
element: entry
}: {
apiParams: ApiOptions;
element: Record<string, string>;
Expand Down Expand Up @@ -672,6 +671,7 @@ export default class EntriesImport extends BaseClass {
if (this.jsonRteCTs.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,
});
Expand Down Expand Up @@ -785,13 +785,13 @@ export default class EntriesImport extends BaseClass {
const contentType: any = find(cTs, { uid: cTUid });
if (contentType.field_rules) {
const fieldDatatypeMap: { [key: string]: string } = {};
for (let i = 0; i < contentType.schema.length; i++) {
for (let i = 0; i < contentType.schema?.length; i++) {
const field = contentType.schema[i].uid;
fieldDatatypeMap[field] = contentType.schema[i].data_type;
}
let fieldRuleLength = contentType.field_rules.length;
let fieldRuleLength = contentType.field_rules?.length;
for (let k = 0; k < fieldRuleLength; k++) {
let fieldRuleConditionLength = contentType.field_rules[k].conditions.length;
let fieldRuleConditionLength = contentType.field_rules[k].conditions?.length;
for (let i = 0; i < fieldRuleConditionLength; i++) {
if (fieldDatatypeMap[contentType.field_rules[k].conditions[i].operand_field] === 'reference') {
let fieldRulesValue = contentType.field_rules[k].conditions[i].value;
Expand Down Expand Up @@ -905,7 +905,7 @@ export default class EntriesImport extends BaseClass {
locales: [],
entryUid: this.entriesUidMapper[entry.uid],
};
if (entry.publish_details && entry.publish_details.length > 0) {
if (entry.publish_details && entry.publish_details?.length > 0) {
forEach(entry.publish_details, (pubObject) => {
if (
this.envs.hasOwnProperty(pubObject.environment) &&
Expand Down
9 changes: 9 additions & 0 deletions packages/contentstack-import/src/types/entries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type EntryJsonRTEFieldDataType = {
uid?: string;
type?: string;
text?: string;
attrs?: { 'entry-uid'?: string; type?: string } & Record<string, any>;
children?: EntryJsonRTEFieldDataType[];
};

export { EntryJsonRTEFieldDataType };
2 changes: 2 additions & 0 deletions packages/contentstack-import/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ export interface TermsConfig{

export { default as DefaultConfig } from './default-config';
export { default as ImportConfig } from './import-config';

export * from './entries'
export * from './marketplace-app'
Loading

0 comments on commit 6384050

Please sign in to comment.