-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhelpers.js
60 lines (50 loc) · 1.33 KB
/
helpers.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
var path = require('path');
// Helper functions
var _root = path.resolve(__dirname, '..');
console.log('root directory:', root());
function hasProcessFlag(flag) {
return process.argv.join('').indexOf(flag) > -1;
}
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [_root].concat(args));
}
function rootNode(args) {
args = Array.prototype.slice.call(arguments, 0);
return root.apply(path, ['node_modules'].concat(args));
}
function prependExt(extensions, args) {
args = args || [];
if (!Array.isArray(args)) {
args = [args]
}
return extensions.reduce(function (memo, val) {
return memo.concat(val, args.map(function (prefix) {
return prefix + val;
}));
}, ['']);
}
function packageSort(packages) {
var len = packages.length - 1;
var first = packages[0];
var last = packages[len];
return function sort(a, b) {
var i = packages.indexOf(a.names[0]);
var j = packages.indexOf(b.names[0]);
if (i > j) {
return 1
} else if (i == j) {
return 0
} else return -1;
}
}
function reverse(arr) {
return arr.reverse();
}
exports.reverse = reverse;
exports.hasProcessFlag = hasProcessFlag;
exports.root = root;
exports.rootNode = rootNode;
exports.prependExt = prependExt;
exports.prepend = prependExt;
exports.packageSort = packageSort;