Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX | 11-06-2024 | Release #1434

Merged
merged 20 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5b4c6d6
fix: Handled pagination during the script creation
cs-raj Jun 3, 2024
dcc2433
minor version bump
cs-raj Jun 3, 2024
86abcc4
variable declaration fix
cs-raj Jun 3, 2024
274d060
fixed the issues with rich text type and bugs in entries helper
cs-raj Jun 4, 2024
989bdd1
fix: handle deprecation warning message
aman19K Jun 4, 2024
628c065
Merge pull request #1422 from contentstack/bugfix/DX-717
cs-raj Jun 4, 2024
aee169d
Merge remote-tracking branch 'origin/development' into fix/DX-647
cs-raj Jun 4, 2024
178da1c
fixed the entry migration script for contentTypes
cs-raj Jun 4, 2024
a9b13c1
Merge pull request #1424 from contentstack/fix/dev
cs-raj Jun 4, 2024
8191a9a
Merge branch 'development' into fix/DX-647
cs-raj Jun 4, 2024
3191808
Merge pull request #1423 from contentstack/fix/DX-647
cs-raj Jun 4, 2024
a034cee
Implemented compass app integration with Seed and Bootstrap command (…
sunil-lakshman Jun 5, 2024
5b8cd04
Merge branch 'development' into fix/DX-51/deprecation-warning
aman19K Jun 5, 2024
430d83a
Merge pull request #1427 from contentstack/fix/DX-51/deprecation-warning
aman19K Jun 5, 2024
8ffd515
Merge pull request #1428 from contentstack/main
harshithad0703 Jun 5, 2024
c88a610
Merge branch 'staging' into staging-to-development
harshithad0703 Jun 5, 2024
66f91b7
Merge pull request #1429 from contentstack/staging-to-development
harshithad0703 Jun 5, 2024
f15d212
fix: Reverted bootstrap changes
cs-raj Jun 7, 2024
3ba452e
Merge pull request #1432 from contentstack/revert/changes
cs-raj Jun 7, 2024
882e103
Merge pull request #1433 from contentstack/development
cs-raj Jun 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading