2018-07-16 03:49:56 -04: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 09:47:58 -04:00
|
|
|
|
import * as yargs from 'yargs';
|
2018-07-16 03:49:56 -04:00
|
|
|
|
|
2019-04-28 15:47:57 -04:00
|
|
|
|
import {AbsoluteFsPath} from '../src/ngtsc/path';
|
2018-07-16 03:49:56 -04:00
|
|
|
|
import {mainNgcc} from './src/main';
|
2019-03-29 06:13:14 -04:00
|
|
|
|
import {ConsoleLogger, LogLevel} from './src/logging/console_logger';
|
2018-07-16 03:49:56 -04:00
|
|
|
|
|
|
|
|
|
// CLI entry point
|
|
|
|
|
if (require.main === module) {
|
|
|
|
|
const args = process.argv.slice(2);
|
2019-03-20 09:47:58 -04:00
|
|
|
|
const options =
|
|
|
|
|
yargs
|
|
|
|
|
.option('s', {
|
|
|
|
|
alias: 'source',
|
2019-03-20 09:47:59 -04:00
|
|
|
|
describe:
|
|
|
|
|
'A path (relative to the working directory) of the `node_modules` folder to process.',
|
2019-03-20 09:47:58 -04:00
|
|
|
|
default: './node_modules'
|
|
|
|
|
})
|
2019-03-20 09:47:58 -04:00
|
|
|
|
.option('f', {alias: 'formats', hidden: true, array: true})
|
|
|
|
|
.option('p', {
|
|
|
|
|
alias: 'properties',
|
2019-03-20 09:47:58 -04:00
|
|
|
|
array: true,
|
2019-03-20 09:47:58 -04:00
|
|
|
|
describe:
|
2019-03-20 09:47:59 -04: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 09:47:58 -04: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 09:47:58 -04:00
|
|
|
|
})
|
|
|
|
|
.option('t', {
|
|
|
|
|
alias: 'target',
|
2019-03-20 09:47:59 -04:00
|
|
|
|
describe:
|
|
|
|
|
'A relative path (from the `source` path) to a single entry-point to process (plus its dependencies).',
|
2019-03-20 09:47:58 -04:00
|
|
|
|
})
|
2019-03-20 09:47:58 -04:00
|
|
|
|
.option('first-only', {
|
|
|
|
|
describe:
|
2019-03-29 06:13:14 -04:00
|
|
|
|
'If specified then only the first matching package.json property will be compiled.',
|
2019-03-20 09:47:58 -04:00
|
|
|
|
type: 'boolean'
|
|
|
|
|
})
|
2019-03-29 06:13:14 -04:00
|
|
|
|
.option('l', {
|
|
|
|
|
alias: 'loglevel',
|
|
|
|
|
describe: 'The lowest severity logging message that should be output.',
|
|
|
|
|
choices: ['debug', 'info', 'warn', 'error'],
|
|
|
|
|
})
|
2019-03-20 09:47:58 -04:00
|
|
|
|
.help()
|
|
|
|
|
.parse(args);
|
|
|
|
|
|
2019-03-20 09:47:58 -04: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-04-28 15:47:57 -04:00
|
|
|
|
const baseSourcePath = AbsoluteFsPath.resolve(options['s'] || './node_modules');
|
2019-03-20 09:47:59 -04:00
|
|
|
|
const propertiesToConsider: string[] = options['p'];
|
|
|
|
|
const targetEntryPointPath = options['t'] ? options['t'] : undefined;
|
2019-03-20 09:47:58 -04:00
|
|
|
|
const compileAllFormats = !options['first-only'];
|
2019-04-03 11:37:36 -04:00
|
|
|
|
const logLevel = options['l'] as keyof typeof LogLevel | undefined;
|
2019-03-20 09:47:58 -04:00
|
|
|
|
try {
|
2019-03-29 06:13:14 -04:00
|
|
|
|
mainNgcc({
|
|
|
|
|
basePath: baseSourcePath,
|
|
|
|
|
propertiesToConsider,
|
|
|
|
|
targetEntryPointPath,
|
|
|
|
|
compileAllFormats,
|
2019-04-03 11:37:36 -04:00
|
|
|
|
logger: logLevel && new ConsoleLogger(LogLevel[logLevel]),
|
2019-03-29 06:13:14 -04:00
|
|
|
|
});
|
2019-03-20 09:47:58 -04:00
|
|
|
|
process.exitCode = 0;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e.stack || e.message);
|
|
|
|
|
process.exitCode = 1;
|
|
|
|
|
}
|
2018-07-16 03:49:56 -04:00
|
|
|
|
}
|