2016-06-01 17:58:11 -04:00
|
|
|
#!/usr/bin/env node
|
2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2016-06-01 17:58:11 -04:00
|
|
|
/**
|
|
|
|
* Extract i18n messages from source code
|
|
|
|
*/
|
2017-03-27 12:44:35 -04:00
|
|
|
// Must be imported first, because Angular decorators throw on load.
|
2016-06-01 17:58:11 -04:00
|
|
|
import 'reflect-metadata';
|
2017-09-12 18:53:17 -04:00
|
|
|
import * as api from './transformers/api';
|
|
|
|
import {ParsedConfiguration} from './perform_compile';
|
2017-09-13 19:55:42 -04:00
|
|
|
import {main, readCommandLineAndConfiguration} from './main';
|
2019-06-06 15:22:32 -04:00
|
|
|
import {setFileSystem, NodeJSFileSystem} from './ngtsc/file_system';
|
2016-06-01 17:58:11 -04:00
|
|
|
|
2017-09-13 19:55:42 -04:00
|
|
|
export function mainXi18n(
|
|
|
|
args: string[], consoleError: (msg: string) => void = console.error): number {
|
2017-09-12 18:53:17 -04:00
|
|
|
const config = readXi18nCommandLineAndConfiguration(args);
|
2019-06-06 15:22:32 -04:00
|
|
|
return main(args, consoleError, config, undefined, undefined, undefined);
|
2017-09-12 18:53:17 -04:00
|
|
|
}
|
2016-10-21 18:17:57 -04:00
|
|
|
|
2017-09-12 18:53:17 -04:00
|
|
|
function readXi18nCommandLineAndConfiguration(args: string[]): ParsedConfiguration {
|
|
|
|
const options: api.CompilerOptions = {};
|
|
|
|
const parsedArgs = require('minimist')(args);
|
|
|
|
if (parsedArgs.outFile) options.i18nOutFile = parsedArgs.outFile;
|
|
|
|
if (parsedArgs.i18nFormat) options.i18nOutFormat = parsedArgs.i18nFormat;
|
|
|
|
if (parsedArgs.locale) options.i18nOutLocale = parsedArgs.locale;
|
2016-06-01 17:58:11 -04:00
|
|
|
|
2017-09-12 18:53:17 -04:00
|
|
|
const config = readCommandLineAndConfiguration(args, options, [
|
|
|
|
'outFile',
|
|
|
|
'i18nFormat',
|
|
|
|
'locale',
|
|
|
|
]);
|
|
|
|
// only emit the i18nBundle but nothing else.
|
|
|
|
return {...config, emitFlags: api.EmitFlags.I18nBundle};
|
2016-06-01 17:58:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry point
|
|
|
|
if (require.main === module) {
|
2017-09-12 18:53:17 -04:00
|
|
|
const args = process.argv.slice(2);
|
2019-06-06 15:22:32 -04:00
|
|
|
// We are running the real compiler so run against the real file-system
|
|
|
|
setFileSystem(new NodeJSFileSystem());
|
2017-09-13 19:55:42 -04:00
|
|
|
process.exitCode = mainXi18n(args);
|
|
|
|
}
|