Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- name: Install dependencies for all plugins
run: |
npm run setup-repo-old
NODE_ENV=PREPACK_MODE npm run setup-repo-old

- name: Run tests for Contentstack Command
working-directory: ./packages/contentstack-command
Expand Down
8 changes: 4 additions & 4 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fileignoreconfig:
- filename: package-lock.json
checksum: 484e310f7e8884916149057a6581e655503d6977021f54da4cfdb31558820ffc
checksum: d3b93fad9630655f037e36b78fea3354f1a038988562254afdad0f6e54ece12d
- filename: pnpm-lock.yaml
checksum: 3cdef03a4cdc334dd5ab432ab9dfa9c35f529ed5f744d5a44a4bff68f1e43ead
checksum: aa6177859aaa87caf2892e8034657fd485c3abe7c13a833fd28449a1d33fa950
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
checksum: 0582d62b88834554cf12951c8690a73ef3ddbb78b82d2804d994cf4148e1ef93
- filename: packages/contentstack-import-setup/test/config.json
Expand Down Expand Up @@ -32,7 +32,7 @@ fileignoreconfig:
- filename: packages/contentstack-import-setup/test/unit/login-handler.test.ts
checksum: e549f9ca3a9aae0d93b7284f7e771d55c0610725ddcb4333612df2f215e92769
- filename: packages/contentstack/README.md
checksum: f46084b199b3b0d7986b363c86a657570def71e5da29b948cc343eaf94ec7e97
checksum: 10f580c697d0b70b813428954b946e60609f41c42e78ca95ca3232443e725615
- filename: packages/contentstack-import-setup/test/unit/modules/assets.test.ts
checksum: 449a5e3383631a6f78d1291aa3c28c91681879289398f0a933158fba5c5d5acf
- filename: packages/contentstack-auth/env.example
Expand Down Expand Up @@ -142,7 +142,7 @@ fileignoreconfig:
- filename: packages/contentstack-export/test/unit/export/modules/stack.test.ts
checksum: bb0f20845d85fd56197f1a8c67b8f71c57dcd1836ed9cfd86d1f49f41e84d3a0
- filename: packages/contentstack-export/test/unit/export/modules/taxonomies.test.ts
checksum: 621c1de129488b6a0372a91056ebb84353bcc642ce06de59e3852cfee8d0ce49
checksum: 5b1d2ba5ec9100fd6174e9c6771b7e49c93a09fa2d6aedadd338e56bc3e3610f
- filename: packages/contentstack-export/test/unit/export/modules/custom-roles.test.ts
checksum: 39f0166a8030ee8f504301f3a42cc71b46ddc027189b90029ef19800b79a46e5
- filename: packages/contentstack-export/test/unit/export/modules/workflows.test.ts
Expand Down
1,439 changes: 647 additions & 792 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-bootstrap",
"description": "Bootstrap contentstack apps",
"version": "1.16.1",
"version": "1.17.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand All @@ -16,12 +16,12 @@
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
"dependencies": {
"@contentstack/cli-cm-seed": "~1.12.2",
"@contentstack/cli-cm-seed": "~1.13.0",
"@contentstack/cli-command": "~1.6.1",
"@contentstack/cli-utilities": "~1.14.4",
"@oclif/core": "^4.3.0",
"@oclif/plugin-help": "^6.2.28",
"inquirer": "8.2.6",
"inquirer": "8.2.7",
"mkdirp": "^1.0.4",
"tar": "^6.2.1 "
},
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@oclif/plugin-help": "^6.2.28",
"chalk": "^4.1.2",
"dotenv": "^16.5.0",
"inquirer": "8.2.6",
"inquirer": "8.2.7",
"lodash": "^4.17.21",
"winston": "^3.17.0"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "@contentstack/cli-cm-clone",
"description": "Contentstack stack clone plugin",
"version": "1.16.1",
"version": "1.17.0",
"author": "Contentstack",
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
"@colors/colors": "^1.6.0",
"@contentstack/cli-cm-export": "~1.20.1",
"@contentstack/cli-cm-import": "~1.28.4",
"@contentstack/cli-cm-export": "~1.21.0",
"@contentstack/cli-cm-import": "~1.29.0",
"@contentstack/cli-command": "~1.6.1",
"@contentstack/cli-utilities": "~1.14.4",
"@oclif/core": "^4.3.0",
"@oclif/plugin-help": "^6.2.28",
"chalk": "^4.1.2",
"inquirer": "8.2.6",
"inquirer": "8.2.7",
"lodash": "^4.17.21",
"merge": "^2.1.1",
"ora": "^5.4.1",
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 @@ -395,7 +395,7 @@ USAGE
[--personalize <value>] [--launch <value>]

ARGUMENTS
REGION Name for the region
[REGION] Name for the region

FLAGS
-d, --cda=<value> Custom host to set for content delivery API, if this flag is added then cma, ui-host and
Expand Down
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.9.1",
"version": "1.10.0",
"author": "Abhinav Gupta @abhinav-from-contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
122 changes: 77 additions & 45 deletions packages/contentstack-export-to-csv/src/commands/cm/export-to-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
cliux,
doesBranchExist,
isManagementTokenValid,
log
} = require('@contentstack/cli-utilities');
const util = require('../../util');
const config = require('../../util/config');
Expand All @@ -18,7 +17,8 @@ class ExportToCsvCommand extends Command {
required: false,
multiple: false,
options: ['entries', 'users', 'teams', 'taxonomies'],
description: 'Option to export data (entries, users, teams, taxonomies). <options: entries|users|teams|taxonomies>',
description:
'Option to export data (entries, users, teams, taxonomies). <options: entries|users|teams|taxonomies>',
}),
alias: flags.string({
char: 'a',
Expand Down Expand Up @@ -67,12 +67,22 @@ class ExportToCsvCommand extends Command {
'taxonomy-uid': flags.string({
description: 'Provide the taxonomy UID of the related terms you want to export.',
}),
'include-fallback': flags.boolean({
description:
"[Optional] Include fallback locale data when exporting taxonomies. When enabled, if a taxonomy term doesn't exist in the specified locale, it will fallback to the hierarchy defined in the branch settings.",
default: false,
}),
'fallback-locale': flags.string({
description:
"[Optional] Specify a specific fallback locale for taxonomy export. This locale will be used when a taxonomy term doesn't exist in the primary locale. Takes priority over branch fallback hierarchy when both are specified.",
required: false,
}),
delimiter: flags.string({
description: '[optional] Provide a delimiter to separate individual data fields within the CSV file. For example: cm:export-to-csv --delimiter \'|\'',
description:
"[optional] Provide a delimiter to separate individual data fields within the CSV file. For example: cm:export-to-csv --delimiter '|'",
default: ',',
}),
};

};
async run() {
try {
let action, managementAPIClient;
Expand All @@ -87,9 +97,11 @@ class ExportToCsvCommand extends Command {
'content-type': contentTypesFlag,
alias: managementTokenAlias,
branch: branchUid,
"team-uid": teamUid,
'team-uid': teamUid,
'taxonomy-uid': taxonomyUID,
delimiter
'include-fallback': includeFallback,
'fallback-locale': fallbackLocale,
delimiter,
},
} = await this.parse(ExportToCsvCommand);

Expand Down Expand Up @@ -127,7 +139,12 @@ class ExportToCsvCommand extends Command {
}

stackAPIClient = this.getStackClient(managementAPIClient, stack);
stackAPIClient = await this.checkAndUpdateBranchDetail(branchUid, stack, stackAPIClient, managementAPIClient);
stackAPIClient = await this.checkAndUpdateBranchDetail(
branchUid,
stack,
stackAPIClient,
managementAPIClient,
);

const contentTypeCount = await util.getContentTypeCount(stackAPIClient);

Expand Down Expand Up @@ -223,15 +240,15 @@ class ExportToCsvCommand extends Command {
}
case config.exportTeams:
case 'teams': {
try{
try {
let organization;
if (org) {
organization = { uid: org, name: orgName || org };
} else {
organization = await util.chooseOrganization(managementAPIClient, action); // prompt for organization
}
await util.exportTeams(managementAPIClient,organization,teamUid, delimiter);

await util.exportTeams(managementAPIClient, organization, teamUid, delimiter);
} catch (error) {
if (error.message || error.errorMessage) {
cliux.error(util.formatError(error));
Expand All @@ -242,7 +259,11 @@ class ExportToCsvCommand extends Command {
case config.exportTaxonomies:
case 'taxonomies': {
let stack;
let language;
let stackAPIClient;
let finalIncludeFallback = includeFallback;
let finalFallbackLocale = fallbackLocale;

if (managementTokenAlias) {
const { stackDetails, apiClient } = await this.getAliasDetails(managementTokenAlias, stackName);
managementAPIClient = apiClient;
Expand All @@ -252,7 +273,27 @@ class ExportToCsvCommand extends Command {
}

stackAPIClient = this.getStackClient(managementAPIClient, stack);
await this.createTaxonomyAndTermCsvFile(stackAPIClient, stackName, stack, taxonomyUID, delimiter);
if (locale) {
language = { code: locale };
} else {
language = await util.chooseLanguage(stackAPIClient);
}

// if (includeFallback === undefined || fallbackLocale === undefined) {
// const fallbackOptions = await util.chooseFallbackOptions(stackAPIClient);
// }


if (fallbackLocale !== undefined) {
finalFallbackLocale = fallbackLocale;
}

await this.createTaxonomyAndTermCsvFile(stackAPIClient, stackName, stack, taxonomyUID, delimiter, {
locale: language.code,
branch: branchUid,
include_fallback: finalIncludeFallback,
fallback_locale: finalFallbackLocale,
});
break;
}
}
Expand Down Expand Up @@ -287,7 +328,7 @@ class ExportToCsvCommand extends Command {
.query()
.find()
.then(({ items }) => (items !== undefined ? items : []))
.catch((_err) => {});
.catch(() => {});
}

/**
Expand Down Expand Up @@ -335,9 +376,14 @@ class ExportToCsvCommand extends Command {
let apiClient, stackDetails;
const listOfTokens = configHandler.get('tokens');
if (managementTokenAlias && listOfTokens[managementTokenAlias]) {
const checkManagementTokenValidity = await isManagementTokenValid((listOfTokens[managementTokenAlias].apiKey) ,listOfTokens[managementTokenAlias].token);
if(checkManagementTokenValidity.hasOwnProperty('message')) {
throw checkManagementTokenValidity.valid==='failedToCheck'?checkManagementTokenValidity.message:(`error: Management token or stack API key is invalid. ${checkManagementTokenValidity.message}`);
const checkManagementTokenValidity = await isManagementTokenValid(
listOfTokens[managementTokenAlias].apiKey,
listOfTokens[managementTokenAlias].token,
);
if (Object.prototype.hasOwnProperty.call(checkManagementTokenValidity, 'message')) {
throw checkManagementTokenValidity.valid === 'failedToCheck'
? checkManagementTokenValidity.message
: `error: Management token or stack API key is invalid. ${checkManagementTokenValidity.message}`;
}
apiClient = await managementSDKClient({
host: this.cmaHost,
Expand Down Expand Up @@ -393,13 +439,12 @@ class ExportToCsvCommand extends Command {
* @param {object} stack
* @param {string} taxUID
*/
async createTaxonomyAndTermCsvFile(stackAPIClient, stackName, stack, taxUID, delimiter) {
//TODO: Temp variable to export taxonomies in importable format will replaced with flag once decided
const importableCSV = true;
async createTaxonomyAndTermCsvFile(stackAPIClient, stackName, stack, taxUID, delimiter, localeOptions = {}) {
const payload = {
stackAPIClient,
type: '',
limit: config.limit || 100,
...localeOptions, // Spread locale, branch, include_fallback, fallback_locale
};
//check whether the taxonomy is valid or not
let taxonomies = [];
Expand All @@ -411,36 +456,13 @@ class ExportToCsvCommand extends Command {
taxonomies = await util.getAllTaxonomies(payload);
}

if (!importableCSV) {
const formattedTaxonomiesData = util.formatTaxonomiesData(taxonomies);
if (formattedTaxonomiesData?.length) {
const fileName = `${stackName ? stackName : stack.name}_taxonomies.csv`;
util.write(this, formattedTaxonomiesData, fileName, 'taxonomies', delimiter);
} else {
cliux.print('info: No taxonomies found! Please provide a valid stack.', { color: 'blue' });
}

for (let index = 0; index < taxonomies?.length; index++) {
const taxonomy = taxonomies[index];
const taxonomyUID = taxonomy?.uid;
if (taxonomyUID) {
payload['taxonomyUID'] = taxonomyUID;
const terms = await util.getAllTermsOfTaxonomy(payload);
const formattedTermsData = util.formatTermsOfTaxonomyData(terms, taxonomyUID);
const taxonomyName = taxonomy?.name ?? '';
const termFileName = `${stackName ?? stack.name}_${taxonomyName}_${taxonomyUID}_terms.csv`;
if (formattedTermsData?.length) {
util.write(this, formattedTermsData, termFileName, 'terms', delimiter);
} else {
cliux.print(`info: No terms found for the taxonomy UID - '${taxonomyUID}'!`, { color: 'blue' });
}
}
}
if (!taxonomies?.length) {
cliux.print('info: No taxonomies found!', { color: 'blue' });
} else {
const fileName = `${stackName ?? stack.name}_taxonomies.csv`;
const { taxonomiesData, headers } = await util.createImportableCSV(payload, taxonomies);
if (taxonomiesData?.length) {
util.write(this, taxonomiesData, fileName, 'taxonomies',delimiter, headers);
util.write(this, taxonomiesData, fileName, 'taxonomies', delimiter, headers);
}
}
}
Expand Down Expand Up @@ -486,6 +508,16 @@ ExportToCsvCommand.examples = [
'',
'Exporting taxonomies and respective terms to a .CSV file with a delimiter',
'csdx cm:export-to-csv --action <taxonomies> --alias <management-token-alias> --delimiter <delimiter>',
'',
'Exporting taxonomies with specific locale',
'csdx cm:export-to-csv --action <taxonomies> --alias <management-token-alias> --locale <locale>',
'',
'Exporting taxonomies with fallback locale support',
'csdx cm:export-to-csv --action <taxonomies> --alias <management-token-alias> --locale <locale> --include-fallback',
'',
'Exporting taxonomies with custom fallback locale',
'csdx cm:export-to-csv --action <taxonomies> --alias <management-token-alias> --locale <locale> --include-fallback --fallback-locale <fallback-locale>',
'',
];

module.exports = ExportToCsvCommand;
Loading
Loading