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 nodeFs = require('fs');
const GENERATED_FILES = /\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/; 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 = `/** const PREAMBLE = `/**
* This file is generated by the Angular 2 template compiler. * This file is generated by the Angular 2 template compiler.
@ -94,9 +95,13 @@ export class CodeGenerator {
} }
codegen(): Promise<any> { codegen(): Promise<any> {
const filePaths = this.program.getSourceFiles() // Compare with false since the default should be true
.map(sf => this.reflectorHost.getCanonicalFileName(sf.fileName)) const skipFileNames = (this.options.generateCodeForLibraries === false) ?
.filter(f => !GENERATED_FILES.test(f)); 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 fileMetas = filePaths.map((filePath) => this.readFileMetadata(filePath));
const ngModules = fileMetas.reduce((ngModules, fileMeta) => { const ngModules = fileMetas.reduce((ngModules, fileMeta) => {
ngModules.push(...fileMeta.ngModules); 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 // Don't produce .ngfactory.ts or .css.shim.ts files
skipTemplateCodegen: boolean; 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 // Print extra information while running the compiler
trace: boolean; trace: boolean;