From f2878a20ff6b76cf047831be356cc7f0e07146f7 Mon Sep 17 00:00:00 2001 From: Enngage Date: Wed, 24 Feb 2021 09:09:25 +0100 Subject: [PATCH] feat: adds support for exporting workflow steps --- README.md | 1 + src/core/core.models.ts | 2 ++ src/export/export.models.ts | 2 ++ src/export/export.service.ts | 16 +++++++++++++--- src/zip/zip.service.ts | 2 ++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1a4ffb8..37f2258 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Install package globally: * language * assetFolder * binaryFile +* workflowSteps (only export) ### Execution diff --git a/src/core/core.models.ts b/src/core/core.models.ts index 41774fa..792a1e9 100644 --- a/src/core/core.models.ts +++ b/src/core/core.models.ts @@ -38,6 +38,7 @@ export type ItemType = | 'language' | 'asset' | 'assetFolder' + | 'workflowStep' | 'binaryFile'; export type ValidImportModel = @@ -96,5 +97,6 @@ export interface IPackageDataOverview { languagesCount: number; assetsCount: number; assetFoldersCount: number; + workflowStepsCount: number; } diff --git a/src/export/export.models.ts b/src/export/export.models.ts index b064ea2..9810661 100644 --- a/src/export/export.models.ts +++ b/src/export/export.models.ts @@ -8,6 +8,7 @@ import { LanguageVariantContracts, TaxonomyContracts, ProjectContracts, + WorkflowContracts, } from '@kentico/kontent-management'; import { IProcessedItem, IPackageMetadata, ItemType } from '../core'; @@ -21,6 +22,7 @@ export interface IExportConfig { } export interface IExportData { + workflowSteps: WorkflowContracts.IWorkflowStepContract[]; taxonomies: TaxonomyContracts.ITaxonomyContract[]; contentTypeSnippets: ContentTypeSnippetContracts.IContentTypeSnippetContract[]; contentTypes: ContentTypeContracts.IContentTypeContract[]; diff --git a/src/export/export.service.ts b/src/export/export.service.ts index d473400..4e17904 100644 --- a/src/export/export.service.ts +++ b/src/export/export.service.ts @@ -9,7 +9,8 @@ import { AssetContracts, LanguageContracts, AssetFolderContracts, - ProjectContracts + ProjectContracts, + WorkflowContracts } from '@kentico/kontent-management'; import { IExportAllResult, IExportConfig, IExportData } from './export.models'; @@ -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 }); @@ -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)) @@ -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, @@ -115,6 +119,12 @@ export class ExportService { return response.data.items.map((m) => m._raw); } + public async exportWorkflowStepsAsync(): Promise { + 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 { const response = await this.client.listTaxonomies().toPromise(); response.data.taxonomies.forEach((m) => this.processItem(m.name, 'taxonomy', m)); diff --git a/src/zip/zip.service.ts b/src/zip/zip.service.ts index 2ce4c7b..78c0ca3 100644 --- a/src/zip/zip.service.ts +++ b/src/zip/zip.service.ts @@ -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) { @@ -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);