Skip to content

Commit

Permalink
Merge pull request #1062 from contentstack/feat/CS-41385-import-taxonomy
Browse files Browse the repository at this point in the history
Add Taxonomy module to CLI Import Plugin
  • Loading branch information
aman19K authored Sep 27, 2023
2 parents 99b7537 + 334b007 commit 5593c1c
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 6 deletions.
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);
default:
return Promise.resolve();
}
Expand Down
Loading

0 comments on commit 5593c1c

Please sign in to comment.