Fix exit code. Give a specific type. Add test cases.

This commit is contained in:
Bowen Ni
2016-11-30 16:37:28 -08:00
committed by Alex Rickabaugh
parent 9761db5ac2
commit 6ea3ab7e14
2 changed files with 68 additions and 12 deletions

View File

@ -22,14 +22,14 @@ function codegen(
return CodeGenerator.create(ngOptions, cliOptions, program, host).codegen();
}
export function main(args: any, consoleError: any): Promise<number> {
export function main(args: any, consoleError: (s: string) => void = console.error): Promise<number> {
const project = args.p || args.project || '.';
const cliOptions = new tsc.NgcCliOptions(args);
return tsc.main(project, cliOptions, codegen).then(() => 0).catch(e => {
if (e instanceof tsc.UserError) {
consoleError(e.message);
return Promise.resolve(0);
return Promise.resolve(1);
} else {
consoleError(e.stack);
consoleError('Compilation failed');
@ -41,5 +41,5 @@ export function main(args: any, consoleError: any): Promise<number> {
// CLI entry point
if (require.main === module) {
const args = require('minimist')(process.argv.slice(2));
main(args, console.error).then((exitCode: number) => process.exit(exitCode));
main(args).then((exitCode: number) => process.exit(exitCode));
}