-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (30 loc) · 700 Bytes
/
Copy pathindex.js
File metadata and controls
35 lines (30 loc) · 700 Bytes
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
var exec = require('child_process').execSync
var platform = require('os').platform()
var quote = require("shell-quote").quote
module.exports = function(){
var commands = Array.isArray(arguments[0]) ? arguments[0] : Array.prototype.slice.apply(arguments)
var command = null
commands.some(function(c){
if (isExec(findCommand(c))){
command = c
return true
}
})
return command
}
function isExec(command){
try{
exec(quote(command.split(" ")), { stdio: 'ignore' })
return true
}
catch (_e){
return false
}
}
function findCommand(command){
if (/^win/.test(platform)){
return "where " + command
} else {
return "command -v " + command
}
}