| 
									
										
										
										
											2018-07-16 08:49:56 +01:00
										 |  |  |  | #!/usr/bin/env node | 
					
						
							|  |  |  |  | /** | 
					
						
							|  |  |  |  |  * @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
 | 
					
						
							|  |  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  | import * as yargs from 'yargs'; | 
					
						
							| 
									
										
										
										
											2018-07-16 08:49:56 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 20:22:32 +01:00
										 |  |  |  | import {resolve, setFileSystem, NodeJSFileSystem} from '../src/ngtsc/file_system'; | 
					
						
							| 
									
										
										
										
											2018-07-16 08:49:56 +01:00
										 |  |  |  | import {mainNgcc} from './src/main'; | 
					
						
							| 
									
										
										
										
											2019-03-29 10:13:14 +00:00
										 |  |  |  | import {ConsoleLogger, LogLevel} from './src/logging/console_logger'; | 
					
						
							| 
									
										
										
										
											2018-07-16 08:49:56 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | // CLI entry point
 | 
					
						
							|  |  |  |  | if (require.main === module) { | 
					
						
							|  |  |  |  |   const args = process.argv.slice(2); | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |   const options = | 
					
						
							|  |  |  |  |       yargs | 
					
						
							|  |  |  |  |           .option('s', { | 
					
						
							|  |  |  |  |             alias: 'source', | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:59 +00:00
										 |  |  |  |             describe: | 
					
						
							|  |  |  |  |                 'A path (relative to the working directory) of the `node_modules` folder to process.', | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |             default: './node_modules' | 
					
						
							|  |  |  |  |           }) | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |           .option('f', {alias: 'formats', hidden: true, array: true}) | 
					
						
							|  |  |  |  |           .option('p', { | 
					
						
							|  |  |  |  |             alias: 'properties', | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |             array: true, | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |             describe: | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:59 +00:00
										 |  |  |  |                 'An array of names of properties in package.json to compile (e.g. `module` or `es2015`)\n' + | 
					
						
							|  |  |  |  |                 'Each of these properties should hold the path to a bundle-format.\n' + | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |                 'If provided, only the specified properties are considered for processing.\n' + | 
					
						
							|  |  |  |  |                 'If not provided, all the supported format properties (e.g. fesm2015, fesm5, es2015, esm2015, esm5, main, module) in the package.json are considered.' | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |           }) | 
					
						
							|  |  |  |  |           .option('t', { | 
					
						
							|  |  |  |  |             alias: 'target', | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:59 +00:00
										 |  |  |  |             describe: | 
					
						
							|  |  |  |  |                 'A relative path (from the `source` path) to a single entry-point to process (plus its dependencies).', | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |           }) | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |           .option('first-only', { | 
					
						
							|  |  |  |  |             describe: | 
					
						
							| 
									
										
										
										
											2019-03-29 10:13:14 +00:00
										 |  |  |  |                 'If specified then only the first matching package.json property will be compiled.', | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |             type: 'boolean' | 
					
						
							|  |  |  |  |           }) | 
					
						
							| 
									
										
										
										
											2019-03-29 10:13:14 +00:00
										 |  |  |  |           .option('l', { | 
					
						
							|  |  |  |  |             alias: 'loglevel', | 
					
						
							|  |  |  |  |             describe: 'The lowest severity logging message that should be output.', | 
					
						
							|  |  |  |  |             choices: ['debug', 'info', 'warn', 'error'], | 
					
						
							|  |  |  |  |           }) | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |           .help() | 
					
						
							|  |  |  |  |           .parse(args); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |   if (options['f'] && options['f'].length) { | 
					
						
							|  |  |  |  |     console.error( | 
					
						
							|  |  |  |  |         'The formats option (-f/--formats) has been removed. Consider the properties option (-p/--properties) instead.'); | 
					
						
							|  |  |  |  |     process.exit(1); | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-06-06 20:22:32 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   setFileSystem(new NodeJSFileSystem()); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   const baseSourcePath = resolve(options['s'] || './node_modules'); | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:59 +00:00
										 |  |  |  |   const propertiesToConsider: string[] = options['p']; | 
					
						
							|  |  |  |  |   const targetEntryPointPath = options['t'] ? options['t'] : undefined; | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |   const compileAllFormats = !options['first-only']; | 
					
						
							| 
									
										
										
										
											2019-04-03 16:37:36 +01:00
										 |  |  |  |   const logLevel = options['l'] as keyof typeof LogLevel | undefined; | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |   try { | 
					
						
							| 
									
										
										
										
											2019-03-29 10:13:14 +00:00
										 |  |  |  |     mainNgcc({ | 
					
						
							|  |  |  |  |       basePath: baseSourcePath, | 
					
						
							|  |  |  |  |       propertiesToConsider, | 
					
						
							|  |  |  |  |       targetEntryPointPath, | 
					
						
							|  |  |  |  |       compileAllFormats, | 
					
						
							| 
									
										
										
										
											2019-04-03 16:37:36 +01:00
										 |  |  |  |       logger: logLevel && new ConsoleLogger(LogLevel[logLevel]), | 
					
						
							| 
									
										
										
										
											2019-03-29 10:13:14 +00:00
										 |  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-03-20 13:47:58 +00:00
										 |  |  |  |     process.exitCode = 0; | 
					
						
							|  |  |  |  |   } catch (e) { | 
					
						
							|  |  |  |  |     console.error(e.stack || e.message); | 
					
						
							|  |  |  |  |     process.exitCode = 1; | 
					
						
							|  |  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-16 08:49:56 +01:00
										 |  |  |  | } |