forked from NodeBB/NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
109 lines (92 loc) · 2.79 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';
var async = require('async');
var winston = require('winston');
var buildStart;
exports.build = function build(targets, callback) {
buildStart = Date.now();
var db = require('./src/database');
var meta = require('./src/meta');
var plugins = require('./src/plugins');
var valid = ['js', 'clientCSS', 'acpCSS', 'tpl'];
targets = (targets === true ? valid : targets.split(',').filter(function (target) {
return valid.indexOf(target) !== -1;
}));
if (!targets) {
winston.error('[build] No valid build targets found. Aborting.');
return process.exit(0);
}
async.series([
async.apply(db.init),
async.apply(meta.themes.setupPaths),
async.apply(plugins.prepareForBuild)
], function (err) {
if (err) {
winston.error('[build] Encountered error preparing for build: ' + err.message);
return process.exit(1);
}
exports.buildTargets(targets, callback);
});
};
exports.buildTargets = function (targets, callback) {
var meta = require('./src/meta');
buildStart = buildStart || Date.now();
var step = function (startTime, target, next) {
winston.info('[build] ' + target + ' => Completed in ' + ((Date.now() - startTime) / 1000) + 's');
next();
};
async.parallel([
function (next) {
if (targets.indexOf('js') !== -1) {
winston.info('[build] Building javascript');
var startTime = Date.now();
async.series([
async.apply(meta.js.minify, 'nodebb.min.js'),
async.apply(meta.js.minify, 'acp.min.js')
], step.bind(this, startTime, 'js', next));
} else {
setImmediate(next);
}
},
function (next) {
async.eachSeries(targets, function (target, next) {
var startTime;
switch(target) {
case 'js':
setImmediate(next);
break;
case 'clientCSS':
winston.info('[build] Building client-side CSS');
startTime = Date.now();
meta.css.minify('stylesheet.css', step.bind(this, startTime, target, next));
break;
case 'acpCSS':
winston.info('[build] Building admin control panel CSS');
startTime = Date.now();
meta.css.minify('admin.css', step.bind(this, startTime, target, next));
break;
case 'tpl':
winston.info('[build] Building templates');
startTime = Date.now();
meta.templates.compile(step.bind(this, startTime, target, next));
break;
default:
winston.warn('[build] Unknown build target: \'' + target + '\'');
setImmediate(next);
break;
}
}, next);
}
], function (err) {
if (err) {
winston.error('[build] Encountered error during build step: ' + err.message);
return process.exit(1);
}
var time = (Date.now() - buildStart) / 1000;
winston.info('[build] Asset compilation successful. Completed in ' + time + 's.');
if (typeof callback === 'function') {
callback();
} else {
process.exit(0);
}
});
};