forked from sindresorhus/binary-version
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
23 lines (20 loc) · 693 Bytes
/
Copy pathindex.js
File metadata and controls
23 lines (20 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict';
var execFile = require('child_process').execFile;
var findVersions = require('find-versions');
var cygwin = process.platform === "win32" && (process.env.ORIGINAL_PATH || '').indexOf('/cygdrive/') != -1;
module.exports = function (bin, cb) {
var args = ['--version'];
if(cygwin) {
args = ['-c', bin + ' --version'];
bin = 'c:\\cygwin\\bin\\bash.exe';
}
execFile(bin, args, function (err, stdout, stderr) {
if (err) {
if (err.code === 'ENOENT') {
err.message = 'Couldn\'t find the `' + bin + '` binary. Make sure it\'s installed and in your $PATH';
}
return cb(err);
}
cb(null, findVersions(stdout.trim() || stderr.trim(), {loose: true})[0]);
});
};