-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
executable file
·33 lines (25 loc) · 805 Bytes
/
bin.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
#!/usr/bin/env node
const { resolve } = require('path');
const exec = require('async-execute');
const exist = require('@does/exist');
require('colors');
const getCommand = require('./lib/getCommand');
const getArgs = require('./lib/getArgs');
const { argv: [ , , ...rest ] } = process;
process.on('unhandledRejection', console.error);
(async() => {
const path = resolve('package.json');
if (!(await exist(path))) {
console.warn(`Could not find package.json file at ${path.yellow}.`.red.bold);
return;
}
const command = await getCommand(require(path));
const args = await getArgs(rest);
const cmd = [
command,
args && !command.startsWith('/') ? '--' : '',
args,
].filter(Boolean).join(' ');
console.log(`Executing: ${cmd.bold}`);
await exec(cmd, {pipe: true, exit: true});
})();