-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvm-test.js
53 lines (43 loc) · 1.39 KB
/
nvm-test.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
var async = require('async');
var fs = require('fs'),
util = require('util'),
child = require('child_process');
var max_node = '0.10';
fs.readFile('package.json', function (err, data) {
var package = JSON.parse(data.toString());
var engines = package.engines && package.engines.node;
if (! engines) {
return;
}
// we either do a range or a list of specific versions
//
// in the case of range, iterate from start to end (or max node
// version 0.10)
//
// in the case of versions, run on each one
var start, end = max_node, doingRange = false, versions = [];
engines.split(' ').forEach(function (engine) {
if (engine[0] === '>') {
start = engine.slice(2);
doingRange = true;
} else if (engine[0] === '<') {
end = engine.slice(2);
} else {
versions.push(engine);
}
});
async.eachLimit(doingRange ? [ start, end ] : versions, 1, function (each, callback) {
console.log('--> testing', each);
child.exec('echo "source ~/.nvm/nvm.sh && nvm use ' + each + ' && npm test" | bash', function (err, stdout, stderr) {
if (err) {
console.log(stderr);
}
console.log(stdout);
callback(err);
});
}, function (err) {
if (err) {
console.log(err);
}
});
});