| 
									
										
										
										
											2017-07-21 14:20:34 -07: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO(chuckj): Remove the requirment for a fake 'reflect` implementation from
 | 
					
						
							|  |  |  | // the compiler
 | 
					
						
							|  |  |  | import 'reflect-metadata'; | 
					
						
							| 
									
										
										
										
											2017-07-26 11:40:33 -05:00
										 |  |  | import {performCompilation} from '@angular/compiler-cli'; | 
					
						
							| 
									
										
										
										
											2017-07-21 14:20:34 -07:00
										 |  |  | import * as fs from 'fs'; | 
					
						
							| 
									
										
										
										
											2017-07-26 11:40:33 -05:00
										 |  |  | import * as path from 'path'; | 
					
						
							| 
									
										
										
										
											2017-07-21 14:20:34 -07: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 11:40:33 -05: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 14:20:34 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (result === 0) { | 
					
						
							|  |  |  |     // Ensure that expected output files exist.
 | 
					
						
							|  |  |  |     if (ngOptions && ngOptions.expectedOut) { | 
					
						
							|  |  |  |       for (const out of ngOptions.expectedOut) { | 
					
						
							|  |  |  |         fs.appendFileSync(out, '', 'utf-8'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (require.main === module) { | 
					
						
							|  |  |  |   process.exitCode = main(process.argv.slice(2)); | 
					
						
							| 
									
										
										
										
											2017-07-26 11:40:33 -05:00
										 |  |  | } |