feature(ngc): allow codegen to skip over .d.ts inputs (#11021)

This commit is contained in:
Alex Eagle 2016-08-23 16:26:35 -07:00 committed by Kara
parent aa5c8ca61f
commit c7a874dd2f
2 changed files with 13 additions and 3 deletions

View File

@ -26,6 +26,7 @@ import {StaticReflector, StaticSymbol} from './static_reflector';
const nodeFs = require('fs');
const GENERATED_FILES = /\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/;
const GENERATED_OR_DTS_FILES = /\.d\.ts$|\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/;
const PREAMBLE = `/**
* This file is generated by the Angular 2 template compiler.
@ -94,9 +95,13 @@ export class CodeGenerator {
}
codegen(): Promise<any> {
const filePaths = this.program.getSourceFiles()
.map(sf => this.reflectorHost.getCanonicalFileName(sf.fileName))
.filter(f => !GENERATED_FILES.test(f));
// Compare with false since the default should be true
const skipFileNames = (this.options.generateCodeForLibraries === false) ?
GENERATED_OR_DTS_FILES :
GENERATED_FILES;
let filePaths = this.program.getSourceFiles()
.filter(sf => !skipFileNames.test(sf.fileName))
.map(sf => this.reflectorHost.getCanonicalFileName(sf.fileName));
const fileMetas = filePaths.map((filePath) => this.readFileMetadata(filePath));
const ngModules = fileMetas.reduce((ngModules, fileMeta) => {
ngModules.push(...fileMeta.ngModules);

View File

@ -16,6 +16,11 @@ interface Options extends ts.CompilerOptions {
// Don't produce .ngfactory.ts or .css.shim.ts files
skipTemplateCodegen: boolean;
// Whether to generate code for library code.
// If true, produce .ngfactory.ts and .css.shim.ts files for .d.ts inputs.
// Default is true.
generateCodeForLibraries?: boolean;
// Print extra information while running the compiler
trace: boolean;