This repository has been archived by the owner on Jun 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
78 lines (74 loc) · 2.17 KB
/
cli.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const yargs = require("yargs");
const { bddy } = require("bddy-core");
const PrettyError = require("pretty-error");
const pe = new PrettyError();
pe.appendStyle({
"pretty-error > header > title > kind": { display: "none" },
"pretty-error > header > colon": { display: "none" },
"pretty-error > header > message": {
color: "bright-white",
background: "cyan",
padding: "0 0"
},
"pretty-error > trace > item": { marginLeft: 2, bullet: '"<grey>-</grey>"' },
"pretty-error > trace > item > header > pointer > file": { color: "bright-cyan" },
"pretty-error > trace > item > header > pointer > colon": { color: "cyan" },
"pretty-error > trace > item > header > pointer > line": { color: "bright-cyan" },
"pretty-error > trace > item > header > what": { color: "bright-white" },
"pretty-error > trace > item > footer > addr": { display: "none" }
});
async function build(defs, argv, _options) {
const defaultOptions = {
parallelJobs: argv.j,
quiet: argv.q,
verbose: argv.v
};
const options = Object.assign(defaultOptions, _options);
const bddyInst = bddy(defs, argv, options);
const targets = argv.targets || argv._;
if (argv._.length) {
for (let wish of argv._) {
await bddyInst.wish(wish);
}
} else if (bddyInst.wanted && bddyInst.wanted.length) {
for (let wish of bddyInst.wanted) {
await bddyInst.wish(wish);
}
} else {
await bddyInst.wish("start");
}
}
function parseARGV(yargs, _argopt) {
const argopt = Object.assign(
{
j: {
alias: "jobs",
number: true,
default: 0,
requiresArg: true,
describe: "Allow N jobs at once (incluences <run>); 0 for CPU cores of your system"
},
q: {
boolean: true,
alias: "quiet",
default: false,
describe: "Quiet Mode"
},
v: {
boolean: true,
alias: "verbose",
default: false,
describe: "Verbose Mode"
}
},
_argopt
);
return yargs.options(argopt).argv;
}
module.exports = function(defs, argopt, options) {
build(defs, parseARGV(yargs, argopt), options).catch(function(e) {
const renderedError = pe.render(e);
console.log(renderedError);
if (!e.bddyIgnorable) process.exit(1);
});
};