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", 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..d025b326 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(); @@ -73,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); }); @@ -102,7 +111,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);