Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance logging #151

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 7 additions & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions src/cli/tasks/extract.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -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();
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
Expand Down