| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | const execa = require('execa'); |
| 3 | const executable = require('executable'); |
| 4 | |
| 5 | module.exports = (bin, args) => { |
| 6 | if (!Array.isArray(args)) { |
| 7 | args = ['--help']; |
| 8 | } |
| 9 | |
| 10 | return executable(bin) |
| 11 | .then(works => { |
| 12 | if (!works) { |
| 13 | throw new Error(`Couldn't execute the \`${bin}\` binary. Make sure it has the right permissions.`); |
| 14 | } |
| 15 | |
| 16 | return execa(bin, args); |
| 17 | }) |
| 18 | .then(res => res.code === 0); |
| 19 | }; |
| 20 | |
| 21 | module.exports.sync = (bin, args) => { |
| 22 | if (!Array.isArray(args)) { |
| 23 | args = ['--help']; |
| 24 | } |
| 25 | |
| 26 | if (!executable.sync(bin)) { |
| 27 | throw new Error(`Couldn't execute the \`${bin}\` binary. Make sure it has the right permissions.`); |
| 28 | } |
| 29 | |
| 30 | return execa.sync(bin, args).status === 0; |
| 31 | }; |