Use proper exit codes
This commit is contained in:
parent
a83123fb12
commit
9908681243
@ -1,4 +1,5 @@
|
|||||||
import * as yargs from 'yargs';
|
import * as yargs from 'yargs';
|
||||||
|
import { red, green } from 'colorette';
|
||||||
|
|
||||||
import { ExtractTask } from './tasks/extract.task';
|
import { ExtractTask } from './tasks/extract.task';
|
||||||
import { ParserInterface } from '../parsers/parser.interface';
|
import { ParserInterface } from '../parsers/parser.interface';
|
||||||
@ -148,6 +149,13 @@ const compiler: CompilerInterface = CompilerFactory.create(cli.format, {
|
|||||||
});
|
});
|
||||||
extractTask.setCompiler(compiler);
|
extractTask.setCompiler(compiler);
|
||||||
|
|
||||||
extractTask.execute();
|
// Run task
|
||||||
|
try {
|
||||||
console.log(donateMessage);
|
extractTask.execute();
|
||||||
|
console.log(green('\nDone.\n'));
|
||||||
|
console.log(donateMessage);
|
||||||
|
process.exit(0);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(red(`\nAn error occurred: ${e}\n`));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
@ -59,28 +59,30 @@ export class ExtractTask implements TaskInterface {
|
|||||||
try {
|
try {
|
||||||
existing = this.compiler.parse(fs.readFileSync(outputPath, 'utf-8'));
|
existing = this.compiler.parse(fs.readFileSync(outputPath, 'utf-8'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.out(`%s %s`, dim(`- ${outputPath}`), red(`(merge error: ${e})`));
|
this.out(`%s %s`, dim(`- ${outputPath}`), red(`[ERROR]`));
|
||||||
return;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge extracted strings with existing
|
// merge extracted strings with existing
|
||||||
const draft = extracted.union(existing);
|
const draft = extracted.union(existing);
|
||||||
|
|
||||||
if (existing.isEmpty()) {
|
|
||||||
this.out(dim(`- ${outputPath}`));
|
|
||||||
} else {
|
|
||||||
this.out(`%s %s`, dim(`- ${outputPath}`), green('(merged)'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run collection through post processors
|
// Run collection through post processors
|
||||||
const final = this.process(draft, extracted, existing);
|
const final = this.process(draft, extracted, existing);
|
||||||
|
|
||||||
// Save to file
|
// Save
|
||||||
this.save(outputPath, final);
|
try {
|
||||||
|
let event = 'CREATED';
|
||||||
|
if (!fs.existsSync(outputPath)) {
|
||||||
|
this.options.replace ? event = 'REPLACED' : event = 'MERGED';
|
||||||
|
}
|
||||||
|
this.save(outputPath, final);
|
||||||
|
this.out(`%s %s`, dim(`- ${outputPath}`), green(`[${event}]`));
|
||||||
|
} catch (e) {
|
||||||
|
this.out(`%s %s`, dim(`- ${outputPath}`), red(`[ERROR]`));
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.out(green('\nDone.\n'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setParsers(parsers: ParserInterface[]): this {
|
public setParsers(parsers: ParserInterface[]): this {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user