-
Notifications
You must be signed in to change notification settings - Fork 20
/
run.js
35 lines (28 loc) · 945 Bytes
/
run.js
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
const webpack = require('webpack');
const tasks = new Map();
function run(task) {
const start = new Date();
console.log(`Starting '${task}'...`);
return Promise.resolve().then(() => tasks.get(task)()).then(() => {
console.log(`Finished '${task}' after ${new Date().getTime() - start.getTime()}ms`);
}, err => console.error(err.stack));
}
tasks.set('clean', () => del(['public/dist/*', '!public/dist/.git'], { dot: true }));
tasks.set('bundle', () => {
const webpackConfig = require('./webpack.config');
return new Promise((resolve, reject) => {
webpack(webpackConfig).run((err, stats) => {
if (err) {
reject(err);
} else {
console.log(stats.toString(webpackConfig.stats));
resolve();
}
});
});
});
tasks.set('build', () => {
return Promise.resolve()
.then(() => run('bundle'));
});
run(/^\w/.test(process.argv[2] || '') ? process.argv[2] : 'start' /* default */);