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 path from 'canonical-path';
|
|
|
|
|
import * as yargs from 'yargs';
|
2018-07-16 03:49:56 -04:00
|
|
|
|
|
2019-03-20 09:47:58 -04:00
|
|
|
|
import {AbsoluteFsPath} from '../src/ngtsc/path';
|
|
|
|
|
|
2018-07-16 03:49:56 -04:00
|
|
|
|
import {mainNgcc} from './src/main';
|
2019-03-20 09:47:58 -04:00
|
|
|
|
import {EntryPointJsonProperty} from './src/packages/entry_point';
|
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:58 -04:00
|
|
|
|
describe: 'A path to the `node_modules` folder to compile.',
|
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:
|
|
|
|
|
'An array of names of properties in package.json (e.g. `module` or `es2015`)\n' +
|
|
|
|
|
'These properties should hold a path to a bundle-format to compile.\n' +
|
|
|
|
|
'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:58 -04:00
|
|
|
|
describe: 'A path to a single entry-point to compile (plus its dependencies).',
|
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-03-20 09:47:58 -04:00
|
|
|
|
const baseSourcePath = AbsoluteFsPath.from(path.resolve(options['s'] || './node_modules'));
|
2019-03-20 09:47:58 -04:00
|
|
|
|
const propertiesToConsider: EntryPointJsonProperty[] = options['p'];
|
2019-03-20 09:47:58 -04:00
|
|
|
|
const targetEntryPointPath =
|
|
|
|
|
options['t'] ? AbsoluteFsPath.from(path.resolve(options['t'])) : undefined;
|
2019-03-20 09:47:58 -04:00
|
|
|
|
try {
|
2019-03-20 09:47:58 -04:00
|
|
|
|
mainNgcc({baseSourcePath, propertiesToConsider, targetEntryPointPath});
|
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
|
|
|
|
}
|