@wocker/utils 2.0.6 → 2.0.7-beta.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.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class ProgressBar {
|
|
2
|
+
protected label?: string | undefined;
|
|
3
|
+
protected readonly stdout: NodeJS.WriteStream & {
|
|
4
|
+
fd: 1;
|
|
5
|
+
};
|
|
6
|
+
protected progress: number;
|
|
7
|
+
constructor(label?: string | undefined, stdout?: NodeJS.WriteStream & {
|
|
8
|
+
fd: 1;
|
|
9
|
+
});
|
|
10
|
+
start(): void;
|
|
11
|
+
stop(): void;
|
|
12
|
+
update(progress: number, label?: string): void;
|
|
13
|
+
render(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProgressBar = void 0;
|
|
4
|
+
class ProgressBar {
|
|
5
|
+
constructor(label, stdout = process.stdout) {
|
|
6
|
+
this.label = label;
|
|
7
|
+
this.stdout = stdout;
|
|
8
|
+
this.progress = 0;
|
|
9
|
+
}
|
|
10
|
+
start() {
|
|
11
|
+
this.render();
|
|
12
|
+
}
|
|
13
|
+
stop() {
|
|
14
|
+
this.stdout.write("\n");
|
|
15
|
+
}
|
|
16
|
+
update(progress, label) {
|
|
17
|
+
this.progress = progress;
|
|
18
|
+
if (label) {
|
|
19
|
+
this.label = label;
|
|
20
|
+
}
|
|
21
|
+
this.render();
|
|
22
|
+
}
|
|
23
|
+
render() {
|
|
24
|
+
const [consoleWidth] = this.stdout.getWindowSize(), label = this.label || "Processing", percentage = this.progress.toString().padStart(3, " ") + "%", width = Math.min(100, consoleWidth - label.length - percentage.length - 5), filled = Math.round(width * this.progress / 100), bar = "█".repeat(Math.min(width, filled)) + "░".repeat(Math.max(0, width - filled));
|
|
25
|
+
this.stdout.write(`\r${label}: ${bar} ${percentage}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ProgressBar = ProgressBar;
|
package/lib/makes/index.d.ts
CHANGED
package/lib/makes/index.js
CHANGED
|
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ProgressBar"), exports);
|
|
17
18
|
__exportStar(require("./Volume"), exports);
|
|
@@ -15,19 +15,19 @@ const validatePrompt_1 = require("../validation/validatePrompt");
|
|
|
15
15
|
const prepareMessage_1 = require("../tools/prepareMessage");
|
|
16
16
|
const prepareHelp_1 = require("../tools/prepareHelp");
|
|
17
17
|
exports.promptConfirm = (0, core_1.createPrompt)((config, done) => {
|
|
18
|
-
const { message = "Confirm", default: defaultValue
|
|
18
|
+
const { message = "Confirm", default: defaultValue } = config;
|
|
19
19
|
const [status, setStatus] = (0, core_1.useState)("idle"), [inputValue, setInputValue] = (0, core_1.useState)(""), [error, setError] = (0, core_1.useState)(""), icon = (0, core_1.usePrefix)({ status });
|
|
20
|
-
const result = (0, core_1.useMemo)(() => {
|
|
20
|
+
const [result, validResult] = (0, core_1.useMemo)(() => {
|
|
21
21
|
if (inputValue) {
|
|
22
22
|
if (/^y(es?)?$/i.test(inputValue)) {
|
|
23
|
-
return true;
|
|
23
|
+
return [true, true];
|
|
24
24
|
}
|
|
25
25
|
else if (/^(n|no)$/i.test(inputValue)) {
|
|
26
|
-
return false;
|
|
26
|
+
return [false, true];
|
|
27
27
|
}
|
|
28
|
-
return undefined;
|
|
28
|
+
return [undefined, false];
|
|
29
29
|
}
|
|
30
|
-
return defaultValue;
|
|
30
|
+
return [defaultValue, true];
|
|
31
31
|
}, [inputValue, defaultValue]);
|
|
32
32
|
const theme = (0, core_1.makeTheme)({
|
|
33
33
|
style: {
|
|
@@ -41,7 +41,7 @@ exports.promptConfirm = (0, core_1.createPrompt)((config, done) => {
|
|
|
41
41
|
switch (key.name) {
|
|
42
42
|
case "return":
|
|
43
43
|
setInputValue("");
|
|
44
|
-
if (
|
|
44
|
+
if (!validResult) {
|
|
45
45
|
setStatus("error");
|
|
46
46
|
setError("Invalid value");
|
|
47
47
|
break;
|
|
@@ -53,7 +53,8 @@ exports.promptConfirm = (0, core_1.createPrompt)((config, done) => {
|
|
|
53
53
|
break;
|
|
54
54
|
}
|
|
55
55
|
setStatus("done");
|
|
56
|
-
|
|
56
|
+
setInputValue(result ? "Yes" : "No");
|
|
57
|
+
done(result !== null && result !== void 0 ? result : false);
|
|
57
58
|
break;
|
|
58
59
|
case "tab":
|
|
59
60
|
const inputValue = result ? "Yes" : "No";
|
|
@@ -68,12 +69,13 @@ exports.promptConfirm = (0, core_1.createPrompt)((config, done) => {
|
|
|
68
69
|
}));
|
|
69
70
|
return [
|
|
70
71
|
[
|
|
71
|
-
`${icon}
|
|
72
|
-
theme.style.message(message, status, "?"),
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
`${icon}`,
|
|
73
|
+
theme.style.message(message, status, "?").trim(),
|
|
74
|
+
status !== "done"
|
|
75
|
+
? theme.style.defaultAnswer(typeof config.default === "boolean" ? (config.default ? "Y/n" : "y/N") : "y/n")
|
|
76
|
+
: undefined,
|
|
77
|
+
status === "done" ? theme.style.answer(inputValue) : inputValue
|
|
78
|
+
].filter((m) => typeof m !== "undefined").join(" "),
|
|
77
79
|
error
|
|
78
80
|
? theme.style.error(error)
|
|
79
81
|
: ""
|
|
@@ -15,7 +15,7 @@ const messages_1 = require("../messages");
|
|
|
15
15
|
const validatePrompt = (value, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
const { required, min, max, minLength, maxLength, validate } = config;
|
|
17
17
|
const isEmpty = typeof value === "undefined" ||
|
|
18
|
-
(typeof value === "boolean" &&
|
|
18
|
+
(typeof value === "boolean" && false) ||
|
|
19
19
|
(typeof value === "string" && value === "") ||
|
|
20
20
|
(typeof value === "object" && value === null) ||
|
|
21
21
|
(typeof value === "number" && isNaN(value)) ||
|