visual-exec 0.1.14 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/get-default-logger.d.ts +4 -0
- package/dist/get-default-logger.d.ts.map +1 -0
- package/dist/get-default-logger.js +21 -0
- package/dist/get-default-logger.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/visual-exec.d.ts +70 -0
- package/dist/visual-exec.d.ts.map +1 -0
- package/dist/visual-exec.js +179 -0
- package/dist/visual-exec.js.map +1 -0
- package/package.json +22 -7
- package/lib/get-default-logger.js +0 -19
- package/lib/visual-exec.js +0 -213
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-default-logger.d.ts","sourceRoot":"","sources":["../src/get-default-logger.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAC;AAKzC,wBAAgB,gBAAgB,IAAI,YAAY,CAU/C;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDefaultLogger = getDefaultLogger;
|
|
7
|
+
const visual_logger_1 = __importDefault(require("visual-logger"));
|
|
8
|
+
const ci_info_1 = require("ci-info");
|
|
9
|
+
let logger = null;
|
|
10
|
+
function getDefaultLogger() {
|
|
11
|
+
if (!logger) {
|
|
12
|
+
logger = new visual_logger_1.default();
|
|
13
|
+
if (ci_info_1.isCI) {
|
|
14
|
+
logger.info("visual-exec: CI env detected");
|
|
15
|
+
logger.setItemType("none");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return logger;
|
|
19
|
+
}
|
|
20
|
+
exports.default = getDefaultLogger;
|
|
21
|
+
//# sourceMappingURL=get-default-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-default-logger.js","sourceRoot":"","sources":["../src/get-default-logger.ts"],"names":[],"mappings":";;;;;AAKA,4CAUC;AAfD,kEAAyC;AACzC,qCAA+B;AAE/B,IAAI,MAAM,GAAwB,IAAI,CAAC;AAEvC,SAAgB,gBAAgB;IAC9B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,IAAI,uBAAY,EAAE,CAAC;QAE5B,IAAI,cAAI,EAAE,CAAC;YACT,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;YAC5C,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,kBAAe,gBAAgB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.getDefaultLogger = exports.VisualExec = void 0;
|
|
4
|
+
var visual_exec_1 = require("./visual-exec");
|
|
5
|
+
Object.defineProperty(exports, "VisualExec", { enumerable: true, get: function () { return visual_exec_1.VisualExec; } });
|
|
6
|
+
var get_default_logger_1 = require("./get-default-logger");
|
|
7
|
+
Object.defineProperty(exports, "getDefaultLogger", { enumerable: true, get: function () { return get_default_logger_1.getDefaultLogger; } });
|
|
8
|
+
var visual_exec_2 = require("./visual-exec");
|
|
9
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return visual_exec_2.VisualExec; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAA8D;AAArD,yGAAA,UAAU,OAAA;AACnB,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA;AACzB,6CAAsD;AAA7C,sGAAA,UAAU,OAAW"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import VisualLogger from "visual-logger";
|
|
2
|
+
export interface VisualExecOptions {
|
|
3
|
+
/** The command to execute */
|
|
4
|
+
command: string;
|
|
5
|
+
/** Working directory for the command */
|
|
6
|
+
cwd?: string;
|
|
7
|
+
/** Visual logger instance to use */
|
|
8
|
+
visualLogger?: VisualLogger;
|
|
9
|
+
/** Spinner style to use */
|
|
10
|
+
spinner?: any;
|
|
11
|
+
/** Title displayed during execution */
|
|
12
|
+
displayTitle?: string;
|
|
13
|
+
/** Label used in log messages */
|
|
14
|
+
logLabel?: string;
|
|
15
|
+
/** Label used in output messages */
|
|
16
|
+
outputLabel?: string;
|
|
17
|
+
/** Log level for output (default: "verbose") */
|
|
18
|
+
outputLevel?: string;
|
|
19
|
+
/** Maximum buffer size for stdout/stderr (default: 10MB) */
|
|
20
|
+
maxBuffer?: number;
|
|
21
|
+
/** Force stderr output to be logged as error (default: true) */
|
|
22
|
+
forceStderr?: boolean;
|
|
23
|
+
/** Regex or boolean to check stdout for error patterns (default: true) */
|
|
24
|
+
checkStdoutError?: boolean | RegExp;
|
|
25
|
+
}
|
|
26
|
+
interface ExecOutput {
|
|
27
|
+
stdout: string;
|
|
28
|
+
stderr: string;
|
|
29
|
+
}
|
|
30
|
+
interface ExecError extends Error {
|
|
31
|
+
output?: ExecOutput;
|
|
32
|
+
}
|
|
33
|
+
interface ChildProcess {
|
|
34
|
+
stdout: NodeJS.ReadableStream;
|
|
35
|
+
stderr: NodeJS.ReadableStream;
|
|
36
|
+
promise: Promise<ExecOutput>;
|
|
37
|
+
}
|
|
38
|
+
export declare class VisualExec {
|
|
39
|
+
private _title;
|
|
40
|
+
private _logLabel;
|
|
41
|
+
private _outputLabel;
|
|
42
|
+
private _command;
|
|
43
|
+
private _cwd;
|
|
44
|
+
private _logger;
|
|
45
|
+
private _outputLevel;
|
|
46
|
+
private _spinner;
|
|
47
|
+
private _maxBuffer;
|
|
48
|
+
private _forceStderr;
|
|
49
|
+
private _checkStdoutError;
|
|
50
|
+
private _startTime;
|
|
51
|
+
private _stdoutKey?;
|
|
52
|
+
private _stderrKey?;
|
|
53
|
+
private _updateStdout?;
|
|
54
|
+
private _updateStderr?;
|
|
55
|
+
private _child?;
|
|
56
|
+
constructor(options: VisualExecOptions);
|
|
57
|
+
private _makeTitle;
|
|
58
|
+
private _updateDigest;
|
|
59
|
+
show(child: ChildProcess): Promise<ExecOutput>;
|
|
60
|
+
logResult(err: ExecError | null, output?: ExecOutput): void;
|
|
61
|
+
checkForErrors(text: string): RegExpMatchArray | null;
|
|
62
|
+
/**
|
|
63
|
+
* Log the final output. Can be overridden to customize output handling.
|
|
64
|
+
* Set to a no-op function to suppress output logging.
|
|
65
|
+
*/
|
|
66
|
+
logFinalOutput(err: ExecError | null, output: ExecOutput): void;
|
|
67
|
+
execute(command?: string): Promise<ExecOutput>;
|
|
68
|
+
}
|
|
69
|
+
export default VisualExec;
|
|
70
|
+
//# sourceMappingURL=visual-exec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visual-exec.d.ts","sourceRoot":"","sources":["../src/visual-exec.ts"],"names":[],"mappings":"AAGA,OAAO,YAAY,MAAM,eAAe,CAAC;AAUzC,MAAM,WAAW,iBAAiB;IAChC,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC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OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,aAAa,CAAC,CAAwB;IAC9C,OAAO,CAAC,aAAa,CAAC,CAAwB;IAC9C,OAAO,CAAC,MAAM,CAAC,CAAe;gBAElB,OAAO,EAAE,iBAAiB;IAgCtC,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,aAAa;IAmDrB,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IAsC9C,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI;IAoB3D,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI;IAQrD;;;OAGG;IACH,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI;IA2B/D,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAc/C;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VisualExec = void 0;
|
|
7
|
+
const xsh_1 = __importDefault(require("xsh"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const get_default_logger_1 = require("./get-default-logger");
|
|
10
|
+
const visual_logger_1 = __importDefault(require("visual-logger"));
|
|
11
|
+
const has_ansi_1 = __importDefault(require("has-ansi"));
|
|
12
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
13
|
+
// Set xsh to use native Promise
|
|
14
|
+
xsh_1.default.Promise = Promise;
|
|
15
|
+
const ONE_MB = 1024 * 1024;
|
|
16
|
+
const TEN_MB = 10 * ONE_MB;
|
|
17
|
+
class VisualExec {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
const { command, cwd = process.cwd(), visualLogger, spinner = visual_logger_1.default.spinners[1], displayTitle, logLabel, outputLabel, outputLevel = "verbose", maxBuffer = TEN_MB, forceStderr = true, checkStdoutError = true } = options;
|
|
20
|
+
this._title = displayTitle || this._makeTitle(command);
|
|
21
|
+
this._logLabel = logLabel || this._title;
|
|
22
|
+
this._outputLabel = outputLabel || this._title;
|
|
23
|
+
this._command = command;
|
|
24
|
+
this._cwd = cwd || process.cwd();
|
|
25
|
+
this._logger = visualLogger || (0, get_default_logger_1.getDefaultLogger)();
|
|
26
|
+
this._outputLevel = outputLevel;
|
|
27
|
+
this._spinner = spinner;
|
|
28
|
+
this._maxBuffer = maxBuffer;
|
|
29
|
+
this._forceStderr = forceStderr;
|
|
30
|
+
this._checkStdoutError =
|
|
31
|
+
checkStdoutError === true
|
|
32
|
+
? /error|warn|fatal|unhandled|reject|exception|failure|fail|failed/i
|
|
33
|
+
: checkStdoutError;
|
|
34
|
+
this._startTime = Date.now();
|
|
35
|
+
}
|
|
36
|
+
_makeTitle(command) {
|
|
37
|
+
if (typeof command !== "string") {
|
|
38
|
+
command = "user command";
|
|
39
|
+
}
|
|
40
|
+
return `Running ${command}`;
|
|
41
|
+
}
|
|
42
|
+
_updateDigest(item, buf) {
|
|
43
|
+
const newBuf = item.buf + buf;
|
|
44
|
+
const lines = newBuf
|
|
45
|
+
.split("\n")
|
|
46
|
+
.map(x => x && x.trim())
|
|
47
|
+
.filter(x => x);
|
|
48
|
+
const stripLines = lines.map(x => ((0, has_ansi_1.default)(x) ? (0, strip_ansi_1.default)(x) : x));
|
|
49
|
+
let length = 0;
|
|
50
|
+
// gather as many lines from the end as possible that will fit in a single line, using
|
|
51
|
+
// strings without ansi code to get real length
|
|
52
|
+
let ix = stripLines.length - 1;
|
|
53
|
+
for (; ix >= 0; ix--) {
|
|
54
|
+
const line = stripLines[ix];
|
|
55
|
+
if (line) {
|
|
56
|
+
if (length + line.length < 100) {
|
|
57
|
+
length += line.length;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
let msgs = ix >= 0 ? lines.slice(ix + 1) : lines;
|
|
65
|
+
if (msgs.length === 0) {
|
|
66
|
+
// even the last line is too long, save it, and display last line as is
|
|
67
|
+
item.buf = lines[lines.length - 1] || "";
|
|
68
|
+
// set some reasonable limit to avoid visual digest getting clobberred
|
|
69
|
+
if (item.buf.length > 120) {
|
|
70
|
+
// truncate stripped line only to avoid breaking ansi code
|
|
71
|
+
item.buf = stripLines[stripLines.length - 1].substr(0, 100);
|
|
72
|
+
}
|
|
73
|
+
msgs = [item.buf];
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
item.buf = msgs.join("\n");
|
|
77
|
+
}
|
|
78
|
+
if (buf.endsWith("\n")) {
|
|
79
|
+
item.buf += "\n";
|
|
80
|
+
}
|
|
81
|
+
this._logger.updateItem(item.name, {
|
|
82
|
+
msg: msgs.join(chalk_1.default.blue.inverse("\\n")),
|
|
83
|
+
_save: false,
|
|
84
|
+
_render: false
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
show(child) {
|
|
88
|
+
this._stdoutKey = Symbol("visual-exec-stdout");
|
|
89
|
+
this._stderrKey = Symbol("visual-exec-stderr");
|
|
90
|
+
this._logger.addItem({
|
|
91
|
+
name: this._stdoutKey,
|
|
92
|
+
color: "green",
|
|
93
|
+
display: `=== ${this._title}\nstdout`,
|
|
94
|
+
spinner: this._spinner
|
|
95
|
+
});
|
|
96
|
+
this._logger.addItem({
|
|
97
|
+
name: this._stderrKey,
|
|
98
|
+
color: "red",
|
|
99
|
+
display: `stderr`
|
|
100
|
+
});
|
|
101
|
+
const stdoutDigest = { name: this._stdoutKey, buf: "" };
|
|
102
|
+
const stderrDigest = { name: this._stderrKey, buf: "" };
|
|
103
|
+
this._updateStdout = (buf) => this._updateDigest(stdoutDigest, buf);
|
|
104
|
+
this._updateStderr = (buf) => this._updateDigest(stderrDigest, buf);
|
|
105
|
+
child.stdout.on("data", this._updateStdout);
|
|
106
|
+
child.stderr.on("data", this._updateStderr);
|
|
107
|
+
this._child = child;
|
|
108
|
+
return child.promise
|
|
109
|
+
.catch((err) => {
|
|
110
|
+
this.logResult(err);
|
|
111
|
+
throw err;
|
|
112
|
+
})
|
|
113
|
+
.then((output) => {
|
|
114
|
+
this.logResult(null, output);
|
|
115
|
+
return output;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
logResult(err, output) {
|
|
119
|
+
const child = this._child;
|
|
120
|
+
this._logger.removeItem(this._stdoutKey);
|
|
121
|
+
this._logger.removeItem(this._stderrKey);
|
|
122
|
+
child.stdout.removeListener("data", this._updateStdout);
|
|
123
|
+
child.stderr.removeListener("data", this._updateStderr);
|
|
124
|
+
if (err) {
|
|
125
|
+
this._logger.error(`${chalk_1.default.red("Failed")} ${this._logLabel} - ${chalk_1.default.red(err.message)}`);
|
|
126
|
+
output = err.output;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const time = ((Date.now() - this._startTime) / 1000).toFixed(2);
|
|
130
|
+
const dispTime = `${chalk_1.default.magenta(time)}secs`;
|
|
131
|
+
this._logger.info(`Done ${this._logLabel} ${dispTime} ${chalk_1.default.green("exit code 0")}`);
|
|
132
|
+
}
|
|
133
|
+
this.logFinalOutput(err, output);
|
|
134
|
+
}
|
|
135
|
+
checkForErrors(text) {
|
|
136
|
+
if (!this._checkStdoutError || !text)
|
|
137
|
+
return null;
|
|
138
|
+
if (this._checkStdoutError instanceof RegExp) {
|
|
139
|
+
return text.match(this._checkStdoutError);
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Log the final output. Can be overridden to customize output handling.
|
|
145
|
+
* Set to a no-op function to suppress output logging.
|
|
146
|
+
*/
|
|
147
|
+
logFinalOutput(err, output) {
|
|
148
|
+
const level = err || (this._forceStderr && output?.stderr) || this.checkForErrors(output?.stdout || "")
|
|
149
|
+
? "error"
|
|
150
|
+
: this._outputLevel;
|
|
151
|
+
if (!output || (!output.stdout && !output.stderr)) {
|
|
152
|
+
this._logger[level](`${chalk_1.default.green("No output")} from ${this._outputLabel}`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const colorize = (t) => t.replace(/ERR!/g, chalk_1.default.red("ERR!"));
|
|
156
|
+
const logs = [chalk_1.default.green(">>>"), `Start of output from ${this._outputLabel} ===`];
|
|
157
|
+
if (output.stdout) {
|
|
158
|
+
logs.push(`\n${colorize(output.stdout)}`);
|
|
159
|
+
}
|
|
160
|
+
if (output.stderr) {
|
|
161
|
+
logs.push(chalk_1.default.red("\n=== stderr ===\n") + colorize(output.stderr));
|
|
162
|
+
}
|
|
163
|
+
logs.push(chalk_1.default.blue("\n<<<"), `End of output from ${this._outputLabel} ---`);
|
|
164
|
+
this._logger.prefix(false)[level](...logs);
|
|
165
|
+
}
|
|
166
|
+
execute(command) {
|
|
167
|
+
this._startTime = Date.now();
|
|
168
|
+
const child = xsh_1.default.exec({
|
|
169
|
+
silent: true,
|
|
170
|
+
cwd: this._cwd,
|
|
171
|
+
env: Object.assign({}, process.env, { PWD: this._cwd }),
|
|
172
|
+
maxBuffer: this._maxBuffer
|
|
173
|
+
}, command || this._command);
|
|
174
|
+
return this.show(child);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.VisualExec = VisualExec;
|
|
178
|
+
exports.default = VisualExec;
|
|
179
|
+
//# sourceMappingURL=visual-exec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visual-exec.js","sourceRoot":"","sources":["../src/visual-exec.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,kDAA0B;AAC1B,6DAAwD;AACxD,kEAAy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AAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACvE,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,eAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,sBAAsB,IAAI,CAAC,YAAY,MAAM,CAAC,CAAC;QAC7E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAS,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,CAAC,OAAgB;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,aAAG,CAAC,IAAI,CACpB;YACE,MAAM,EAAE,IAAI;YACZ,GAAG,EAAE,IAAI,CAAC,IAAI;YACd,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;YACvD,SAAS,EAAE,IAAI,CAAC,UAAU;SAC3B,EACD,OAAO,IAAI,IAAI,CAAC,QAAQ,CACzB,CAAC;QAEF,OAAO,IAAI,CAAC,IAAI,CAAC,KAAgC,CAAC,CAAC;IACrD,CAAC;CACF;AA5ND,gCA4NC;AAED,kBAAe,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "visual-exec",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Visual shell exec",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Visual shell exec with spinners and progress display",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"test": "vitest run",
|
|
10
|
+
"test:watch": "vitest",
|
|
11
|
+
"prepublishOnly": "xrun --serial build test"
|
|
12
|
+
},
|
|
7
13
|
"repository": {
|
|
8
14
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/jchip/
|
|
15
|
+
"url": "https://github.com/jchip/fynpo.git",
|
|
16
|
+
"directory": "packages/visual-exec"
|
|
10
17
|
},
|
|
11
18
|
"keywords": [
|
|
12
19
|
"visual",
|
|
13
20
|
"shell",
|
|
14
|
-
"exec"
|
|
21
|
+
"exec",
|
|
22
|
+
"spinner",
|
|
23
|
+
"progress"
|
|
15
24
|
],
|
|
16
25
|
"files": [
|
|
17
|
-
"
|
|
26
|
+
"dist"
|
|
18
27
|
],
|
|
19
28
|
"author": "Joel Chen <joel123@gmail.com>",
|
|
20
29
|
"license": "Apache-2.0",
|
|
@@ -26,6 +35,12 @@
|
|
|
26
35
|
"visual-logger": "^1.1.3",
|
|
27
36
|
"xsh": "^0.4.5"
|
|
28
37
|
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^20.0.0",
|
|
40
|
+
"tsx": "^4.20.0",
|
|
41
|
+
"typescript": "^5.9.3",
|
|
42
|
+
"vitest": "^4.0.9"
|
|
43
|
+
},
|
|
29
44
|
"prettier": {
|
|
30
45
|
"printWidth": 100,
|
|
31
46
|
"trailingComma": "none",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const VisualLogger = require("visual-logger");
|
|
4
|
-
const { isCI } = require("ci-info");
|
|
5
|
-
|
|
6
|
-
let logger;
|
|
7
|
-
const getLogger = () => {
|
|
8
|
-
if (!logger) {
|
|
9
|
-
logger = new VisualLogger();
|
|
10
|
-
|
|
11
|
-
if (isCI) {
|
|
12
|
-
logger.info("visual-exec: CI env detected");
|
|
13
|
-
logger.setItemType("none");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return logger;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
module.exports = getLogger;
|
package/lib/visual-exec.js
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-magic-numbers,no-eval,prefer-template */
|
|
4
|
-
|
|
5
|
-
const xsh = require("xsh");
|
|
6
|
-
const chalk = require("chalk");
|
|
7
|
-
const getDefaultLogger = require("./get-default-logger");
|
|
8
|
-
const VisualLogger = require("visual-logger");
|
|
9
|
-
const hasAnsi = require("has-ansi");
|
|
10
|
-
const stripAnsi = require("strip-ansi");
|
|
11
|
-
|
|
12
|
-
xsh.Promise = Promise;
|
|
13
|
-
|
|
14
|
-
const ONE_MB = 1024 * 1024;
|
|
15
|
-
const TEN_MB = 10 * ONE_MB;
|
|
16
|
-
|
|
17
|
-
class VisualExec {
|
|
18
|
-
constructor({
|
|
19
|
-
command,
|
|
20
|
-
cwd = process.cwd(),
|
|
21
|
-
visualLogger,
|
|
22
|
-
spinner = VisualLogger.spinners[1],
|
|
23
|
-
displayTitle = undefined,
|
|
24
|
-
logLabel = undefined,
|
|
25
|
-
outputLabel = undefined,
|
|
26
|
-
outputLevel = "verbose",
|
|
27
|
-
maxBuffer = TEN_MB,
|
|
28
|
-
forceStderr = true,
|
|
29
|
-
checkStdoutError = true
|
|
30
|
-
}) {
|
|
31
|
-
this._title = displayTitle || this._makeTitle(command);
|
|
32
|
-
this._logLabel = logLabel || this._title;
|
|
33
|
-
this._outputLabel = outputLabel || this._title;
|
|
34
|
-
this._command = command;
|
|
35
|
-
this._cwd = cwd || process.cwd();
|
|
36
|
-
this._logger = visualLogger || getDefaultLogger();
|
|
37
|
-
this._outputLevel = outputLevel;
|
|
38
|
-
this._spinner = spinner;
|
|
39
|
-
this._maxBuffer = maxBuffer;
|
|
40
|
-
this._forceStderr = forceStderr;
|
|
41
|
-
this._checkStdoutError =
|
|
42
|
-
checkStdoutError === true
|
|
43
|
-
? /error|warn|fatal|unhandled|reject|exception|failure|fail|failed/i
|
|
44
|
-
: checkStdoutError;
|
|
45
|
-
this._startTime = Date.now();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
_makeTitle(command) {
|
|
49
|
-
if (typeof command !== "string") {
|
|
50
|
-
command = "user command";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return `Running ${command}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/* eslint-disable max-statements */
|
|
57
|
-
_updateDigest(item, buf) {
|
|
58
|
-
const newBuf = item.buf + buf;
|
|
59
|
-
|
|
60
|
-
const lines = newBuf
|
|
61
|
-
.split("\n")
|
|
62
|
-
.map(x => x && x.trim())
|
|
63
|
-
.filter(x => x);
|
|
64
|
-
|
|
65
|
-
const stripLines = lines.map(x => (hasAnsi(x) ? stripAnsi(x) : x));
|
|
66
|
-
|
|
67
|
-
let length = 0;
|
|
68
|
-
|
|
69
|
-
// gather as many lines from the end as possible that will fit in a single line, using
|
|
70
|
-
// strings without ansi code to get real length
|
|
71
|
-
let ix = stripLines.length - 1;
|
|
72
|
-
for (; ix >= 0; ix--) {
|
|
73
|
-
const line = stripLines[ix];
|
|
74
|
-
if (line) {
|
|
75
|
-
if (length + line.length < 100) {
|
|
76
|
-
length += line.length;
|
|
77
|
-
} else {
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let msgs = ix >= 0 ? lines.slice(ix + 1) : lines;
|
|
84
|
-
if (msgs.length === 0) {
|
|
85
|
-
// even the last line is too long, save it, and display last line as is
|
|
86
|
-
item.buf = lines[lines.length - 1] || "";
|
|
87
|
-
// set some reasonable limit to avoid visual digest getting clobberred
|
|
88
|
-
if (item.buf.length > 120) {
|
|
89
|
-
// truncte stripped line only to avoid breaking ansi code
|
|
90
|
-
item.buf = stripLines[stripLines.length - 1].substr(0, 100);
|
|
91
|
-
}
|
|
92
|
-
msgs = [item.buf];
|
|
93
|
-
} else {
|
|
94
|
-
item.buf = msgs.join("\n");
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (buf.endsWith("\n")) {
|
|
98
|
-
item.buf += "\n";
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
this._logger.updateItem(item.name, {
|
|
102
|
-
msg: msgs.join(chalk.blue.inverse("\\n")),
|
|
103
|
-
_save: false,
|
|
104
|
-
_render: false
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
show(child) {
|
|
109
|
-
this._stdoutKey = Symbol("visual-exec-stdout");
|
|
110
|
-
this._stderrKey = Symbol("visual-exec-stderr");
|
|
111
|
-
|
|
112
|
-
this._logger.addItem({
|
|
113
|
-
name: this._stdoutKey,
|
|
114
|
-
color: "green",
|
|
115
|
-
display: `=== ${this._title}\nstdout`,
|
|
116
|
-
spinner: this._spinner
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
this._logger.addItem({
|
|
120
|
-
name: this._stderrKey,
|
|
121
|
-
color: "red",
|
|
122
|
-
display: `stderr`
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const stdoutDigest = { name: this._stdoutKey, buf: "" };
|
|
126
|
-
const stderrDigest = { name: this._stderrKey, buf: "" };
|
|
127
|
-
this._updateStdout = buf => this._updateDigest(stdoutDigest, buf);
|
|
128
|
-
this._updateStderr = buf => this._updateDigest(stderrDigest, buf);
|
|
129
|
-
|
|
130
|
-
child.stdout.on("data", this._updateStdout);
|
|
131
|
-
child.stderr.on("data", this._updateStderr);
|
|
132
|
-
|
|
133
|
-
this._child = child;
|
|
134
|
-
|
|
135
|
-
return child.promise
|
|
136
|
-
.catch(err => {
|
|
137
|
-
this.logResult(err);
|
|
138
|
-
throw err;
|
|
139
|
-
})
|
|
140
|
-
.then(output => {
|
|
141
|
-
this.logResult(null, output);
|
|
142
|
-
return output;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
logResult(err, output) {
|
|
147
|
-
const child = this._child;
|
|
148
|
-
|
|
149
|
-
this._logger.removeItem(this._stdoutKey);
|
|
150
|
-
this._logger.removeItem(this._stderrKey);
|
|
151
|
-
child.stdout.removeListener("data", this._updateStdout);
|
|
152
|
-
child.stderr.removeListener("data", this._updateStderr);
|
|
153
|
-
|
|
154
|
-
if (err) {
|
|
155
|
-
this._logger.error(`${chalk.red("Failed")} ${this._logLabel} - ${chalk.red(err.message)}`);
|
|
156
|
-
output = err.output;
|
|
157
|
-
} else {
|
|
158
|
-
const time = ((Date.now() - this._startTime) / 1000).toFixed(2);
|
|
159
|
-
const dispTime = `${chalk.magenta(time)}secs`;
|
|
160
|
-
this._logger.info(`Done ${this._logLabel} ${dispTime} ${chalk.green("exit code 0")}`);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
this.logFinalOutput(err, output);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
checkForErrors(text) {
|
|
167
|
-
return this._checkStdoutError && text && text.match(this._checkStdoutError);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
logFinalOutput(err, output) {
|
|
171
|
-
const level =
|
|
172
|
-
err || (this._forceStderr && output.stderr) || this.checkForErrors(output.stdout)
|
|
173
|
-
? "error"
|
|
174
|
-
: this._outputLevel;
|
|
175
|
-
|
|
176
|
-
if (!output || (!output.stdout && !output.stderr)) {
|
|
177
|
-
this._logger[level](`${chalk.green("No output")} from ${this._outputLabel}`);
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const colorize = t => t.replace(/ERR!/g, chalk.red("ERR!"));
|
|
182
|
-
|
|
183
|
-
const logs = [chalk.green(">>>"), `Start of output from ${this._outputLabel} ===`];
|
|
184
|
-
|
|
185
|
-
if (output.stdout) {
|
|
186
|
-
logs.push(`\n${colorize(output.stdout)}`);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (output.stderr) {
|
|
190
|
-
logs.push(chalk.red("\n=== stderr ===\n") + colorize(output.stderr));
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
logs.push(chalk.blue("\n<<<"), `End of output from ${this._outputLabel} ---`);
|
|
194
|
-
this._logger.prefix(false)[level](...logs);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
execute(command) {
|
|
198
|
-
this._startTime = Date.now();
|
|
199
|
-
const child = xsh.exec(
|
|
200
|
-
{
|
|
201
|
-
silent: true,
|
|
202
|
-
cwd: this._cwd,
|
|
203
|
-
env: Object.assign({}, process.env, { PWD: this._cwd }),
|
|
204
|
-
maxBuffer: this._maxBuffer
|
|
205
|
-
},
|
|
206
|
-
command || this._command
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
return this.show(child);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
module.exports = VisualExec;
|