1 | "use strict";
|
2 | const rimraf = require('rimraf');
|
3 | const path = require('path');
|
4 | const Task = require('../ember-cli/lib/models/task');
|
5 | const SilentError = require('silent-error');
|
6 | const webpack = require('webpack');
|
7 | const webpack_config_1 = require('../models/webpack-config');
|
8 | const utils_1 = require('../models/webpack-configs/utils');
|
9 | const config_1 = require('../models/config');
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | exports.default = Task.extend({
|
12 | run: function (runTaskOptions) {
|
13 | const project = this.cliProject;
|
14 | const outputPath = runTaskOptions.outputPath || config_1.CliConfig.fromProject().config.apps[0].outDir;
|
15 | if (project.root === outputPath) {
|
16 | throw new SilentError('Output path MUST not be project root directory!');
|
17 | }
|
18 | rimraf.sync(path.resolve(project.root, outputPath));
|
19 | const webpackConfig = new webpack_config_1.NgCliWebpackConfig(runTaskOptions).config;
|
20 | const webpackCompiler = webpack(webpackConfig);
|
21 | const statsConfig = utils_1.getWebpackStatsConfig(runTaskOptions.verbose);
|
22 | return new Promise((resolve, reject) => {
|
23 | const callback = (err, stats) => {
|
24 | if (err) {
|
25 | return reject(err);
|
26 | }
|
27 | this.ui.writeLine(stats.toString(statsConfig));
|
28 | if (runTaskOptions.watch) {
|
29 | return;
|
30 | }
|
31 | if (stats.hasErrors()) {
|
32 | reject();
|
33 | }
|
34 | else {
|
35 | resolve();
|
36 | }
|
37 | };
|
38 | if (runTaskOptions.watch) {
|
39 | webpackCompiler.watch({}, callback);
|
40 | }
|
41 | else {
|
42 | webpackCompiler.run(callback);
|
43 | }
|
44 | })
|
45 | .catch((err) => {
|
46 | if (err) {
|
47 | this.ui.writeError('\nAn error occured during the build:\n' + ((err && err.stack) || err));
|
48 | }
|
49 | throw err;
|
50 | });
|
51 | }
|
52 | });
|
53 |
|
\ | No newline at end of file |