2018-11-05 19:21:27 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#!/usr/bin/env node
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Imports
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const {extend, parse} = require('cjson');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const {readFileSync, writeFileSync} = require('fs');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const {join, resolve} = require('path');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Constants
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const ROOT_DIR = resolve(__dirname, '..');
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-02 19:26:14 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const TS_CONFIG_PATH = join(ROOT_DIR, 'tsconfig.json');
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 19:21:27 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const NG_COMPILER_OPTS = {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  angularCompilerOptions: {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-01 00:54:00 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    enableIvy: false,
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 19:21:27 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  },
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Run
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								_main(process.argv.slice(2));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Functions - Definitions
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-02 21:53:49 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								function _main() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-01 00:54:00 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  // Enable ViewIngine/Disable Ivy in TS config.
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-02 19:26:14 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  console.log(`\nModifying \`${TS_CONFIG_PATH}\`...`);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const oldTsConfigStr = readFileSync(TS_CONFIG_PATH, 'utf8');
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 19:21:27 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const oldTsConfigObj = parse(oldTsConfigStr);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const newTsConfigObj = extend(true, oldTsConfigObj, NG_COMPILER_OPTS);
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-01 02:24:13 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  const newTsConfigStr = `${JSON.stringify(newTsConfigObj, null, 2)}\n`;
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-02 21:53:49 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  console.log(`\nNew config: ${newTsConfigStr}`);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-02 19:26:14 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  writeFileSync(TS_CONFIG_PATH, newTsConfigStr);
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 19:21:27 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-02 21:53:49 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  // Done.
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-01 00:54:00 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  console.log('\nReady to build with ViewEngine!');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  console.log('(To switch back to Ivy (with packages from npm), undo the changes in ' +
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-02 19:26:14 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              `\`${TS_CONFIG_PATH}\` and run \`yarn aio-use-npm && yarn example-use-npm\`.)`);
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-05 19:21:27 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |