blob: 49100bd0052f5e1f8c320a06c295a3eb751ca3a9 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2const execa = require('execa');
3const executable = require('executable');
4
5module.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
21module.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};