- (chore) update packages
- (refactor) use tsquery for querying AST - (feat) autodetect usage of marker function and remove --marker cli argument - (bugfix) extract strings when TranslateService is declared directly as a class parameter. Closes https://github.com/biesbjerg/ngx-translate-extract/issues/83 - (bugfix) handle split strings: marker('hello ' + 'world') is now extracted as a single string: 'hello world'
This commit is contained in:
@@ -6,7 +6,7 @@ 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 { FunctionParser } from '../parsers/function.parser';
|
||||
import { MarkerParser } from '../parsers/marker.parser';
|
||||
import { PostProcessorInterface } from '../post-processors/post-processor.interface';
|
||||
import { SortByKeyPostProcessor } from '../post-processors/sort-by-key.post-processor';
|
||||
import { KeyAsDefaultValuePostProcessor } from '../post-processors/key-as-default-value.post-processor';
|
||||
@@ -29,7 +29,7 @@ export const cli = yargs
|
||||
normalize: true
|
||||
})
|
||||
.check(options => {
|
||||
options.input.forEach((dir: string) => {
|
||||
(options.input as unknown as string[]).forEach((dir: string) => {
|
||||
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
|
||||
throw new Error(`The path you supplied was not found: '${dir}'`);
|
||||
}
|
||||
@@ -50,12 +50,6 @@ export const cli = yargs
|
||||
normalize: true,
|
||||
required: true
|
||||
})
|
||||
.option('marker', {
|
||||
alias: 'm',
|
||||
describe: 'Extract strings passed to a marker function',
|
||||
default: false,
|
||||
type: 'string'
|
||||
})
|
||||
.option('format', {
|
||||
alias: 'f',
|
||||
describe: 'Output format',
|
||||
@@ -96,7 +90,7 @@ export const cli = yargs
|
||||
.exitProcess(true)
|
||||
.parse(process.argv);
|
||||
|
||||
const extractTask = new ExtractTask(cli.input, cli.output, {
|
||||
const extractTask = new ExtractTask(cli.input as unknown as string[], cli.output, {
|
||||
replace: cli.replace,
|
||||
patterns: cli.patterns
|
||||
});
|
||||
@@ -105,13 +99,9 @@ const extractTask = new ExtractTask(cli.input, cli.output, {
|
||||
const parsers: ParserInterface[] = [
|
||||
new PipeParser(),
|
||||
new DirectiveParser(),
|
||||
new ServiceParser()
|
||||
new ServiceParser(),
|
||||
new MarkerParser()
|
||||
];
|
||||
if (cli.marker) {
|
||||
parsers.push(new FunctionParser({
|
||||
identifier: cli.marker
|
||||
}));
|
||||
}
|
||||
extractTask.setParsers(parsers);
|
||||
|
||||
// Post processors
|
||||
|
||||
@@ -100,17 +100,20 @@ export class ExtractTask implements TaskInterface {
|
||||
* Extract strings from specified input dirs using configured parsers
|
||||
*/
|
||||
protected extract(): TranslationCollection {
|
||||
let extracted: TranslationCollection = new TranslationCollection();
|
||||
let collection: TranslationCollection = new TranslationCollection();
|
||||
this.inputs.forEach(dir => {
|
||||
this.readDir(dir, this.options.patterns).forEach(path => {
|
||||
this.out(dim('- %s'), path);
|
||||
const contents: string = fs.readFileSync(path, 'utf-8');
|
||||
this.parsers.forEach(parser => {
|
||||
extracted = extracted.union(parser.extract(contents, path));
|
||||
const extracted = parser.extract(contents, path);
|
||||
if (extracted) {
|
||||
collection = collection.union(extracted);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
return extracted;
|
||||
return collection;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user