feat(i18n): pass translation config directly into ngc (#10622)
This commit is contained in:
@ -6,11 +6,14 @@ import {check, tsc} from './tsc';
|
||||
|
||||
import NgOptions from './options';
|
||||
import {MetadataWriterHost, TsickleHost} from './compiler_host';
|
||||
import {CliOptions} from './cli_options';
|
||||
|
||||
export type CodegenExtension = (ngOptions: NgOptions, program: ts.Program, host: ts.CompilerHost) =>
|
||||
Promise<void>;
|
||||
export type CodegenExtension =
|
||||
(ngOptions: NgOptions, cliOptions: CliOptions, program: ts.Program, host: ts.CompilerHost) =>
|
||||
Promise<void>;
|
||||
|
||||
export function main(project: string, basePath?: string, codegen?: CodegenExtension): Promise<any> {
|
||||
export function main(
|
||||
project: string, cliOptions: CliOptions, codegen?: CodegenExtension): Promise<any> {
|
||||
try {
|
||||
let projectDir = project;
|
||||
if (fs.lstatSync(project).isFile()) {
|
||||
@ -18,7 +21,7 @@ export function main(project: string, basePath?: string, codegen?: CodegenExtens
|
||||
}
|
||||
|
||||
// file names in tsconfig are resolved relative to this absolute path
|
||||
basePath = path.resolve(process.cwd(), basePath || projectDir);
|
||||
const basePath = path.resolve(process.cwd(), cliOptions.basePath || projectDir);
|
||||
|
||||
// read the configuration options from wherever you store them
|
||||
const {parsed, ngOptions} = tsc.readConfiguration(project, basePath);
|
||||
@ -32,7 +35,7 @@ export function main(project: string, basePath?: string, codegen?: CodegenExtens
|
||||
if (ngOptions.skipTemplateCodegen || !codegen) {
|
||||
codegen = () => Promise.resolve(null);
|
||||
}
|
||||
return codegen(ngOptions, program, host).then(() => {
|
||||
return codegen(ngOptions, cliOptions, program, host).then(() => {
|
||||
// Create a new program since codegen files were created after making the old program
|
||||
const newProgram = ts.createProgram(parsed.fileNames, parsed.options, host, program);
|
||||
tsc.typeCheck(host, newProgram);
|
||||
@ -59,11 +62,11 @@ export function main(project: string, basePath?: string, codegen?: CodegenExtens
|
||||
// CLI entry point
|
||||
if (require.main === module) {
|
||||
const args = require('minimist')(process.argv.slice(2));
|
||||
main(args.p || args.project || '.', args.basePath)
|
||||
.then(exitCode => process.exit(exitCode))
|
||||
.catch(e => {
|
||||
console.error(e.stack);
|
||||
console.error('Compilation failed');
|
||||
process.exit(1);
|
||||
});
|
||||
const project = args.p || args.project || '.';
|
||||
const cliOptions = new CliOptions(args);
|
||||
main(project, cliOptions).then((exitCode: any) => process.exit(exitCode)).catch((e: any) => {
|
||||
console.error(e.stack);
|
||||
console.error('Compilation failed');
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user