Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
feat: adds support for exporting workflow steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Feb 24, 2021
1 parent b8aff5a commit f2878a2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Install package globally:
* language
* assetFolder
* binaryFile
* workflowSteps (only export)

### Execution

Expand Down
2 changes: 2 additions & 0 deletions src/core/core.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type ItemType =
| 'language'
| 'asset'
| 'assetFolder'
| 'workflowStep'
| 'binaryFile';

export type ValidImportModel =
Expand Down Expand Up @@ -96,5 +97,6 @@ export interface IPackageDataOverview {
languagesCount: number;
assetsCount: number;
assetFoldersCount: number;
workflowStepsCount: number;
}

2 changes: 2 additions & 0 deletions src/export/export.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
LanguageVariantContracts,
TaxonomyContracts,
ProjectContracts,
WorkflowContracts,
} from '@kentico/kontent-management';

import { IProcessedItem, IPackageMetadata, ItemType } from '../core';
Expand All @@ -21,6 +22,7 @@ export interface IExportConfig {
}

export interface IExportData {
workflowSteps: WorkflowContracts.IWorkflowStepContract[];
taxonomies: TaxonomyContracts.ITaxonomyContract[];
contentTypeSnippets: ContentTypeSnippetContracts.IContentTypeSnippetContract[];
contentTypes: ContentTypeContracts.IContentTypeContract[];
Expand Down
16 changes: 13 additions & 3 deletions src/export/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
AssetContracts,
LanguageContracts,
AssetFolderContracts,
ProjectContracts
ProjectContracts,
WorkflowContracts
} from '@kentico/kontent-management';

import { IExportAllResult, IExportConfig, IExportData } from './export.models';
Expand Down Expand Up @@ -37,7 +38,8 @@ export class ExportService {
contentTypeSnippet: this.config.exportFilter?.includes('contentTypeSnippet') ?? true,
language: this.config.exportFilter?.includes('language') ?? true,
languageVariant: this.config.exportFilter?.includes('languageVariant') ?? true,
taxonomy: this.config.exportFilter?.includes('taxonomy') ?? true
taxonomy: this.config.exportFilter?.includes('taxonomy') ?? true,
workflowSteps: this.config.exportFilter?.includes('workflowStep') ?? true,
};

const contentTypes = await this.exportContentTypesAsync({ processItem: exportItems.contentType });
Expand All @@ -48,6 +50,7 @@ export class ExportService {
contentTypes: exportItems.contentType ? contentTypes : [],
contentTypeSnippets: exportItems.contentTypeSnippet ? await this.exportContentTypeSnippetsAsync() : [],
taxonomies: exportItems.taxonomy ? await this.exportTaxonomiesAsync() : [],
workflowSteps: exportItems.taxonomy ? await this.exportWorkflowStepsAsync() : [],
contentItems: exportItems.contentItem ? await this.exportContentItemsAsync() : [],
languageVariants: exportItems.languageVariant
? await this.exportLanguageVariantsAsync(contentItems.map((m) => m.id))
Expand All @@ -72,7 +75,8 @@ export class ExportService {
contentTypesCount: data.contentTypes.length,
languageVariantsCount: data.languageVariants.length,
languagesCount: data.languages.length,
taxonomiesCount: data.taxonomies.length
taxonomiesCount: data.taxonomies.length,
workflowStepsCount: data.workflowSteps.length,
}
},
validation: projectValidation,
Expand Down Expand Up @@ -115,6 +119,12 @@ export class ExportService {
return response.data.items.map((m) => m._raw);
}

public async exportWorkflowStepsAsync(): Promise<WorkflowContracts.IWorkflowStepContract[]> {
const response = await this.client.listWorkflowSteps().toPromise();
response.data.forEach((m) => this.processItem(m.name, 'workflowStep', m));
return response.data.map((m) => m._raw);
}

public async exportTaxonomiesAsync(): Promise<TaxonomyContracts.ITaxonomyContract[]> {
const response = await this.client.listTaxonomies().toPromise();
response.data.taxonomies.forEach((m) => this.processItem(m.name, 'taxonomy', m));
Expand Down
2 changes: 2 additions & 0 deletions src/zip/zip.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class ZipService {
private readonly languages: string = 'languages.json';
private readonly filesName: string = 'files';
private readonly assetFoldersName: string = 'assetFolders.json';
private readonly workflowStepsName: string = 'workflowSteps.json';
private readonly validationName: string = 'validation.json';

constructor(private config: IZipServiceConfig) {
Expand Down Expand Up @@ -77,6 +78,7 @@ export class ZipService {
zip.file(this.languages, JSON.stringify(exportData.data.languages));
zip.file(this.contentTypeSnippetsName, JSON.stringify(exportData.data.contentTypeSnippets));
zip.file(this.assetFoldersName, JSON.stringify(exportData.data.assetFolders));
zip.file(this.workflowStepsName, JSON.stringify(exportData.data.workflowSteps));

const assetsFolder = zip.folder(this.filesName);

Expand Down

0 comments on commit f2878a2

Please sign in to comment.