feat(compiler-cli): add an `outFile` option to ng-xi18n

Fixes #11416
Closes #14508
Closes #14657
This commit is contained in:
Marc Laval 2017-02-15 18:50:03 +01:00 committed by Igor Minar
parent 234f05996c
commit 39f56fafdd
7 changed files with 18 additions and 9 deletions

View File

@ -68,7 +68,7 @@ describe('template i18n extraction output', () => {
const genDir = 'out';
it('should extract i18n messages as xmb', () => {
const xmbOutput = path.join(outDir, 'messages.xmb');
const xmbOutput = path.join(outDir, 'custom_file.xmb');
expect(fs.existsSync(xmbOutput)).toBeTruthy();
const xmb = fs.readFileSync(xmbOutput, {encoding: 'utf-8'});
expect(xmb).toEqual(EXPECTED_XMB);

View File

@ -132,6 +132,7 @@ function i18nTest() {
angularCompilerOptions: config.ngOptions,
i18nFormat: 'xlf',
locale: null,
outFile: null,
readResource: (fileName: string) => {
readResources.push(fileName);
return hostContext.readResource(fileName);

View File

@ -23,7 +23,7 @@ function extract(
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions,
program: ts.Program, host: ts.CompilerHost): Promise<void> {
return Extractor.create(ngOptions, program, host, cliOptions.locale)
.extract(cliOptions.i18nFormat);
.extract(cliOptions.i18nFormat, cliOptions.outFile);
}
// Entry point

View File

@ -27,7 +27,7 @@ export class Extractor {
public host: ts.CompilerHost, private ngCompilerHost: CompilerHost,
private program: ts.Program) {}
extract(formatName: string): Promise<void> {
extract(formatName: string, outFile: string|null): Promise<void> {
// Checks the format and returns the extension
const ext = this.getExtension(formatName);
@ -35,7 +35,8 @@ export class Extractor {
return promiseBundle.then(bundle => {
const content = this.serialize(bundle, ext);
const dstPath = path.join(this.options.genDir, `messages.${ext}`);
const dstFile = outFile || `messages.${ext}`;
const dstPath = path.join(this.options.genDir, dstFile);
this.host.writeFile(dstPath, content, false);
});
}

View File

@ -62,6 +62,7 @@ export interface NgTools_InternalApi_NG2_ExtractI18n_Options {
readResource: (fileName: string) => Promise<string>;
// Every new property under this line should be optional.
locale?: string;
outFile?: string;
}
/**
@ -147,6 +148,6 @@ export class NgTools_InternalApi_NG_2 {
const extractor = Extractor.create(
options.angularCompilerOptions, options.program, options.host, locale, hostContext);
return extractor.extract(options.i18nFormat);
return extractor.extract(options.i18nFormat, options.outFile || null);
}
}

View File

@ -49,7 +49,7 @@ cp -v package.json $TMP
./node_modules/.bin/ngc -p tsconfig-build.json --i18nFile=src/messages.fi.xlf --locale=fi --i18nFormat=xlf
./node_modules/.bin/ng-xi18n -p tsconfig-xi18n.json --i18nFormat=xlf --locale=fr
./node_modules/.bin/ng-xi18n -p tsconfig-xi18n.json --i18nFormat=xmb
./node_modules/.bin/ng-xi18n -p tsconfig-xi18n.json --i18nFormat=xmb --outFile=custom_file.xmb
node test/test_summaries.js
node test/test_ngtools_api.js

View File

@ -11,13 +11,19 @@ export class CliOptions {
}
export class I18nExtractionCliOptions extends CliOptions {
public i18nFormat: string;
public locale: string;
i18nFormat: string|null;
locale: string|null;
outFile: string|null;
constructor({i18nFormat = null, locale = null}: {i18nFormat?: string, locale: string|null}) {
constructor({i18nFormat = null, locale = null, outFile = null}: {
i18nFormat?: string,
locale?: string,
outFile?: string,
}) {
super({});
this.i18nFormat = i18nFormat;
this.locale = locale;
this.outFile = outFile;
}
}