From 39ae795bc17d2054c477306002d6775f71325801 Mon Sep 17 00:00:00 2001 From: ViES Date: Mon, 21 Oct 2019 08:17:42 +0300 Subject: [PATCH 1/4] (feat) add argument --verbose to show details about result of extraction --- src/cli/cli.ts | 8 +++++++- src/cli/tasks/extract.task.ts | 16 +++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/cli/cli.ts b/src/cli/cli.ts index e07e065a..2132b930 100755 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -89,13 +89,19 @@ export const cli = yargs describe: 'Use null as default value for translations', type: 'boolean' }) + .option('verbose', { + alias: 'vb', + describe: 'Show details about result of extraction', + type: 'boolean' + }) .conflicts('key-as-default-value', 'null-as-default-value') .exitProcess(true) .parse(process.argv); const extractTask = new ExtractTask(cli.input, cli.output, { replace: cli.replace, - patterns: cli.patterns + patterns: cli.patterns, + verbose: cli.verbose }); // Parsers diff --git a/src/cli/tasks/extract.task.ts b/src/cli/tasks/extract.task.ts index a0ecf631..10f933d3 100644 --- a/src/cli/tasks/extract.task.ts +++ b/src/cli/tasks/extract.task.ts @@ -13,12 +13,14 @@ import * as mkdirp from 'mkdirp'; export interface ExtractTaskOptionsInterface { replace?: boolean; patterns?: string[]; + verbose?: boolean; } export class ExtractTask implements TaskInterface { protected options: ExtractTaskOptionsInterface = { replace: false, - patterns: [] + patterns: [], + verbose: false }; protected parsers: ParserInterface[] = []; @@ -36,9 +38,11 @@ export class ExtractTask implements TaskInterface { throw new Error('No compiler configured'); } - this.printEnabledParsers(); - this.printEnabledPostProcessors(); - this.printEnabledCompiler(); + if (this.options.verbose) { + this.printEnabledParsers(); + this.printEnabledPostProcessors(); + this.printEnabledCompiler(); + } this.out(bold('Extracting:')); const extracted = this.extract(); @@ -102,7 +106,9 @@ export class ExtractTask implements TaskInterface { let collection: TranslationCollection = new TranslationCollection(); this.inputs.forEach(dir => { this.readDir(dir, this.options.patterns).forEach(filePath => { - this.out(dim('- %s'), filePath); + if (this.options.verbose) { + this.out(dim('- %s'), filePath); + } const contents: string = fs.readFileSync(filePath, 'utf-8'); this.parsers.forEach(parser => { const extracted = parser.extract(contents, filePath); From 29f9ee74af236b751e726c6170b55866bedc7009 Mon Sep 17 00:00:00 2001 From: ViES Date: Mon, 21 Oct 2019 08:18:13 +0300 Subject: [PATCH 2/4] (feat) show new strings count --- src/cli/tasks/extract.task.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cli/tasks/extract.task.ts b/src/cli/tasks/extract.task.ts index 10f933d3..d452a603 100644 --- a/src/cli/tasks/extract.task.ts +++ b/src/cli/tasks/extract.task.ts @@ -68,6 +68,10 @@ export class ExtractTask implements TaskInterface { // merge extracted strings with existing const draft = extracted.union(existing); + if (!this.options.replace) { + this.out(green(`\nFound %d new strings.\n`), draft.count() - existing.count()); + } + if (existing.isEmpty()) { this.out(dim(`- ${outputPath}`)); } else { From 5668aac752798b87ff8f624be91e5261a0ad0df7 Mon Sep 17 00:00:00 2001 From: ViES Date: Mon, 21 Oct 2019 08:19:18 +0300 Subject: [PATCH 3/4] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 75db0b9e..b403fc20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@biesbjerg/ngx-translate-extract", - "version": "4.2.0", + "version": "4.3.0", "description": "Extract strings from projects using ngx-translate", "main": "dist/index.js", "typings": "dist/index.d.ts", From 1ab9193c4940a0f45d5e7887d2134d1f86743134 Mon Sep 17 00:00:00 2001 From: ViES Date: Mon, 21 Oct 2019 14:24:18 +0300 Subject: [PATCH 4/4] (feat) show deleted strings count --- src/cli/tasks/extract.task.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cli/tasks/extract.task.ts b/src/cli/tasks/extract.task.ts index d452a603..d025b326 100644 --- a/src/cli/tasks/extract.task.ts +++ b/src/cli/tasks/extract.task.ts @@ -68,10 +68,6 @@ export class ExtractTask implements TaskInterface { // merge extracted strings with existing const draft = extracted.union(existing); - if (!this.options.replace) { - this.out(green(`\nFound %d new strings.\n`), draft.count() - existing.count()); - } - if (existing.isEmpty()) { this.out(dim(`- ${outputPath}`)); } else { @@ -81,6 +77,11 @@ export class ExtractTask implements TaskInterface { // Run collection through post processors const final = this.process(draft, extracted, existing); + if (!this.options.replace) { + this.out(green(`\nFound %d new strings.`), draft.count() - existing.count()); + } + this.out(green(`\nDeleted %d strings.\n`), draft.count() - final.count()); + // Save to file this.save(outputPath, final); });