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 & import asset folders & assets inside
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Jan 15, 2020
1 parent 6f4623a commit 8608c29
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 43 deletions.
Binary file modified output/test.zip
Binary file not shown.
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@
],
"license": "MIT",
"dependencies": {
"@kentico/kontent-management": "0.3.11",
"@kentico/kontent-management": "0.3.14",
"jszip": "3.2.2",
"rxjs": "6.5.4",
"yargs": "15.1.0",
"flatted": "2.0.1"
},
"devDependencies": {
"@types/jszip": "3.1.7",
"@types/node": "13.1.5",
"@types/node": "13.1.7",
"@types/yargs": "15.0.0",
"standard-version": "7.0.1",
"ts-node": "8.5.4",
"ts-node": "8.6.2",
"tslint": "5.20.1",
"typescript": "3.7.4"
}
Expand Down
2 changes: 1 addition & 1 deletion src/clean/clean.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class CleanService {
.modifyAssetFolders()
.withData(
assetFolders.map(m => {
return <AssetFolderModels.IModifyAssetFoldersData>{
return <AssetFolderModels.IModifyAssetFoldersData> {
op: 'remove',
reference: {
id: m.id
Expand Down
11 changes: 8 additions & 3 deletions src/core/core.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
TaxonomyModels,
LanguageVariantContracts,
ContentItemContracts,
AssetFolderModels,
AssetFolderContracts,
} from '@kentico/kontent-management';

export type CliAction = 'backup' | 'restore' | 'clean';
Expand All @@ -24,7 +26,8 @@ export type ItemType =
| 'languageVariant'
| 'language'
| 'asset'
| 'assetFolder';
| 'assetFolder'
| 'binaryFile';

export type ValidImportModel =
| ContentTypeModels.ContentType
Expand All @@ -33,7 +36,8 @@ export type ValidImportModel =
| LanguageVariantModels.ContentItemLanguageVariant
| ContentItemModels.ContentItem
| LanguageModels.LanguageModel
| AssetModels.Asset;
| AssetModels.Asset
| AssetFolderModels.AssetFolder;

export type ValidImportContract =
| ContentTypeContracts.IContentTypeContract
Expand All @@ -43,7 +47,8 @@ export type ValidImportContract =
| TaxonomyContracts.ITaxonomyContract
| AssetContracts.IAssetModelContract
| LanguageVariantContracts.ILanguageVariantModelContract
| LanguageContracts.ILanguageModelContract;
| LanguageContracts.ILanguageModelContract
| AssetFolderContracts.IAssetFolderContract;

export interface IProcessedItem {
title: string;
Expand Down
2 changes: 2 additions & 0 deletions src/export/export.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LanguageVariantContracts,
LanguageContracts,
AssetContracts,
AssetFolderContracts,
} from '@kentico/kontent-management';

export interface IExportConfig {
Expand All @@ -21,6 +22,7 @@ export interface IExportData {
languageVariants: LanguageVariantContracts.ILanguageVariantModelContract[];
languages: LanguageContracts.ILanguageModelContract[];
assets: AssetContracts.IAssetModelContract[];
assetFolders: AssetFolderContracts.IAssetFolderContract[];
}

export interface IExportMetadata {
Expand Down
9 changes: 8 additions & 1 deletion src/export/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TaxonomyContracts,
AssetContracts,
LanguageContracts,
AssetFolderContracts,
} from '@kentico/kontent-management';

import { IExportAllResult, IExportConfig, IExportData } from './export.models';
Expand All @@ -32,7 +33,8 @@ export class ExportService {
contentItems: await this.exportContentItemsAsync(),
languageVariants: await this.exportLanguageVariantsAsync(contentTypes.map(m => m.id)),
assets: await this.exportAssetsAsync(),
languages: await this.exportLanguagesAsync()
languages: await this.exportLanguagesAsync(),
assetFolders: await this.exportAssetFoldersAsync()
};

return {
Expand All @@ -49,6 +51,11 @@ export class ExportService {
return response.data.items.map(m => m._raw);
}

public async exportAssetFoldersAsync(): Promise<AssetFolderContracts.IAssetFolderContract[]> {
const response = await this.client.listAssetFolders().toPromise();
return response.data.items.map(m => m._raw);
}

public async exportLanguagesAsync(): Promise<LanguageContracts.ILanguageModelContract[]> {
const response = await this.client.listLanguages().toPromise();
return response.data.items.map(m => m._raw);
Expand Down
21 changes: 11 additions & 10 deletions src/import/import.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ export class ImportHelper {
codenameTranslateHelper.replaceIdReferencesWithCodenames(sourceData.importData, sourceData.importData);

// flatten data
const items = this.flattenExportData(sourceData.importData);
const items = this.flattenExportData(sourceData);

return {
orderedImportItems: items,
binaryFiles: sourceData.binaryFiles
binaryFiles: sourceData.binaryFiles,
assetFolders: sourceData.assetFolders
};
}

Expand Down Expand Up @@ -53,57 +54,57 @@ export class ImportHelper {
return filteredDeps;
}

private flattenExportData(exportData: IExportData): IPreparedImportItem[] {
private flattenExportData(sourceData: IImportSource): IPreparedImportItem[] {
return [
...exportData.taxonomies.map(m => {
...sourceData.importData.taxonomies.map(m => {
return <IPreparedImportItem> {
codename: m.codename,
deps: [],
item: m,
type: 'taxonomy'
};
}),
...this.orderItemsByDeps(exportData.contentTypeSnippets.map(m => {
...this.orderItemsByDeps(sourceData.importData.contentTypeSnippets.map(m => {
return <IPreparedImportItem> {
codename: m.codename,
deps: [],
item: m,
type: 'contentTypeSnippet'
};
})),
...this.orderItemsByDeps(exportData.contentTypes.map(m => {
...this.orderItemsByDeps(sourceData.importData.contentTypes.map(m => {
return <IPreparedImportItem> {
codename: m.codename,
deps: [],
item: m,
type: 'contentType'
};
})),
...exportData.languages.map(m => {
...sourceData.importData.languages.map(m => {
return <IPreparedImportItem> {
codename: m.id,
deps: [],
item: m,
type: 'language'
};
}),
...exportData.assets.map(m => {
...sourceData.importData.assets.map(m => {
return <IPreparedImportItem> {
codename: m.id,
deps: [],
item: m,
type: 'asset'
};
}),
...exportData.contentItems.map(m => {
...sourceData.importData.contentItems.map(m => {
return <IPreparedImportItem> {
codename: m.codename,
deps: [],
item: m,
type: 'contentItem'
};
}),
...exportData.languageVariants.map(m => {
...sourceData.importData.languageVariants.map(m => {
return <IPreparedImportItem> {
codename: m.item.codename,
deps: [m.item.codename],
Expand Down
9 changes: 9 additions & 0 deletions src/import/import.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LanguageContracts,
LanguageVariantContracts,
TaxonomyContracts,
AssetFolderContracts,
} from '@kentico/kontent-management';

import { IProcessedItem, ItemType } from '../core';
Expand Down Expand Up @@ -49,10 +50,18 @@ export interface IImportSource {
languages: LanguageContracts.ILanguageModelContract[];
assets: AssetContracts.IAssetModelContract[];
};
assetFolders: AssetFolderContracts.IAssetFolderContract[];
binaryFiles: IBinaryFile[];
}

export interface IImportData {
orderedImportItems: IPreparedImportItem[];
assetFolders: AssetFolderContracts.IAssetFolderContract[];
binaryFiles: IBinaryFile[];
}

export interface IFlattenedFolder {
name: string;
externalId?: string;
id: string;
}
Loading

0 comments on commit 8608c29

Please sign in to comment.