2017-07-21 17:20:34 -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
|
|
|
|
*/
|
|
|
|
|
2017-08-02 14:20:07 -04:00
|
|
|
// TODO(chuckj): Remove the requirement for a fake 'reflect` implementation from
|
2017-07-21 17:20:34 -04:00
|
|
|
// the compiler
|
|
|
|
import 'reflect-metadata';
|
2017-07-26 12:40:33 -04:00
|
|
|
import {performCompilation} from '@angular/compiler-cli';
|
2017-07-21 17:20:34 -04:00
|
|
|
import * as fs from 'fs';
|
2017-07-26 12:40:33 -04:00
|
|
|
import * as path from 'path';
|
2017-07-21 17:20:34 -04:00
|
|
|
// Note, the tsc_wrapped module comes from rules_typescript, not from @angular/tsc-wrapped
|
|
|
|
import {parseTsconfig} from 'tsc_wrapped';
|
|
|
|
|
|
|
|
function main(args: string[]) {
|
|
|
|
const [{options, bazelOpts, files, config}] = parseTsconfig(args[1]);
|
|
|
|
const ngOptions: {expectedOut: string[]} = (config as any).angularCompilerOptions;
|
|
|
|
|
2017-07-26 12:40:33 -04:00
|
|
|
const parsedArgs = require('minimist')(args);
|
|
|
|
const project = parsedArgs.p || parsedArgs.project || '.';
|
|
|
|
|
|
|
|
const projectDir = fs.lstatSync(project).isFile() ? path.dirname(project) : project;
|
|
|
|
|
|
|
|
// file names in tsconfig are resolved relative to this absolute path
|
|
|
|
const basePath = path.resolve(process.cwd(), projectDir);
|
|
|
|
const result = performCompilation(basePath, files, options, ngOptions, undefined);
|
2017-07-21 17:20:34 -04:00
|
|
|
|
2017-08-02 14:20:07 -04:00
|
|
|
return result.errorCode;
|
2017-07-21 17:20:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
process.exitCode = main(process.argv.slice(2));
|
2017-07-26 12:40:33 -04:00
|
|
|
}
|