Skip to content

Commit

Permalink
Merge branch 'development' into fix/CS-41107
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav-from-contentstack committed Sep 4, 2023
2 parents 6952363 + 64ed9bb commit 558b3df
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
6 changes: 3 additions & 3 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-export-to-csv/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-export-to-csv",
"description": "Export entities to csv",
"version": "1.4.0",
"version": "1.4.1",
"author": "Abhinav Gupta @abhinav-from-contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class ExportToCsvCommand extends Command {
const entriesCount = await util.getEntriesCount(stackAPIClient, contentType, language.code);
let flatEntries = [];
for (let index = 0; index < entriesCount / 100; index++) {
const entriesResult = await util.getEntries(stackAPIClient, contentType, language.code, index);
const entriesResult = await util.getEntries(stackAPIClient, contentType, language.code, index, 100);
const flatEntriesResult = util.cleanEntries(
entriesResult.items,
language.code,
Expand Down
29 changes: 18 additions & 11 deletions packages/contentstack-export-to-csv/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function chooseContentType(stackAPIClient, skip) {
let _chooseContentType = [
{
type: 'checkbox',
message: 'Choose Content Type',
message: 'Choose Content Type (Press Space to select the content types) ',
choices: contentTypesList,
name: 'chosenContentTypes',
loop: false,
Expand All @@ -218,7 +218,7 @@ function chooseInMemContentTypes(contentTypesList) {
let _chooseContentType = [
{
type: 'checkbox-plus',
message: 'Choose Content Type',
message: 'Choose Content Type (Press Space to select the content types)',
choices: contentTypesList,
name: 'chosenContentTypes',
loop: false,
Expand Down Expand Up @@ -316,12 +316,12 @@ function getLanguages(stackAPIClient) {
});
}

function getEntries(stackAPIClient, contentType, language, skip) {
function getEntries(stackAPIClient, contentType, language, skip, limit) {
return new Promise((resolve, reject) => {
stackAPIClient
.contentType(contentType)
.entry()
.query({ include_publish_details: true, locale: language, skip: skip * 100 })
.query({ include_publish_details: true, locale: language, skip: skip * 100, limit: limit, include_workflow: true })
.find()
.then((entries) => resolve(entries))
.catch((error) => reject(error));
Expand Down Expand Up @@ -373,25 +373,31 @@ function exitProgram() {

function cleanEntries(entries, language, environments, contentTypeUid) {
const filteredEntries = entries.filter((entry) => {
return entry['locale'] === language && entry.publish_details.length > 0;
return entry['locale'] === language;
});

return filteredEntries.map((entry) => {
let workflow = '';
const envArr = [];
entry.publish_details.forEach((env) => {
envArr.push(JSON.stringify([environments[env['environment']], env['locale'], env['time']]));
});
if(entry.publish_details.length) {
entry.publish_details.forEach((env) => {
envArr.push(JSON.stringify([environments[env['environment']], env['locale'], env['time']]));
});
}

delete entry.publish_details;
delete entry.setWorkflowStage;
if ('_workflow' in entry) {
workflow = entry['_workflow']['name'];
delete entry['_workflow'];
if(entry._workflow?.name) {
workflow = entry['_workflow']['name'];
delete entry['_workflow'];
}
}
entry = flatten(entry);
entry['publish_details'] = envArr;
entry['_workflow'] = workflow;
entry['ACL'] = JSON.stringify({}); // setting ACL to empty obj
entry['content_type_uid'] = contentTypeUid; // content_type_uid is being returned as 'uid' from the sdk for some reason

// entry['url'] might also be wrong
delete entry.stackHeaders;
delete entry.update;
Expand All @@ -403,6 +409,7 @@ function cleanEntries(entries, language, environments, contentTypeUid) {
delete entry.publishRequest;
return entry;
});
console.log(filteredEntries.length);
}

function getDateTime() {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@contentstack/cli-cm-bulk-publish": "~1.3.10",
"@contentstack/cli-cm-clone": "~1.4.15",
"@contentstack/cli-cm-export": "~1.8.0",
"@contentstack/cli-cm-export-to-csv": "~1.4.0",
"@contentstack/cli-cm-export-to-csv": "~1.4.1",
"@contentstack/cli-cm-import": "~1.8.2",
"@contentstack/cli-cm-migrate-rte": "~1.4.10",
"@contentstack/cli-cm-seed": "~1.4.14",
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 558b3df

Please sign in to comment.