2018-07-16 03:49:56 -04: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
|
|
|
|
*/
|
2018-09-03 04:21:51 -04:00
|
|
|
import * as path from 'canonical-path';
|
2018-08-09 10:59:10 -04:00
|
|
|
import * as yargs from 'yargs';
|
2018-08-09 08:54:20 -04:00
|
|
|
|
2018-12-04 16:18:00 -05:00
|
|
|
import {checkMarkerFile, writeMarkerFile} from './packages/build_marker';
|
2018-08-09 10:59:10 -04:00
|
|
|
import {DependencyHost} from './packages/dependency_host';
|
|
|
|
import {DependencyResolver} from './packages/dependency_resolver';
|
|
|
|
import {EntryPointFormat} from './packages/entry_point';
|
2018-11-25 16:40:25 -05:00
|
|
|
import {makeEntryPointBundle} from './packages/entry_point_bundle';
|
2018-08-09 10:59:10 -04:00
|
|
|
import {EntryPointFinder} from './packages/entry_point_finder';
|
|
|
|
import {Transformer} from './packages/transformer';
|
2018-07-16 03:49:56 -04:00
|
|
|
|
|
|
|
export function mainNgcc(args: string[]): number {
|
2018-08-09 10:59:10 -04:00
|
|
|
const options =
|
|
|
|
yargs
|
|
|
|
.option('s', {
|
|
|
|
alias: 'source',
|
|
|
|
describe: 'A path to the root folder to compile.',
|
|
|
|
default: './node_modules'
|
|
|
|
})
|
|
|
|
.option('f', {
|
|
|
|
alias: 'formats',
|
|
|
|
array: true,
|
|
|
|
describe: 'An array of formats to compile.',
|
|
|
|
default: ['fesm2015', 'esm2015', 'fesm5', 'esm5']
|
|
|
|
})
|
|
|
|
.option('t', {
|
|
|
|
alias: 'target',
|
|
|
|
describe: 'A path to a root folder where the compiled files will be written.',
|
|
|
|
defaultDescription: 'The `source` folder.'
|
|
|
|
})
|
|
|
|
.help()
|
|
|
|
.parse(args);
|
|
|
|
|
|
|
|
const sourcePath: string = path.resolve(options['s']);
|
|
|
|
const formats: EntryPointFormat[] = options['f'];
|
|
|
|
const targetPath: string = options['t'] || sourcePath;
|
|
|
|
|
|
|
|
const transformer = new Transformer(sourcePath, targetPath);
|
|
|
|
const host = new DependencyHost();
|
|
|
|
const resolver = new DependencyResolver(host);
|
|
|
|
const finder = new EntryPointFinder(resolver);
|
|
|
|
|
|
|
|
try {
|
|
|
|
const {entryPoints} = finder.findEntryPoints(sourcePath);
|
2018-10-16 03:56:54 -04:00
|
|
|
entryPoints.forEach(entryPoint => {
|
2018-11-25 16:40:25 -05:00
|
|
|
|
|
|
|
// Are we compiling the Angular core?
|
|
|
|
const isCore = entryPoint.name === '@angular/core';
|
|
|
|
|
2018-10-16 03:56:54 -04:00
|
|
|
// We transform the d.ts typings files while transforming one of the formats.
|
|
|
|
// This variable decides with which of the available formats to do this transform.
|
|
|
|
// It is marginally faster to process via the flat file if available.
|
2018-11-25 16:40:25 -05:00
|
|
|
const dtsTransformFormat: EntryPointFormat = entryPoint.fesm2015 ? 'fesm2015' : 'esm2015';
|
|
|
|
|
|
|
|
formats.forEach(format => {
|
2018-12-04 16:18:00 -05:00
|
|
|
if (checkMarkerFile(entryPoint, format)) {
|
|
|
|
console.warn(`Skipping ${entryPoint.name} : ${format} (already built).`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-25 16:40:25 -05:00
|
|
|
const bundle =
|
|
|
|
makeEntryPointBundle(entryPoint, isCore, format, format === dtsTransformFormat);
|
|
|
|
if (bundle === null) {
|
|
|
|
console.warn(
|
|
|
|
`Skipping ${entryPoint.name} : ${format} (no entry point file for this format).`);
|
|
|
|
} else {
|
|
|
|
transformer.transform(entryPoint, isCore, bundle);
|
|
|
|
}
|
2018-12-04 16:18:00 -05:00
|
|
|
|
|
|
|
// Write the built-with-ngcc marker
|
|
|
|
writeMarkerFile(entryPoint, format);
|
2018-11-25 16:40:25 -05:00
|
|
|
});
|
2018-10-16 03:56:54 -04:00
|
|
|
});
|
2018-08-09 10:59:10 -04:00
|
|
|
} catch (e) {
|
2019-02-14 12:59:46 -05:00
|
|
|
console.error(e.stack || e.message);
|
2018-08-09 10:59:10 -04:00
|
|
|
return 1;
|
2018-08-09 08:54:20 -04:00
|
|
|
}
|
|
|
|
|
2018-08-09 10:59:10 -04:00
|
|
|
return 0;
|
2018-08-09 08:54:20 -04:00
|
|
|
}
|