Skip to content

Commit

Permalink
feat(analyzer): save a summary file
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdel El-Medny committed Feb 5, 2019
1 parent 8acaada commit a254bc9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/analyzer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as pluralize from 'pluralize';
import { ITranslationDifference, ITranslationFile } from '../types';
import { IConfiguration, ITranslationDifference } from '../types';

export class Analyzer {

Expand All @@ -23,12 +23,9 @@ export class Analyzer {
return differences;
}

logDifferences(
differences: Map<string, ITranslationDifference>,
fixFlagOn: boolean
) {
createFeedback( differences: Map<string, ITranslationDifference> ): string[] {

const message: string[] = [];
const messages: string[] = [];

/** We want to be positive here! So we will show the good news first */
const positivelySortedDifferences = Array.from(differences.entries()).sort((a, b) => {
Expand Down Expand Up @@ -62,14 +59,20 @@ export class Analyzer {
toAppendMessage = `🎉 '${fileKey}' matches the master file`;
}

message.push(toAppendMessage);
messages.push(toAppendMessage);
});

console.log(message.join('\n'));

return messages;
}

handleFeedback(messages: string[], config: IConfiguration) {
console.log(messages.join('\n'));

if (fixFlagOn === false) {
if (config.autoFix === false) {
console.log('\x1b[32m%s\x1b[0m', `To fix this, run the command with the --autofix flag or add autofix to true in the configuration file`);
return null;
} else {
return messages;
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ export class Main {

const differences = this.analyzer.getDifferences(configuration!.masterFileName, translationsMap!);

this.analyzer.logDifferences(differences, configuration!.autoFix);
const messages = this.analyzer.createFeedback(differences)!;

this.analyzer.handleFeedback(messages, configuration!);

if ( configuration!.autoFix ) {
const fixedFilesMap = this.translationsDifferenceHandler.handle(
translationsMap!,
Expand All @@ -55,6 +57,11 @@ export class Main {
configuration!,
'json'
);

this.filesManager.writeFile(
configuration!.i18nFilesPath + '/fixed/summary.txt',
messages.join('\n')
);
}

spinner.stop();
Expand Down

0 comments on commit a254bc9

Please sign in to comment.