1 | "use strict";
|
2 | const webpack = require('webpack');
|
3 | const path = require('path');
|
4 | const rimraf = require('rimraf');
|
5 | const Task = require('../ember-cli/lib/models/task');
|
6 | const webpack_xi18n_config_1 = require('../models/webpack-xi18n-config');
|
7 | const config_1 = require('../models/config');
|
8 | exports.Extracti18nTask = Task.extend({
|
9 | run: function (runTaskOptions) {
|
10 | const project = this.project;
|
11 | const appConfig = config_1.CliConfig.fromProject().config.apps[0];
|
12 | const buildDir = '.tmp';
|
13 | const genDir = runTaskOptions.outputPath || appConfig.root;
|
14 | const config = new webpack_xi18n_config_1.XI18nWebpackConfig({
|
15 | genDir,
|
16 | buildDir,
|
17 | i18nFormat: runTaskOptions.i18nFormat,
|
18 | verbose: runTaskOptions.verbose,
|
19 | progress: runTaskOptions.progress
|
20 | }).config;
|
21 | const webpackCompiler = webpack(config);
|
22 | return new Promise((resolve, reject) => {
|
23 | const callback = (err, stats) => {
|
24 | if (err) {
|
25 | return reject(err);
|
26 | }
|
27 | if (stats.hasErrors()) {
|
28 | reject();
|
29 | }
|
30 | else {
|
31 | resolve();
|
32 | }
|
33 | };
|
34 | webpackCompiler.run(callback);
|
35 | })
|
36 | .then(() => {
|
37 |
|
38 | rimraf.sync(path.resolve(project.root, buildDir));
|
39 | })
|
40 | .catch((err) => {
|
41 | if (err) {
|
42 | this.ui.writeError('\nAn error occured during the i18n extraction:\n'
|
43 | + ((err && err.stack) || err));
|
44 | }
|
45 | throw err;
|
46 | });
|
47 | }
|
48 | });
|
49 |
|
\ | No newline at end of file |