UNPKG

1.6 kBJavaScriptView Raw
1#!/usr/bin/env node
2(function() {
3 var argv, buildr, cson, data, filename, fs, optimist, path, preprocessors;
4
5 cson = require('cson');
6
7 fs = require('fs');
8
9 path = require('path');
10
11 buildr = require(__dirname + '/../lib/buildr');
12
13 optimist = require('optimist');
14
15 argv = optimist.options('file', {
16 alias: 'f',
17 "default": 'buildr.cson'
18 }).argv;
19
20 filename = path.resolve(argv.file);
21
22 preprocessors = [
23 function(data) {
24 var m, new_data, p;
25 new_data = data;
26 p = /##def\s+(\w+)\s*"(.*?)"/g;
27 while (m = p.exec(data)) {
28 console.log("--> " + m[0]);
29 new_data = new_data.replace(RegExp(m[1], 'g'), m[2]);
30 }
31 return new_data;
32 }
33 ];
34
35 data = '';
36
37 fs.exists(filename, function(exists) {
38 if (exists) {
39 return fs.readFile(filename, function(err, d) {
40 var p, _i, _len;
41 if (err) {
42 throw err;
43 }
44 data = d.toString();
45 console.log("Preprocessing configuration file...");
46 for (_i = 0, _len = preprocessors.length; _i < _len; _i++) {
47 p = preprocessors[_i];
48 data = p(data);
49 }
50 console.log("Preprocessed.");
51 return cson.parse(data, function(err, config) {
52 var myBuildr;
53 if (err) {
54 throw err;
55 }
56 myBuildr = buildr.createInstance(config);
57 myBuildr.process(function(err) {});
58 if (err) {
59 throw err;
60 }
61 });
62 });
63 } else {
64 return console.error("Configuration file not found: " + filename);
65 }
66 });
67
68}).call(this);