buildr
Version:
The (Java|Coffee)Script and (CSS|Less) (Builder|Bundler|Packer|Minifier|Merger|Checker)
70 lines (58 loc) • 1.63 kB
JavaScript
(function() {
var argv, buildr, cson, data, filename, fs, optimist, path, preprocessors;
cson = require('cson');
fs = require('fs');
path = require('path');
buildr = require(__dirname + '/../lib/buildr');
optimist = require('optimist');
argv = optimist.options('file', {
alias: 'f',
"default": 'buildr.cson'
}).argv;
filename = path.resolve(argv.file);
preprocessors = [
function(data) {
var m, new_data, p;
new_data = data;
p = /##def\s+(\w+)\s*"(.*?)"/g;
while (m = p.exec(data)) {
console.log("--> " + m[0]);
new_data = new_data.replace(RegExp(m[1], 'g'), m[2]);
}
return new_data;
}
];
data = '';
fs.exists(filename, function(exists) {
if (exists) {
return fs.readFile(filename, function(err, d) {
var p, _i, _len;
if (err) {
throw err;
}
data = d.toString();
console.log("Preprocessing configuration file...");
for (_i = 0, _len = preprocessors.length; _i < _len; _i++) {
p = preprocessors[_i];
data = p(data);
}
console.log("Preprocessed.");
return cson.parse(data, function(err, config) {
var myBuildr;
if (err) {
throw err;
}
myBuildr = buildr.createInstance(config);
return myBuildr.process(function(err) {
if (err) {
throw err;
}
});
});
});
} else {
return console.error("Configuration file not found: " + filename);
}
});
}).call(this);