| 
									
										
										
										
											2018-02-02 15:25:33 -08: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @fileoverview Read a tsconfig.json file intended to produce production mode | 
					
						
							|  |  |  |  * JS output, modify it to produce esm5 output instead, and write the result | 
					
						
							|  |  |  |  * to disk. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const fs = require('fs'); | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function main(args) { | 
					
						
							|  |  |  |   if (args.length < 3) { | 
					
						
							|  |  |  |     console.error('Usage: $0 input.tsconfig.json output.tsconfig.json newRoot binDir'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   [input, output, newRoot, binDir] = args; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const data = JSON.parse(fs.readFileSync(input, {encoding: 'utf-8'})); | 
					
						
							|  |  |  |   data['compilerOptions']['target'] = 'es5'; | 
					
						
							|  |  |  |   data['bazelOptions']['es5Mode'] = true; | 
					
						
							| 
									
										
										
										
											2018-11-20 21:06:17 +01:00
										 |  |  |   data['compilerOptions']['outDir'] = path.posix.join(data['compilerOptions']['outDir'], newRoot); | 
					
						
							| 
									
										
										
										
											2018-02-02 15:25:33 -08:00
										 |  |  |   if (data['angularCompilerOptions']) { | 
					
						
							| 
									
										
										
										
											2018-11-20 21:06:17 +01:00
										 |  |  |     // Relative path to the execroot that refers to the directory for the ES5 output files.
 | 
					
						
							|  |  |  |     const newOutputBase = path.posix.join(binDir, newRoot); | 
					
						
							| 
									
										
										
										
											2018-03-29 18:21:40 -07:00
										 |  |  |     // Don't enable tsickle's closure conversions
 | 
					
						
							|  |  |  |     data['angularCompilerOptions']['annotateForClosureCompiler'] = false; | 
					
						
							| 
									
										
										
										
											2018-11-20 21:06:17 +01:00
										 |  |  |     // Note: It's important that the "expectedOut" is only modified in a way that still
 | 
					
						
							|  |  |  |     // keeps posix normalized paths. Otherwise this could cause unexpected behavior because
 | 
					
						
							|  |  |  |     // ngc-wrapped is expecting POSIX paths and the TypeScript Bazel rules by default only pass
 | 
					
						
							|  |  |  |     // POSIX paths as well.
 | 
					
						
							| 
									
										
										
										
											2018-02-02 15:25:33 -08:00
										 |  |  |     data['angularCompilerOptions']['expectedOut'] = | 
					
						
							|  |  |  |         data['angularCompilerOptions']['expectedOut'].map( | 
					
						
							| 
									
										
										
										
											2018-11-20 21:06:17 +01:00
										 |  |  |             f => f.replace(/\.closure\.js$/, '.js').replace(binDir, newOutputBase)); | 
					
						
							| 
									
										
										
										
											2018-02-02 15:25:33 -08:00
										 |  |  |   } | 
					
						
							|  |  |  |   fs.writeFileSync(output, JSON.stringify(data)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (require.main === module) { | 
					
						
							|  |  |  |   process.exitCode = main(process.argv.slice(2)); | 
					
						
							|  |  |  | } |