forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
59 lines (49 loc) · 1.75 KB
/
build.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
59
import * as rimraf from 'rimraf';
import * as path from 'path';
const Task = require('../ember-cli/lib/models/task');
const SilentError = require('silent-error');
import * as webpack from 'webpack';
import { BuildTaskOptions } from '../commands/build';
import { NgCliWebpackConfig } from '../models/webpack-config';
import { getWebpackStatsConfig } from '../models/webpack-configs/utils';
import { CliConfig } from '../models/config';
export default Task.extend({
run: function (runTaskOptions: BuildTaskOptions) {
const project = this.cliProject;
const outputPath = runTaskOptions.outputPath || CliConfig.fromProject().config.apps[0].outDir;
if (project.root === outputPath) {
throw new SilentError ('Output path MUST not be project root directory!');
}
rimraf.sync(path.resolve(project.root, outputPath));
const webpackConfig = new NgCliWebpackConfig(runTaskOptions).config;
const webpackCompiler = webpack(webpackConfig);
const statsConfig = getWebpackStatsConfig(runTaskOptions.verbose);
return new Promise((resolve, reject) => {
const callback: webpack.compiler.CompilerCallback = (err, stats) => {
if (err) {
return reject(err);
}
this.ui.writeLine(stats.toString(statsConfig));
if (runTaskOptions.watch) {
return;
}
if (stats.hasErrors()) {
reject();
} else {
resolve();
}
};
if (runTaskOptions.watch) {
webpackCompiler.watch({}, callback);
} else {
webpackCompiler.run(callback);
}
})
.catch((err: Error) => {
if (err) {
this.ui.writeError('\nAn error occured during the build:\n' + ((err && err.stack) || err));
}
throw err;
});
}
});