Add cli option to customize compiler indentation. Closes #22

This commit is contained in:
Kim Biesbjerg
2017-03-29 14:20:01 +02:00
parent ff1c91010e
commit 9a2108e9a9
9 changed files with 97 additions and 47 deletions

View File

@@ -1,7 +1,10 @@
import { ExtractTask } from './tasks/extract.task';
import { ParserInterface } from '../parsers/parser.interface';
import { PipeParser } from '../parsers/pipe.parser';
import { DirectiveParser } from '../parsers/directive.parser';
import { ServiceParser } from '../parsers/service.parser';
import { CompilerInterface } from '../compilers/compiler.interface';
import { CompilerFactory } from '../compilers/compiler.factory';
import * as fs from 'fs';
import * as yargs from 'yargs';
@@ -48,6 +51,12 @@ export const cli = yargs
type: 'string',
choices: ['json', 'namespaced-json', 'pot']
})
.option('format-indentation', {
alias: 'fi',
describe: 'Output format indentation',
default: '\t',
type: 'string'
})
.option('replace', {
alias: 'r',
describe: 'Replace the contents of output file if it exists (Merges by default)',
@@ -69,19 +78,22 @@ export const cli = yargs
.exitProcess(true)
.parse(process.argv);
const extractTask = new ExtractTask(cli.input, cli.output, {
const parsers: ParserInterface[] = [
new ServiceParser(),
new PipeParser(),
new DirectiveParser()
];
const compiler: CompilerInterface = CompilerFactory.create(cli.format, {
indentation: cli.formatIndentation
});
new ExtractTask(cli.input, cli.output, {
replace: cli.replace,
sort: cli.sort,
clean: cli.clean,
patterns: cli.patterns
});
extractTask
.setParsers([
new ServiceParser(),
new PipeParser(),
new DirectiveParser()
])
.setCompiler(cli.format)
.execute();
})
.setParsers(parsers)
.setCompiler(compiler)
.execute();

View File

@@ -2,7 +2,6 @@ import { TranslationCollection } from '../../utils/translation.collection';
import { TaskInterface } from './task.interface';
import { ParserInterface } from '../../parsers/parser.interface';
import { CompilerInterface } from '../../compilers/compiler.interface';
import { CompilerFactory } from '../../compilers/compiler.factory';
import * as chalk from 'chalk';
import * as glob from 'glob';
@@ -56,13 +55,8 @@ export class ExtractTask implements TaskInterface {
return this;
}
public setCompiler(compiler: CompilerInterface | string): this {
if (typeof compiler === 'string') {
this._compiler = CompilerFactory.create(compiler)
} else {
this._compiler = compiler;
}
public setCompiler(compiler: CompilerInterface): this {
this._compiler = compiler;
return this;
}
@@ -70,10 +64,9 @@ export class ExtractTask implements TaskInterface {
* Extract strings from input dirs using configured parsers
*/
protected _extract(): TranslationCollection {
let collection: TranslationCollection = new TranslationCollection();
this._out(chalk.bold('Extracting strings...'));
let collection: TranslationCollection = new TranslationCollection();
this._input.forEach(dir => {
this._readDir(dir, this._options.patterns).forEach(path => {
this._out(chalk.gray('- %s'), path);
@@ -83,6 +76,7 @@ export class ExtractTask implements TaskInterface {
});
});
});
return collection;
}