Skip to content

Commit

Permalink
Merge pull request #1434 from contentstack/staging
Browse files Browse the repository at this point in the history
DX | 11-06-2024 | Release
  • Loading branch information
cs-raj authored Jun 11, 2024
2 parents 8171ace + f47fbe0 commit ea04520
Show file tree
Hide file tree
Showing 17 changed files with 800 additions and 596 deletions.
1,064 changes: 583 additions & 481 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions packages/contentstack-bootstrap/src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ const envFileHandler = async (
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
result = await writeEnvFile(content, filePath);
break;
case 'compass-app':
fileName = '.env';
filePath = pathValidator(path.join(sanitizePath(clonedDirectory), sanitizePath(fileName)));
content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${
environmentVariables.deliveryToken
}\n${
livePreviewEnabled
? `\nCONTENTSTACK_PREVIEW_TOKEN=${
environmentVariables.preview_token || `''`
}\nCONTENTSTACK_PREVIEW_HOST=${previewHost}\nCONTENTSTACK_APP_HOST=${appHost}\n`
: '\n'
}CONTENTSTACK_ENVIRONMENT=${environmentVariables.environment}\nCONTENTSTACK_API_HOST=${
customHost ? customHost : managementAPIHost
}${
!isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : ''
}\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false`;
result = await writeEnvFile(content, filePath);
break;
case 'gatsby':
case 'gatsby-starter':
fileName = `.env.${environmentVariables.environment}`;
Expand Down
5 changes: 5 additions & 0 deletions packages/contentstack-bootstrap/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const config: Configuration = {
{ displayName: 'Vue JS', configKey: 'vue-starter' },
{ displayName: 'Stencil', configKey: 'stencil-starter' },
{ displayName: 'Nuxt3', configKey: 'nuxt3-starter' },
// { displayName: 'Compass App', configKey: 'compass-app' }
],
appLevelConfig: {
nextjs: {
Expand All @@ -47,6 +48,10 @@ const config: Configuration = {
source: 'contentstack/contentstack-angular-modularblock-example',
stack: 'contentstack/stack-contentstack-angular-modularblock-example',
},
'compass-app': {
source: 'SunilLsagar/universal-demo',
stack: 'SunilLsagar/stack-universal-demo',
},
'nuxtjs-disabled': {
source: 'contentstack/contentstack-nuxtjs-vue-universal-demo',
stack: 'shafeeqd959/stack-contentstack-nuxtjs-vue-universal-demo',
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@contentstack/cli-cm-branches",
"description": "Contentstack CLI plugin to do branches operations",
"version": "1.0.26",
"version": "1.1.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.18",
"@contentstack/cli-utilities": "~1.6.2",
"@oclif/core": "^2.9.3",
"@oclif/core": "^3.26.5",
"async": "^3.2.4",
"big-json": "^3.2.0",
"bluebird": "^3.7.2",
Expand Down Expand Up @@ -95,4 +95,4 @@
}
},
"repository": "https://github.com/contentstack/cli"
}
}
41 changes: 31 additions & 10 deletions packages/contentstack-branches/src/utils/entry-create-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,21 +462,42 @@ export function entryCreateScript(contentType) {
}
}
const getEntries = async (branchName, contentType, skip = 0, limit = 100, entries = []) => {
let requestObject = {
skip,
limit,
include_count: true,
};
const entriesSearchResponse = await managementAPIClient
.stack({ api_key: stackSDKInstance.api_key, branch_uid: branchName })
.contentType(contentType)
.entry()
.query(requestObject)
.find();
if (entriesSearchResponse?.items?.length > 0) {
skip += limit || 100;
entries = [...entries, ...entriesSearchResponse.items];
if (skip >= entriesSearchResponse.count) {
return entries;
}
return await getEntries(branchName, contentType, skip, limit, entries);
}
return entries;
};
const createEntryTask = () => {
return {
title: 'Create Entries',
successTitle: 'Entries Created Successfully',
failedTitle: 'Failed to create entries',
task: async () => {
const compareBranchEntries = await managementAPIClient
.stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
.contentType('${contentType}')
.entry()
.query()
.find();
const compareBranchEntries = await getEntries(compareBranch, '${contentType}')
const compareFilteredProperties = compareBranchEntries.items.map((entry) => {
const compareFilteredProperties = compareBranchEntries.map((entry) => {
keysToRemove.map((key) => delete entry[key]);
return entry;
});
Expand All @@ -486,9 +507,9 @@ export function entryCreateScript(contentType) {
.contentType('${contentType}')
.fetch();
for (let i = 0; i < compareBranchEntries?.items?.length; i++) {
assetRefPath[compareBranchEntries.items[i].uid] = []
findAssets(contentType.schema, compareBranchEntries.items[i], assetRefPath[compareBranchEntries.items[i].uid]);
for (let i = 0; i < compareBranchEntries?.length; i++) {
assetRefPath[compareBranchEntries[i].uid] = []
findAssets(contentType.schema, compareBranchEntries[i], assetRefPath[compareBranchEntries[i].uid]);
cAssetDetails = [...new Map(cAssetDetails.map((item) => [item['uid'], item])).values()];
}
if (cAssetDetails && cAssetDetails.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export function entryCreateUpdateScript(contentType) {
function converter(data) {
let arr = [];
for (const elm of data.entries()) {
for (const elm of data) {
// @ts-ignore
arr.push([elm[1].title, elm[1]]);
arr.push([elm.title, elm]);
}
return arr;
}
Expand Down Expand Up @@ -476,35 +476,54 @@ export function entryCreateUpdateScript(contentType) {
}
};
const getEntries = async (branchName, contentType, skip = 0, limit = 100, entries = []) => {
let requestObject = {
skip,
limit,
include_count: true,
};
const entriesSearchResponse = await managementAPIClient
.stack({ api_key: stackSDKInstance.api_key, branch_uid: branchName })
.contentType(contentType)
.entry()
.query(requestObject)
.find();
if (entriesSearchResponse?.items?.length > 0) {
skip += limit || 100;
entries = [...entries, ...entriesSearchResponse.items];
if (skip >= entriesSearchResponse.count) {
return entries;
}
return await getEntries(branchName, contentType, skip, limit, entries);
}
return entries;
};
const updateEntryTask = () => {
return {
title: 'Update Entries',
successMessage: 'Entries Updated Successfully',
failedMessage: 'Failed to update entries',
task: async () => {
let compareBranchEntries = await managementAPIClient
.stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
.contentType('${contentType}')
.entry()
.query()
.find();
let compareBranchEntries = await getEntries(compareBranch, '${contentType}')
let baseBranchEntries = await stackSDKInstance.contentType('${contentType}').entry().query().find();
let baseBranchEntries = await getEntries(branch, '${contentType}');
let contentType = await managementAPIClient
.stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
.contentType('${contentType}')
.fetch();
for (let i = 0; i < compareBranchEntries?.items?.length; i++) {
assetRefPath[compareBranchEntries.items[i].uid] = []
findAssets(contentType.schema, compareBranchEntries.items[i], assetRefPath[compareBranchEntries.items[i].uid]);
for (let i = 0; i < compareBranchEntries?.length; i++) {
assetRefPath[compareBranchEntries[i].uid] = []
findAssets(contentType.schema, compareBranchEntries[i], assetRefPath[compareBranchEntries[i].uid]);
}
for (let i = 0; i < baseBranchEntries?.items?.length; i++) {
assetRefPath[baseBranchEntries.items[i].uid] = []
findAssets(contentType.schema, baseBranchEntries.items[i], assetRefPath[baseBranchEntries.items[i].uid]);
assetRefPath[baseBranchEntries[i].uid] = []
findAssets(contentType.schema, baseBranchEntries[i], assetRefPath[baseBranchEntries[i].uid]);
}
assetDetails = [...new Map(assetDetails.map((item) => [item['uid'], item])).values()];
newAssetDetails = assetDetails;
Expand Down Expand Up @@ -568,12 +587,12 @@ export function entryCreateUpdateScript(contentType) {
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (baseBranchEntries && baseBranchEntries.items.length) {
let baseEntryUid = baseBranchEntries.items[0].uid;
if (baseBranchEntries && baseBranchEntries.length) {
let baseEntryUid = baseBranchEntries[0].uid;
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);
if (flag.references) {
await updateReferences(entryDetails, baseBranchEntries.items[0], references);
await updateReferences(entryDetails, baseBranchEntries[0], references);
}
await updateEntry(entry, entryDetails);
Expand All @@ -589,19 +608,20 @@ export function entryCreateUpdateScript(contentType) {
}
});
} else {
let compareMap = new Map(converter(compareBranchEntries.items));
let baseMap = new Map(converter(baseBranchEntries.items));
let compareMap = new Map(converter(compareBranchEntries));
let baseMap = new Map(converter(baseBranchEntries));
//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);
// Change
for(let i = 0; i < arr.length ; i++){
let entryDetails = deleteUnwantedKeysFromObject(compareMap.get(arr[i]), keysToRemove);
//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)) {
if (compareMap.get(arr[i]) && !baseMap.get(arr[i])) {
let createdEntry = await stackSDKInstance
.contentType('${contentType}')
.entry()
Expand All @@ -613,8 +633,8 @@ export function entryCreateUpdateScript(contentType) {
}
await updateEntry(createdEntry, entryDetails);
}
} else if (compareMap.get(el) && baseMap.get(el)) {
let baseEntry = baseMap.get(el);
} else if (compareMap.get(arr[i]) && baseMap.get(arr[i])) {
let baseEntry = baseMap.get(arr[i]);
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntry.uid);
if (flag.references) {
Expand All @@ -624,7 +644,7 @@ export function entryCreateUpdateScript(contentType) {
await updateEntry(entry, entryDetails);
}
}
});
}
}
} catch (error) {
throw error;
Expand Down
62 changes: 41 additions & 21 deletions packages/contentstack-branches/src/utils/entry-update-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export function entryUpdateScript(contentType) {
function converter(data) {
let arr = [];
for (const elm of data.entries()) {
for (const elm of data) {
// @ts-ignore
arr.push([elm[1].title, elm[1]]);
arr.push([elm.title, elm]);
}
return arr;
}
Expand Down Expand Up @@ -476,35 +476,55 @@ export function entryUpdateScript(contentType) {
}
};
const getEntries = async (branchName, contentType, skip = 0, limit = 100, entries = []) => {
let requestObject = {
skip,
limit,
include_count: true,
};
const entriesSearchResponse = await managementAPIClient
.stack({ api_key: stackSDKInstance.api_key, branch_uid: branchName })
.contentType(contentType)
.entry()
.query(requestObject)
.find();
if (entriesSearchResponse?.items?.length > 0) {
skip += limit || 100;
entries = [...entries, ...entriesSearchResponse.items];
if (skip >= entriesSearchResponse.count) {
return entries;
}
return await getEntries(branchName, contentType, skip, limit, entries);
}
return entries;
};
const updateEntryTask = () => {
return {
title: 'Update Entries',
successMessage: 'Entries Updated Successfully',
failedMessage: 'Failed to update entries',
task: async () => {
let compareBranchEntries = await managementAPIClient
.stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
.contentType('${contentType}')
.entry()
.query()
.find();
let compareBranchEntries = await getEntries(compareBranch, '${contentType}');
let baseBranchEntries = await stackSDKInstance.contentType('${contentType}').entry().query().find();
let baseBranchEntries = await getEntries(branch, '${contentType}');
let contentType = await managementAPIClient
.stack({ api_key: stackSDKInstance.api_key, branch_uid: compareBranch })
.contentType('${contentType}')
.fetch();
for (let i = 0; i < compareBranchEntries?.items?.length; i++) {
assetRefPath[compareBranchEntries.items[i].uid] = []
findAssets(contentType.schema, compareBranchEntries.items[i], assetRefPath[compareBranchEntries.items[i].uid]);
for (let i = 0; i < compareBranchEntries?.length; i++) {
assetRefPath[compareBranchEntries[i].uid] = []
findAssets(contentType.schema, compareBranchEntries[i], assetRefPath[compareBranchEntries[i].uid]);
}
for (let i = 0; i < baseBranchEntries?.items?.length; i++) {
assetRefPath[baseBranchEntries.items[i].uid] = []
findAssets(contentType.schema, baseBranchEntries.items[i], assetRefPath[baseBranchEntries.items[i].uid]);
for (let i = 0; i < baseBranchEntries?.length; i++) {
assetRefPath[baseBranchEntries[i].uid] = []
findAssets(contentType.schema, baseBranchEntries[i], assetRefPath[baseBranchEntries[i].uid]);
}
assetDetails = [...new Map(assetDetails.map((item) => [item['uid'], item])).values()];
newAssetDetails = assetDetails;
Expand Down Expand Up @@ -561,16 +581,16 @@ export function entryUpdateScript(contentType) {
try {
if (contentType?.options?.singleton) {
compareBranchEntries?.items?.map(async (el) => {
compareBranchEntries?.map(async (el) => {
let entryDetails = deleteUnwantedKeysFromObject(el, keysToRemove);
if(entryDetails !== undefined){
entryDetails = updateAssetDetailsInEntries(entryDetails);
if (baseBranchEntries && baseBranchEntries.items.length) {
let baseEntryUid = baseBranchEntries.items[0].uid;
if (baseBranchEntries && baseBranchEntries.length) {
let baseEntryUid = baseBranchEntries[0].uid;
let entry = await stackSDKInstance.contentType('${contentType}').entry(baseEntryUid);
if (flag.references) {
await updateReferences(entryDetails, baseBranchEntries.items[0], references);
await updateReferences(entryDetails, baseBranchEntries[0], references);
}
await updateEntry(entry, entryDetails);
Expand All @@ -586,8 +606,8 @@ export function entryUpdateScript(contentType) {
}
});
} else {
let compareMap = new Map(converter(compareBranchEntries.items));
let baseMap = new Map(converter(baseBranchEntries.items));
let compareMap = new Map(converter(compareBranchEntries));
let baseMap = new Map(converter(baseBranchEntries));
//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
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@colors/colors": "^1.5.0",
"@contentstack/cli-cm-export": "~1.11.4",
"@contentstack/cli-cm-import": "~1.15.6",
"@contentstack/cli-cm-import": "~1.15.7",
"@contentstack/cli-command": "~1.2.18",
"@contentstack/cli-utilities": "~1.6.2",
"async": "^3.2.4",
Expand Down Expand Up @@ -72,4 +72,4 @@
"cm:stack-clone": "O-CLN"
}
}
}
}
Loading

0 comments on commit ea04520

Please sign in to comment.