feat(i18n): pass translation config directly into ngc (#10622)
This commit is contained in:
@ -2,5 +2,6 @@ export {MetadataWriterHost, TsickleHost} from './src/compiler_host';
|
||||
export {CodegenExtension, main} from './src/main';
|
||||
|
||||
export {default as AngularCompilerOptions} from './src/options';
|
||||
export * from './src/cli_options';
|
||||
export * from './src/collector';
|
||||
export * from './src/schema';
|
||||
|
34
tools/@angular/tsc-wrapped/src/cli_options.ts
Normal file
34
tools/@angular/tsc-wrapped/src/cli_options.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
export class CliOptions {
|
||||
public basePath: string;
|
||||
constructor({basePath = null}: {basePath?: string}) { this.basePath = basePath; }
|
||||
}
|
||||
|
||||
export class I18nExtractionCliOptions extends CliOptions {
|
||||
public i18nFormat: string;
|
||||
|
||||
constructor({i18nFormat = null}: {i18nFormat?: string}) {
|
||||
super({});
|
||||
this.i18nFormat = i18nFormat;
|
||||
}
|
||||
}
|
||||
|
||||
export class NgcCliOptions extends CliOptions {
|
||||
public i18nFormat: string;
|
||||
public i18nFile: string;
|
||||
public locale: string;
|
||||
|
||||
constructor({i18nFormat = null, i18nFile = null, locale = null, basePath = null}:
|
||||
{i18nFormat?: string, i18nFile?: string, locale?: string, basePath?: string}) {
|
||||
super({basePath: basePath});
|
||||
this.i18nFormat = i18nFormat;
|
||||
this.i18nFile = i18nFile;
|
||||
this.locale = locale;
|
||||
}
|
||||
}
|
@ -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