1 | import * as path from "path";
|
2 | import _ from "lodash";
|
3 | import rimraf from "rimraf";
|
4 |
|
5 | import prettyConsole from "./libs/pretty_console";
|
6 | import build from "./build";
|
7 | import dev from "./dev";
|
8 |
|
9 | require("es6-promise").polyfill();
|
10 |
|
11 | exports.develop = execute(develop);
|
12 | exports.start = exports.develop;
|
13 | exports.build = execute(build);
|
14 |
|
15 | function execute(target) {
|
16 | return ({ antwar, webpack, environment }) =>
|
17 | target({
|
18 | environment,
|
19 | antwar: _.merge(
|
20 | defaultConfiguration(),
|
21 | _.isFunction(antwar) ? antwar(environment) : antwar
|
22 | ),
|
23 | webpack: webpack(environment),
|
24 | });
|
25 | }
|
26 |
|
27 | function defaultConfiguration() {
|
28 | return {
|
29 | port: 3000,
|
30 | output: "build",
|
31 | console: prettyConsole,
|
32 | };
|
33 | }
|
34 |
|
35 | function develop(configurations) {
|
36 | const cwd = process.cwd();
|
37 | const buildDir = path.join(cwd, "./.antwar");
|
38 |
|
39 | return new Promise(function(resolve, reject) {
|
40 | rimraf(buildDir, function(err) {
|
41 | if (err) {
|
42 | return reject(err);
|
43 | }
|
44 |
|
45 | return build
|
46 | .devIndex(configurations)
|
47 | .then(dev.server.bind(null, configurations))
|
48 | .then(resolve)
|
49 | .catch(reject);
|
50 | });
|
51 | });
|
52 | }
|