-
Notifications
You must be signed in to change notification settings - Fork 412
/
Copy pathbuild.js
executable file
·74 lines (60 loc) · 1.91 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
#!/usr/bin/env node
// Simple Node Project Builder
// Copies, symlinks and compresses files into the right locations.
// Can also compact & bundle JS/CSS together for distribution.
// Copyright (c) 2015 Joseph Huckaby, MIT License.
var fs = require('fs');
var path = require('path');
var util = require('util');
var async = require('async');
var Tools = require('pixl-tools');
var mkdirp = Tools.mkdirp;
var BuildTools = require('./build-tools.js');
var setup = require('../sample_conf/setup.json');
var mode = 'dist';
if (process.argv.length > 2) mode = process.argv[2];
var steps = setup.build.common || [];
if (setup.build[mode]) {
steps = steps.concat( setup.build[mode] );
}
// chdir to the proper server root dir
process.chdir( path.dirname( __dirname ) );
// make sure we have a logs dir
mkdirp.sync( 'logs' );
fs.chmodSync( 'logs', "755" );
// log to file instead of console
console.log = function(msg, data) {
if (data) msg += ' ' + JSON.stringify(data);
fs.appendFile( 'logs/install.log', msg + "\n", function() {} );
if (mode == 'dev') process.stdout.write( msg + "\n" );
};
console.log("\nBuilding project ("+mode+")...\n");
async.eachSeries( steps, function(step, callback) {
// foreach step
// util.isArray is DEPRECATED??? Nooooooooode!
var isArray = Array.isArray || util.isArray;
if (isArray(step)) {
// [ "symlinkFile", "node_modules/pixl-webapp/js", "htdocs/js/common" ],
var func = step.shift();
console.log( func + ": " + JSON.stringify(step));
step.push( callback );
BuildTools[func].apply( null, step );
}
else {
// { "action": "bundleCompress", ... }
var func = step.action;
delete step.action;
console.log( func + ": " + JSON.stringify(step));
BuildTools[func].apply( null, [step, callback] );
}
},
function(err) {
// done with iteration, check for error
if (err) {
console.error("\nBuild Error: " + err + "\n");
}
else {
console.log("\nBuild complete.\n");
}
} );
// End