feat(compiler-cli): introduce synchronous codegen API
This commit is contained in:
parent
269bbe0e7d
commit
b00b80a45b
|
@ -40,17 +40,24 @@ export class CodeGenerator {
|
||||||
return this.compiler
|
return this.compiler
|
||||||
.analyzeModulesAsync(this.program.getSourceFiles().map(
|
.analyzeModulesAsync(this.program.getSourceFiles().map(
|
||||||
sf => this.ngCompilerHost.getCanonicalFileName(sf.fileName)))
|
sf => this.ngCompilerHost.getCanonicalFileName(sf.fileName)))
|
||||||
.then(analyzedModules => this.compiler.emitAllImpls(analyzedModules))
|
.then(analyzedModules => this.emit(analyzedModules));
|
||||||
.then(generatedModules => {
|
}
|
||||||
return generatedModules.map(generatedModule => {
|
|
||||||
const sourceFile = this.program.getSourceFile(generatedModule.srcFileUrl);
|
codegenSync(): string[] {
|
||||||
const emitPath = this.ngCompilerHost.calculateEmitPath(generatedModule.genFileUrl);
|
const analyzed = this.compiler.analyzeModulesSync(this.program.getSourceFiles().map(
|
||||||
const source =
|
sf => this.ngCompilerHost.getCanonicalFileName(sf.fileName)));
|
||||||
generatedModule.source || compiler.toTypeScript(generatedModule, PREAMBLE);
|
return this.emit(analyzed);
|
||||||
this.host.writeFile(emitPath, source, false, () => {}, [sourceFile]);
|
}
|
||||||
return emitPath;
|
|
||||||
});
|
private emit(analyzedModules: compiler.NgAnalyzedModules) {
|
||||||
});
|
const generatedModules = this.compiler.emitAllImpls(analyzedModules);
|
||||||
|
return generatedModules.map(generatedModule => {
|
||||||
|
const sourceFile = this.program.getSourceFile(generatedModule.srcFileUrl);
|
||||||
|
const emitPath = this.ngCompilerHost.calculateEmitPath(generatedModule.genFileUrl);
|
||||||
|
const source = generatedModule.source || compiler.toTypeScript(generatedModule, PREAMBLE);
|
||||||
|
this.host.writeFile(emitPath, source, false, () => {}, [sourceFile]);
|
||||||
|
return emitPath;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static create(
|
static create(
|
||||||
|
|
|
@ -258,7 +258,9 @@ export class CompilerHost implements AotCompilerHost {
|
||||||
return v3Metadata;
|
return v3Metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadResource(filePath: string): Promise<string> { return this.context.readResource(filePath); }
|
loadResource(filePath: string): Promise<string>|string {
|
||||||
|
return this.context.readResource(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
loadSummary(filePath: string): string|null {
|
loadSummary(filePath: string): string|null {
|
||||||
if (this.context.fileExists(filePath)) {
|
if (this.context.fileExists(filePath)) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ export interface ExtractorHost extends StaticSymbolResolverHost, AotSummaryResol
|
||||||
/**
|
/**
|
||||||
* Loads a resource (e.g. html / css)
|
* Loads a resource (e.g. html / css)
|
||||||
*/
|
*/
|
||||||
loadResource(path: string): Promise<string>;
|
loadResource(path: string): Promise<string>|string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Extractor {
|
export class Extractor {
|
||||||
|
|
Loading…
Reference in New Issue