1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.logExec = exports.execShell = exports.execWithArgs = exports.execCommand = exports.proxyCommand = void 0;
|
4 | const execa = require("execa");
|
5 | const colors_1 = require("../colors");
|
6 | async function proxyCommand(cmd, args = [], opt = {}) {
|
7 | const processArgs = process.argv.slice(2);
|
8 | await execWithArgs(cmd, [...args, ...processArgs], {
|
9 | ...opt,
|
10 | });
|
11 | }
|
12 | exports.proxyCommand = proxyCommand;
|
13 | async function execCommand(cmd, opt = {}) {
|
14 | logExec(cmd, [], opt);
|
15 | await execa
|
16 | .command(cmd, {
|
17 | stdio: 'inherit',
|
18 | preferLocal: true,
|
19 | ...opt,
|
20 | })
|
21 | .catch(err => handleError(err, cmd, opt));
|
22 | }
|
23 | exports.execCommand = execCommand;
|
24 | async function execWithArgs(cmd, args = [], opt = {}) {
|
25 | logExec(cmd, args, opt);
|
26 | await execa(cmd, args, {
|
27 | stdio: 'inherit',
|
28 | preferLocal: true,
|
29 | ...opt,
|
30 | }).catch(err => handleError(err, cmd, opt));
|
31 | }
|
32 | exports.execWithArgs = execWithArgs;
|
33 | async function execShell(cmd, opt = {}) {
|
34 | await execCommand(cmd, {
|
35 | shell: true,
|
36 | ...opt,
|
37 | });
|
38 | }
|
39 | exports.execShell = execShell;
|
40 | function handleError(err, cmd, opt = {}) {
|
41 | if (opt.noProcessExit) {
|
42 | throw err || new Error(`execCommand failed: ${cmd}`);
|
43 | }
|
44 | if (err) {
|
45 | if (err.originalMessage) {
|
46 | console.log(colors_1.dimGrey(err.originalMessage));
|
47 | }
|
48 | else if (err.shortMessage) {
|
49 | console.log(colors_1.dimGrey(err.shortMessage));
|
50 | }
|
51 | else {
|
52 | console.error(err);
|
53 | }
|
54 | if (err.exitCode) {
|
55 | process.exit(err.exitCode);
|
56 | }
|
57 | }
|
58 | process.exit(1);
|
59 | }
|
60 | function logExec(cmd, args = [], opt = {}) {
|
61 | const cmdline = [
|
62 | ...Object.entries(opt.env || {}).map(([k, v]) => [k, v].join('=')),
|
63 | cmd,
|
64 | ...args,
|
65 | ].join(' ');
|
66 | console.log(colors_1.grey(cmdline));
|
67 | }
|
68 | exports.logExec = logExec;
|