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

Commit

Permalink
feat: improves logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Jan 16, 2020
1 parent 9bf80ad commit cb37f7a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/cli/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const restore = async (config: ICliFileConfig) => {
},
projectId: config.projectId,
apiKey: config.apiKey,
enableLog: config.enableLog,
workflowIdForImportedItems: '00000000-0000-0000-0000-000000000000',
process: {
language: item => config.importLanguages,
Expand Down
63 changes: 35 additions & 28 deletions src/import/import.helper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { codenameTranslateHelper } from '../core';
import { IExportData } from '../export';
import { IImportData, IPreparedImportItem, IImportSource } from './import.models';
import { IImportData, IImportSource, IPreparedImportItem } from './import.models';

export class ImportHelper {
public prepareImportData(sourceData: IImportSource): IImportData {
// translate internal ids to codenames
codenameTranslateHelper.replaceIdReferencesWithCodenames(sourceData.importData, sourceData.importData);
codenameTranslateHelper.replaceIdReferencesWithCodenames(
sourceData.importData.contentTypes,
sourceData.importData
);
codenameTranslateHelper.replaceIdReferencesWithCodenames(
sourceData.importData.contentTypeSnippets,
sourceData.importData
);

// flatten data
const items = this.flattenSourceData(sourceData);
Expand Down Expand Up @@ -39,10 +45,7 @@ export class ImportHelper {
return sortedItems;
}

private getDependenciesOfItem(
item: IPreparedImportItem,
allItems: IPreparedImportItem[]
): string[] {
private getDependenciesOfItem(item: IPreparedImportItem, allItems: IPreparedImportItem[]): string[] {
const deps: string[] = [];

// get referenced codenames in item
Expand All @@ -57,55 +60,59 @@ export class ImportHelper {
private flattenSourceData(sourceData: IImportSource): IPreparedImportItem[] {
return [
...sourceData.importData.taxonomies.map(m => {
return <IPreparedImportItem> {
return <IPreparedImportItem>{
codename: m.codename,
deps: [],
item: m,
type: 'taxonomy'
};
}),
...this.orderItemsByDeps(sourceData.importData.contentTypeSnippets.map(m => {
return <IPreparedImportItem> {
codename: m.codename,
deps: [],
item: m,
type: 'contentTypeSnippet'
};
})),
...this.orderItemsByDeps(sourceData.importData.contentTypes.map(m => {
return <IPreparedImportItem> {
codename: m.codename,
deps: [],
item: m,
type: 'contentType'
};
})),
...this.orderItemsByDeps(
sourceData.importData.contentTypeSnippets.map(m => {
return <IPreparedImportItem>{
codename: m.codename,
deps: [],
item: m,
type: 'contentTypeSnippet'
};
})
),
...this.orderItemsByDeps(
sourceData.importData.contentTypes.map(m => {
return <IPreparedImportItem>{
codename: m.codename,
deps: [],
item: m,
type: 'contentType'
};
})
),
...sourceData.importData.languages.map(m => {
return <IPreparedImportItem> {
return <IPreparedImportItem>{
codename: m.id,
deps: [],
item: m,
type: 'language'
};
}),
...sourceData.importData.assets.map(m => {
return <IPreparedImportItem> {
return <IPreparedImportItem>{
codename: m.id,
deps: [],
item: m,
type: 'asset'
};
}),
...sourceData.importData.contentItems.map(m => {
return <IPreparedImportItem> {
return <IPreparedImportItem>{
codename: m.codename,
deps: [],
item: m,
type: 'contentItem'
};
}),
...sourceData.importData.languageVariants.map(m => {
return <IPreparedImportItem> {
return <IPreparedImportItem>{
codename: m.item.codename,
deps: [m.item.codename],
item: m,
Expand Down
1 change: 1 addition & 0 deletions src/import/import.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IImportConfig {
workflowIdForImportedItems: string;
projectId: string;
apiKey: string;
enableLog: boolean;
onImport?: (item: IProcessedItem) => void;
process?: {
taxonomy?: (
Expand Down
9 changes: 9 additions & 0 deletions src/import/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ export class ImportService {
public async importFromSourceAsync(
sourceData: IImportSource
): Promise<IImportItemResult<ValidImportContract, ValidImportModel>[]> {

if (this.config.enableLog) {
console.log(`Preparing data for import`);
}
const importData = importHelper.prepareImportData(sourceData);

if (this.config.enableLog) {
console.log(`Importing data`);
}

return await this.importAsync(importData);
}

Expand Down
8 changes: 7 additions & 1 deletion src/zip/zip.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ZipService {
}
const assets = await this.readAndParseJsonFile(unzippedFile, this.assetsName);

return {
const result = {
importData: {
assets,
contentTypes: await this.readAndParseJsonFile(unzippedFile, this.contentTypesName),
Expand All @@ -57,6 +57,12 @@ export class ZipService {
assetFolders: await this.readAndParseJsonFile(unzippedFile, this.assetFoldersName),
binaryFiles: await this.extractBinaryFilesAsync(unzippedFile, assets)
};

if (this.config.enableLog) {
console.log(`Pasing zip completed`);
}

return result;
}

public async createZipAsync(exportData: IExportData, metadata: IExportMetadata): Promise<void> {
Expand Down

0 comments on commit cb37f7a

Please sign in to comment.