UNPKG

1.17 kBJavaScriptView Raw
1import * as path from "path";
2import _ from "lodash";
3import rimraf from "rimraf";
4
5import prettyConsole from "./libs/pretty_console";
6import build from "./build";
7import dev from "./dev";
8
9require("es6-promise").polyfill();
10
11exports.develop = execute(develop);
12exports.start = exports.develop; // convenience alias
13exports.build = execute(build);
14
15function 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
27function defaultConfiguration() {
28 return {
29 port: 3000,
30 output: "build",
31 console: prettyConsole,
32 };
33}
34
35function 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}