forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract-i18n.ts
58 lines (46 loc) · 1.46 KB
/
extract-i18n.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import * as webpack from 'webpack';
import * as path from 'path';
import * as rimraf from 'rimraf';
const Task = require('../ember-cli/lib/models/task');
import {XI18nWebpackConfig} from '../models/webpack-xi18n-config';
import {CliConfig} from '../models/config';
export const Extracti18nTask = Task.extend({
run: function (runTaskOptions: any) {
const project = this.project;
const appConfig = CliConfig.fromProject().config.apps[0];
const buildDir = '.tmp';
const genDir = runTaskOptions.outputPath || appConfig.root;
const config = new XI18nWebpackConfig({
genDir,
buildDir,
i18nFormat: runTaskOptions.i18nFormat,
verbose: runTaskOptions.verbose,
progress: runTaskOptions.progress
}).config;
const webpackCompiler = webpack(config);
return new Promise((resolve, reject) => {
const callback: webpack.compiler.CompilerCallback = (err, stats) => {
if (err) {
return reject(err);
}
if (stats.hasErrors()) {
reject();
} else {
resolve();
}
};
webpackCompiler.run(callback);
})
.then(() => {
// Deletes temporary build folder
rimraf.sync(path.resolve(project.root, buildDir));
})
.catch((err: Error) => {
if (err) {
this.ui.writeError('\nAn error occured during the i18n extraction:\n'
+ ((err && err.stack) || err));
}
throw err;
});
}
});