2016-05-03 20:31:40 -04:00
|
|
|
#!/usr/bin/env node
|
2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-04-29 13:35:36 -04:00
|
|
|
|
2017-03-27 12:44:35 -04:00
|
|
|
// Must be imported first, because Angular decorators throw on load.
|
2016-04-29 13:35:36 -04:00
|
|
|
import 'reflect-metadata';
|
|
|
|
|
|
|
|
import * as ts from 'typescript';
|
2016-05-27 19:22:16 -04:00
|
|
|
import * as tsc from '@angular/tsc-wrapped';
|
2017-01-27 16:19:00 -05:00
|
|
|
import {isSyntaxError} from '@angular/compiler';
|
2016-05-01 14:22:39 -04:00
|
|
|
|
2016-05-24 13:53:48 -04:00
|
|
|
import {CodeGenerator} from './codegen';
|
2016-05-01 14:22:39 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
function codegen(
|
2016-08-12 17:45:36 -04:00
|
|
|
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.NgcCliOptions, program: ts.Program,
|
|
|
|
host: ts.CompilerHost) {
|
2017-06-09 17:00:03 -04:00
|
|
|
if (ngOptions.enableSummariesForJit === undefined) {
|
|
|
|
// default to false
|
|
|
|
ngOptions.enableSummariesForJit = false;
|
|
|
|
}
|
2016-11-15 16:57:25 -05:00
|
|
|
return CodeGenerator.create(ngOptions, cliOptions, program, host).codegen();
|
2016-04-29 13:35:36 -04:00
|
|
|
}
|
|
|
|
|
2016-11-30 19:45:40 -05:00
|
|
|
export function main(
|
|
|
|
args: any, consoleError: (s: string) => void = console.error): Promise<number> {
|
2016-08-12 17:45:36 -04:00
|
|
|
const project = args.p || args.project || '.';
|
|
|
|
const cliOptions = new tsc.NgcCliOptions(args);
|
2016-11-30 16:59:53 -05:00
|
|
|
|
|
|
|
return tsc.main(project, cliOptions, codegen).then(() => 0).catch(e => {
|
2017-01-27 16:19:00 -05:00
|
|
|
if (e instanceof tsc.UserError || isSyntaxError(e)) {
|
2016-11-30 16:59:53 -05:00
|
|
|
consoleError(e.message);
|
2016-11-30 19:37:28 -05:00
|
|
|
return Promise.resolve(1);
|
2016-11-30 16:59:53 -05:00
|
|
|
} else {
|
|
|
|
consoleError(e.stack);
|
|
|
|
consoleError('Compilation failed');
|
|
|
|
return Promise.resolve(1);
|
|
|
|
}
|
2016-08-12 17:45:36 -04:00
|
|
|
});
|
2016-04-29 13:35:36 -04:00
|
|
|
}
|
2016-11-30 16:59:53 -05:00
|
|
|
|
|
|
|
// CLI entry point
|
|
|
|
if (require.main === module) {
|
|
|
|
const args = require('minimist')(process.argv.slice(2));
|
2016-11-30 19:37:28 -05:00
|
|
|
main(args).then((exitCode: number) => process.exit(exitCode));
|
2016-11-30 19:45:40 -05:00
|
|
|
}
|