-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jakefile
67 lines (64 loc) · 2.09 KB
/
Jakefile
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
var fs = require('fs');
desc('Draw routes');
task('routes', [], function () {
function print (method) {
return function () {
//console.log(method + "\t" + arguments[0]);
};
}
function add_spaces (str, len, to_start) {
var str_len = str.length;
for (var i = str_len; i < len; i += 1) {
if (!to_start) {
str += ' ';
} else {
str = ' ' + str;
}
}
return str;
}
var app = require('express').createServer();
var mapper = require('express-on-railway').init(app).routes;
var dump = mapper.dump();
var max_len = 0, helper_max_len = 0;
dump.forEach(function (data) {
if (data.path.length > max_len) {
max_len = data.path.length;
}
if (data.helper.length > helper_max_len) {
helper_max_len = data.helper.length;
}
});
dump.forEach(function (data) {
console.log(
add_spaces(data.helper, helper_max_len + 1, true) + ' ' +
data.method.toUpperCase() + "\t" +
add_spaces(data.path, max_len + 1) +
data.file + "#" + data.action
);
});
complete();
}, true);
desc('Check and install required packages');
task('depends', [], function () {
var npm = require('npm'), cb_counter = 0, wait_for_all = function () {
if (--cb_counter === 0) complete();
};
npm.load({}, function (err) {
if (err) throw err;
npm.commands.ls(['installed'], true, function (err, packages) {
var requirements = JSON.parse(fs.readFileSync('config/requirements.json'));
requirements.forEach(function (package) {
cb_counter += 1;
if (packages[package]) {
console.log('Package ' + package + ' is already installed');
wait_for_all();
} else {
npm.commands.install([package], function (err, data) {
wait_for_all();
});
}
});
});
});
}, true);