-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·54 lines (43 loc) · 1.51 KB
/
build.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
// check if specific task was requested
let task = process.argv[2];
// get project configuration
let config = require('./project.json');
// define default tasks to run, order is being respected
let tasks = {
styles: { path: './tasks/styles' },
scripts: { path: './tasks/scripts' },
fonts: { path: './tasks/copy', id: 'Fonts' },
html: { path: './tasks/copy', id: 'HTML' },
images: { path: './tasks/images' },
sprites: { path: './tasks/sprites' }
};
// specific task requested, pick it and remove other tasks
if (tasks[task]) {
tasks = Object.defineProperty({}, task, {
value: tasks[task],
writable: true,
enumerable: true,
configurable: true
});
}
// needed modules
let chalk = require('chalk');
let async = require('async');
// measure total build time
let start = Date.now();
// translate requested build environment
let mode = chalk.blue.bold(config.env === 'prod' ? 'production' : 'develop');
// function to run once building finished
let done = () => {
let hr = chalk.green.bold(String.fromCharCode(8212).repeat(process.stdout.columns * 0.125));
let duration = Date.now() - start;
// building done
console.log(`\n${hr}\nFinished building. ${chalk.blue.bold('(')}${duration}ms${chalk.blue.bold(')')}`);
};
// log environment
console.log(`\nBuilding in ${mode} mode...\n`);
// run tasks
async.series(Object.keys(tasks).map((key) => {
return (cb) => new (require(tasks[key].path))(tasks[key]).run(cb);
}), done);