2016-06-01 14:58:11 -07:00
|
|
|
#!/usr/bin/env node
|
2016-06-23 09:47:54 -07: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 14:58:11 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract i18n messages from source code
|
|
|
|
*/
|
2017-03-27 09:44:35 -07:00
|
|
|
// Must be imported first, because Angular decorators throw on load.
|
2016-06-01 14:58:11 -07:00
|
|
|
import 'reflect-metadata';
|
|
|
|
|
2016-10-21 15:17:57 -07:00
|
|
|
import * as tsc from '@angular/tsc-wrapped';
|
2016-06-01 14:58:11 -07:00
|
|
|
import * as ts from 'typescript';
|
2016-10-21 15:17:57 -07:00
|
|
|
|
|
|
|
import {Extractor} from './extractor';
|
2016-06-01 14:58:11 -07:00
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
function extract(
|
2016-08-12 14:45:36 -07:00
|
|
|
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions,
|
2016-12-19 11:56:10 -08:00
|
|
|
program: ts.Program, host: ts.CompilerHost): Promise<void> {
|
2017-02-16 17:03:18 +01:00
|
|
|
return Extractor.create(ngOptions, program, host, cliOptions.locale)
|
2017-03-24 09:59:58 -07:00
|
|
|
.extract(cliOptions.i18nFormat !, cliOptions.outFile);
|
2016-06-01 14:58:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry point
|
|
|
|
if (require.main === module) {
|
|
|
|
const args = require('minimist')(process.argv.slice(2));
|
2016-08-12 14:45:36 -07:00
|
|
|
const project = args.p || args.project || '.';
|
|
|
|
const cliOptions = new tsc.I18nExtractionCliOptions(args);
|
2017-01-26 10:27:07 +01:00
|
|
|
tsc.main(project, cliOptions, extract, {noEmit: true})
|
2016-08-12 14:45:36 -07:00
|
|
|
.then((exitCode: any) => process.exit(exitCode))
|
|
|
|
.catch((e: any) => {
|
2016-06-08 16:38:52 -07:00
|
|
|
console.error(e.stack);
|
2016-07-21 13:56:58 -07:00
|
|
|
console.error('Extraction failed');
|
2016-06-08 16:38:52 -07:00
|
|
|
process.exit(1);
|
|
|
|
});
|
2016-08-12 14:45:36 -07:00
|
|
|
}
|