-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (34 loc) · 1003 Bytes
/
index.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
const path = require('path')
const fs = require('fs')
const execSh = require('exec-sh').promise
async function exec({ args, verbose }) {
if (args == undefined || args.length <= 0) {
console.error('Error: No executable specified.')
return 1
}
let pwd = process.cwd()
while (true) {
let executable = path.resolve(pwd, `node_modules/.bin/${args[0]}`)
if (verbose) {
console.log(`Search in ${executable}`)
}
if (fs.existsSync(executable)) {
if (verbose) {
console.log(`${executable} ${args.slice(1).join(' ')}`)
}
return await execSh(`${executable} ${args.slice(1).join(' ')}`)
}
if (
pwd == undefined ||
pwd == process.env.HOME ||
pwd.toLowerCase().indexOf(process.env.HOME.toLowerCase()) != 0
) {
if (verbose) {
console.log(`(global) ${args.join(' ')}`)
}
return await execSh(`${args.join(' ')} 2>&1`)
}
pwd = path.resolve(pwd, '../')
}
}
module.exports = { exec }