Add tests and allow more liberal spacing with get/instant calls

This commit is contained in:
Kim Biesbjerg
2016-12-13 15:17:03 +01:00
parent ca8b122295
commit 8093370e94
9 changed files with 64 additions and 20 deletions

View File

@@ -21,7 +21,7 @@ const options = cli.parse({
[options.dir, options.output].forEach(dir => {
if (!fs.existsSync(dir)) {
cli.fatal('The directory path you supplied was not found: ' + dir);
cli.fatal(`The directory path you supplied was not found: '${dir}'`);
}
});
@@ -39,17 +39,12 @@ const patterns: string[] = [
'/**/*.js'
];
const extractor: Extractor = new Extractor(parsers, patterns);
try {
const extractor: Extractor = new Extractor(parsers, patterns);
cli.info(`Extracting strings from '${options.dir}'`);
const extracted: TranslationCollection = extractor.process(options.dir);
cli.ok(`* Extracted ${extracted.count()} strings`);
if (extracted.isEmpty()) {
process.exit();
}
let collection: TranslationCollection = extracted;
let compiler = new JsonCompiler();
@@ -60,8 +55,10 @@ try {
if (!options.replace && fs.existsSync(dest)) {
const existing: TranslationCollection = compiler.parse(fs.readFileSync(dest, 'utf-8'));
collection = extracted.union(existing);
cli.ok(`* Merged ${existing.count()} existing strings`);
if (existing.count() > 0) {
collection = extracted.union(existing);
cli.ok(`* Merged ${existing.count()} existing strings`);
}
if (options.clean) {
const collectionCount = collection.count();