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 of errors before backup / import - stores log …
Browse files Browse the repository at this point in the history
…file on FS
  • Loading branch information
Enngage committed Feb 25, 2020
1 parent 9c5ff72 commit a476e4d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
39 changes: 12 additions & 27 deletions src/cli/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs';
import yargs = require('yargs');

import { CleanService } from '../clean';
import { ICliFileConfig } from '../core';
import { ICliFileConfig, fileHelper } from '../core';
import { ExportService, IExportAllResult } from '../export';
import { IImportSource, ImportService } from '../import';
import { ZipService } from '../zip';
Expand Down Expand Up @@ -42,20 +42,13 @@ const backup = async (config: ICliFileConfig) => {

console.log('Completed');
} else {
console.log(`Project contains following inconsistencies:`);
for (const issue of report.type_issues) {
console.log(`Type ${issue.type.codename} has issues: ${issue.issues.map(m => m.messages).join(',')}`);
}
for (const issue of report.variant_issues) {
console.log(
`Variant ${issue.item.codename} (${issue.language.codename}) has issues: ${issue.issues
.map(m => m.messages)
.join(',')}`
);
}
const logFilename: string = 'backup_data_inconsistencies_log.json';

await fileHelper.createFileInCurrentFolderAsync(logFilename, JSON.stringify(report));

console.log(`Project could not be exported due to data inconsistencies.`);
console.log(`A log file '${logFilename}' with issues was created in current folder.`);
console.log(`To export data regardless of issues, set 'force' config parameter to true`);
console.log(`Export failed. See reasons above`);
}
};

Expand Down Expand Up @@ -106,21 +99,13 @@ const restore = async (config: ICliFileConfig) => {

console.log('Completed');
} else {
console.log(`Project contains following inconsistencies:`);
for (const issue of data.validation.type_issues) {
console.log(`Type ${issue.type.codename} has issues: ${issue.issues.map(m => m.messages).join(',')}`);
}
for (const issue of data.validation.variant_issues) {
console.log(
`Variant ${issue.item.codename} (${issue.language.codename}) has issues: ${issue.issues
.map(m => m.messages)
.join(',')}`
);
}
const logFilename: string = 'import_data_inconsistencies_log.json';

await fileHelper.createFileInCurrentFolderAsync(logFilename, JSON.stringify(data.validation));

console.log(`To import data regardless of issues, set 'force' config parameter to true, however keep in mind that without
fixing the issues, the import will likely fail.`);
console.log(`Import failed. See reasons above`);
console.log(`Project could not be imported due to data inconsistencies.`);
console.log(`A log file '${logFilename}' with issues was created in current folder.`);
console.log(`To import data regardless of issues, set 'force' config parameter to true`);
}
};

Expand Down
13 changes: 13 additions & 0 deletions src/core/file-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as fs from 'fs';

export class FileHelper {

async createFileInCurrentFolderAsync(filename: string, data: any): Promise<void> {
const filePath = './' + filename;

await fs.promises.writeFile(filePath, data);
}

}

export const fileHelper = new FileHelper();
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './core.models';
export * from './translation-helper';
export * from './id-translate-helper';
export * from './file-helper';

0 comments on commit a476e4d

Please sign in to comment.