message-await 0.3.1 → 0.4.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/src/contracts.d.ts +13 -11
- package/dist/src/index.js +27 -17
- package/package.json +1 -1
package/dist/src/contracts.d.ts
CHANGED
|
@@ -14,16 +14,7 @@ export declare type MessageAwaitOptions = {
|
|
|
14
14
|
*/
|
|
15
15
|
hideCursor: boolean;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
18
|
-
/**
|
|
19
|
-
* awaits the completion of a promise and marks the message as success or failure based on the promise
|
|
20
|
-
* @param promise
|
|
21
|
-
* @param exitProcess - if the promise is rejected exits the node process. Defaults to false
|
|
22
|
-
* @param printError - if the promise is rejected prints the error that is returned. Defaults to false
|
|
23
|
-
* @param updateSuccessMessage - optional. update the message on success
|
|
24
|
-
* @param updateFailureMessage - optional. update the message on rejection
|
|
25
|
-
*/
|
|
26
|
-
await: <T>(promise: Promise<T>, exitProcess?: boolean, printError?: boolean, updateSuccessMessage?: string | ((result: T) => string), updateFailureMessage?: string) => Promise<T>;
|
|
17
|
+
export interface UpdateMessage {
|
|
27
18
|
/**
|
|
28
19
|
* marks the message as complete.
|
|
29
20
|
* @param success - defaults to true. Adds a tick or a cross to the message
|
|
@@ -53,4 +44,15 @@ export declare type MessageAwait = {
|
|
|
53
44
|
* gets the currently displayed message
|
|
54
45
|
*/
|
|
55
46
|
getMessage: () => string;
|
|
56
|
-
}
|
|
47
|
+
}
|
|
48
|
+
export interface MessageAwait extends UpdateMessage {
|
|
49
|
+
/**
|
|
50
|
+
* awaits the completion of a promise and marks the message as success or failure based on the promise
|
|
51
|
+
* @param promise
|
|
52
|
+
* @param exitProcess - if the promise is rejected exits the node process. Defaults to false
|
|
53
|
+
* @param printError - if the promise is rejected prints the error that is returned. Defaults to false
|
|
54
|
+
* @param updateSuccessMessage - optional. update the message on success
|
|
55
|
+
* @param updateFailureMessage - optional. update the message on rejection
|
|
56
|
+
*/
|
|
57
|
+
await: <T>(promise: Promise<T> | ((updateMessage: UpdateMessage) => Promise<T>), exitProcess?: boolean, printError?: boolean, updateSuccessMessage?: string | ((result: T) => string), updateFailureMessage?: string | ((error: unknown) => string)) => Promise<T>;
|
|
58
|
+
}
|
package/dist/src/index.js
CHANGED
|
@@ -12,7 +12,11 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
14
|
if (k2 === undefined) k2 = k;
|
|
15
|
-
Object.
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
16
20
|
}) : (function(o, m, k, k2) {
|
|
17
21
|
if (k2 === undefined) k2 = k;
|
|
18
22
|
o[k2] = m[k];
|
|
@@ -20,10 +24,14 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
20
24
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
25
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
26
|
};
|
|
23
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
24
|
-
for (var i = 0,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
28
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
29
|
+
if (ar || !(i in from)) {
|
|
30
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
31
|
+
ar[i] = from[i];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
27
35
|
};
|
|
28
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
37
|
var readline_1 = require("readline");
|
|
@@ -53,8 +61,8 @@ function print(message, options) {
|
|
|
53
61
|
return requiredOptions.format(message + dots);
|
|
54
62
|
}
|
|
55
63
|
function resetCursor() {
|
|
56
|
-
readline_1.cursorTo(process.stdout, 0);
|
|
57
|
-
readline_1.clearLine(process.stdout, 1);
|
|
64
|
+
(0, readline_1.cursorTo)(process.stdout, 0);
|
|
65
|
+
(0, readline_1.clearLine)(process.stdout, 1);
|
|
58
66
|
}
|
|
59
67
|
function writeMessage() {
|
|
60
68
|
resetCursor();
|
|
@@ -99,7 +107,7 @@ function print(message, options) {
|
|
|
99
107
|
throw new Error("Progress Message is complete");
|
|
100
108
|
}
|
|
101
109
|
resetCursor();
|
|
102
|
-
console.log.apply(console, __spreadArray([logMessage], optional));
|
|
110
|
+
console.log.apply(console, __spreadArray([logMessage], optional, false));
|
|
103
111
|
writeMessage();
|
|
104
112
|
}
|
|
105
113
|
function complete(success, updateMessage) {
|
|
@@ -112,13 +120,13 @@ function print(message, options) {
|
|
|
112
120
|
resetCursor();
|
|
113
121
|
message = updateMessage || message;
|
|
114
122
|
if (success) {
|
|
115
|
-
console.log(generateMessage()
|
|
123
|
+
console.log("".concat(generateMessage(), " ").concat(logSymbols.success));
|
|
116
124
|
}
|
|
117
125
|
else {
|
|
118
|
-
console.log(generateMessage()
|
|
126
|
+
console.log("".concat(generateMessage(), " ").concat(logSymbols.error));
|
|
119
127
|
}
|
|
120
128
|
if (requiredOptions.hideCursor) {
|
|
121
|
-
cli_cursor_1.show();
|
|
129
|
+
(0, cli_cursor_1.show)();
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
132
|
function success(updateMessage) {
|
|
@@ -127,14 +135,19 @@ function print(message, options) {
|
|
|
127
135
|
function fail(updateMessage) {
|
|
128
136
|
return complete(false, updateMessage);
|
|
129
137
|
}
|
|
138
|
+
function getMessage() {
|
|
139
|
+
return message;
|
|
140
|
+
}
|
|
130
141
|
function await(promise, exitProcess, printError, updateSuccessMessage, updateFailureMessage) {
|
|
131
|
-
return promise
|
|
142
|
+
return (typeof promise === 'function'
|
|
143
|
+
? promise({ complete: complete, log: log, updateMessage: updateMessage, getMessage: getMessage, success: success, fail: fail })
|
|
144
|
+
: promise)
|
|
132
145
|
.then(function (value) {
|
|
133
146
|
complete(true, typeof updateSuccessMessage === 'function' ? updateSuccessMessage(value) : updateSuccessMessage);
|
|
134
147
|
return value;
|
|
135
148
|
})
|
|
136
149
|
.catch(function (err) {
|
|
137
|
-
complete(false, updateFailureMessage);
|
|
150
|
+
complete(false, typeof updateFailureMessage === 'function' ? updateFailureMessage(err) : updateFailureMessage);
|
|
138
151
|
if (printError) {
|
|
139
152
|
console.error(err);
|
|
140
153
|
}
|
|
@@ -144,11 +157,8 @@ function print(message, options) {
|
|
|
144
157
|
return Promise.reject(err);
|
|
145
158
|
});
|
|
146
159
|
}
|
|
147
|
-
function getMessage() {
|
|
148
|
-
return message;
|
|
149
|
-
}
|
|
150
160
|
if (requiredOptions.hideCursor) {
|
|
151
|
-
cli_cursor_1.hide();
|
|
161
|
+
(0, cli_cursor_1.hide)();
|
|
152
162
|
}
|
|
153
163
|
if (requiredOptions.spinner) {
|
|
154
164
|
startTimer();
|