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

Add Taxonomy module to CLI Import Plugin #1062

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class ExportToCsvCommand extends Command {
throw new Error(branchExists.errorMessage);
}
stack.branch_uid = branchUid;
stackAPIClient = getStackClient(managementAPIClient, stack);
stackAPIClient = this.getStackClient(managementAPIClient, stack);
} catch (error) {
if (error?.message || error?.errorMessage) {
cliux.error(util.formatError(error));
Expand Down
5 changes: 3 additions & 2 deletions packages/contentstack-export/src/export/modules/taxonomies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import omit from 'lodash/omit';
import keys from 'lodash/keys';
import isEmpty from 'lodash/isEmpty';
import flatten from 'lodash/flatten';
import keys from 'lodash/keys';
import { resolve as pResolve } from 'node:path';
import { cliux, configHandler, HttpClient } from '@contentstack/cli-utilities';

Expand Down Expand Up @@ -120,7 +120,7 @@ export default class ExportTaxonomies extends BaseClass {
log(this.exportConfig, `No terms found for taxonomy - '${taxonomyUID}'`, 'info');
} else {
fsUtil.writeFile(pResolve(this.termsFolderPath, `${taxonomyUID}-${this.termsConfig.fileName}`), this.terms);
log(this.exportConfig, `Terms from taxonomy '${taxonomyUID}' were successfully exported.`, 'success');
log(this.exportConfig, `Terms from taxonomy '${taxonomyUID}' were exported successfully.`, 'success');
}
}
log(this.exportConfig, `All the terms have been exported successfully!`, 'success');
Expand Down Expand Up @@ -172,6 +172,7 @@ export default class ExportTaxonomies extends BaseClass {
include_count: true,
skip: 0,
limit: this.taxonomiesConfig.limit || 100,
depth: 0 // include all the terms if set to 0
};

if (skip >= 0) params['skip'] = skip;
Expand Down
9 changes: 9 additions & 0 deletions packages/contentstack-import/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const config: DefaultConfig = {
'locales',
'environments',
'assets',
'taxonomies',
'extensions',
'marketplace-apps',
'global-fields',
Expand Down Expand Up @@ -142,6 +143,14 @@ const config: DefaultConfig = {
dirName: 'marketplace_apps',
fileName: 'marketplace_apps.json',
},
taxonomies: {
dirName: 'taxonomies',
fileName: 'taxonomies.json'
},
terms: {
dirName: 'terms',
fileName: 'terms.json'
},
},
languagesCode: [
'af-za',
Expand Down
18 changes: 17 additions & 1 deletion packages/contentstack-import/src/import/modules/base-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { LabelData } from '@contentstack/management/types/stack/label';
import { WebhookData } from '@contentstack/management/types/stack/webhook';
import { WorkflowData } from '@contentstack/management/types/stack/workflow';
import { RoleData } from '@contentstack/management/types/stack/role';
import { HttpClient } from '@contentstack/cli-utilities';

import { log } from '../../utils';
import { ImportConfig, ModuleClassParams } from '../../types';
Expand Down Expand Up @@ -47,7 +48,9 @@ export type ApiModuleType =
| 'create-entries'
| 'update-entries'
| 'publish-entries'
| 'delete-entries';
| 'delete-entries'
| 'create-taxonomies'
| 'create-terms';

export type ApiOptions = {
uid?: string;
Expand Down Expand Up @@ -381,6 +384,19 @@ export default abstract class BaseClass {
.delete({ locale: additionalInfo.locale })
.then(onSuccess)
.catch(onReject);
case 'create-taxonomies':
return new HttpClient()
.headers(additionalInfo.headers)
.post(additionalInfo.url, { taxonomy: apiData })
.then(onSuccess)
.catch(onReject);
case 'create-terms':
const url = `${additionalInfo.baseUrl}/${apiData.taxonomy_uid}/terms`;
return new HttpClient()
.headers(additionalInfo.headers)
.post(url, { term: apiData })
.then(onSuccess)
.catch(onReject);
aman19K marked this conversation as resolved.
Show resolved Hide resolved
default:
return Promise.resolve();
}
Expand Down
Loading