message-await 0.2.0 → 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 +28 -20
- package/package.json +12 -12
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, 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,12 +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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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));
|
|
29
35
|
};
|
|
30
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
37
|
var readline_1 = require("readline");
|
|
@@ -55,8 +61,8 @@ function print(message, options) {
|
|
|
55
61
|
return requiredOptions.format(message + dots);
|
|
56
62
|
}
|
|
57
63
|
function resetCursor() {
|
|
58
|
-
readline_1.cursorTo(process.stdout, 0);
|
|
59
|
-
readline_1.clearLine(process.stdout, 1);
|
|
64
|
+
(0, readline_1.cursorTo)(process.stdout, 0);
|
|
65
|
+
(0, readline_1.clearLine)(process.stdout, 1);
|
|
60
66
|
}
|
|
61
67
|
function writeMessage() {
|
|
62
68
|
resetCursor();
|
|
@@ -101,7 +107,7 @@ function print(message, options) {
|
|
|
101
107
|
throw new Error("Progress Message is complete");
|
|
102
108
|
}
|
|
103
109
|
resetCursor();
|
|
104
|
-
console.log.apply(console,
|
|
110
|
+
console.log.apply(console, __spreadArray([logMessage], optional, false));
|
|
105
111
|
writeMessage();
|
|
106
112
|
}
|
|
107
113
|
function complete(success, updateMessage) {
|
|
@@ -114,13 +120,13 @@ function print(message, options) {
|
|
|
114
120
|
resetCursor();
|
|
115
121
|
message = updateMessage || message;
|
|
116
122
|
if (success) {
|
|
117
|
-
console.log(generateMessage()
|
|
123
|
+
console.log("".concat(generateMessage(), " ").concat(logSymbols.success));
|
|
118
124
|
}
|
|
119
125
|
else {
|
|
120
|
-
console.log(generateMessage()
|
|
126
|
+
console.log("".concat(generateMessage(), " ").concat(logSymbols.error));
|
|
121
127
|
}
|
|
122
128
|
if (requiredOptions.hideCursor) {
|
|
123
|
-
cli_cursor_1.show();
|
|
129
|
+
(0, cli_cursor_1.show)();
|
|
124
130
|
}
|
|
125
131
|
}
|
|
126
132
|
function success(updateMessage) {
|
|
@@ -129,14 +135,19 @@ function print(message, options) {
|
|
|
129
135
|
function fail(updateMessage) {
|
|
130
136
|
return complete(false, updateMessage);
|
|
131
137
|
}
|
|
138
|
+
function getMessage() {
|
|
139
|
+
return message;
|
|
140
|
+
}
|
|
132
141
|
function await(promise, exitProcess, printError, updateSuccessMessage, updateFailureMessage) {
|
|
133
|
-
return promise
|
|
142
|
+
return (typeof promise === 'function'
|
|
143
|
+
? promise({ complete: complete, log: log, updateMessage: updateMessage, getMessage: getMessage, success: success, fail: fail })
|
|
144
|
+
: promise)
|
|
134
145
|
.then(function (value) {
|
|
135
|
-
complete(true, updateSuccessMessage);
|
|
146
|
+
complete(true, typeof updateSuccessMessage === 'function' ? updateSuccessMessage(value) : updateSuccessMessage);
|
|
136
147
|
return value;
|
|
137
148
|
})
|
|
138
149
|
.catch(function (err) {
|
|
139
|
-
complete(false, updateFailureMessage);
|
|
150
|
+
complete(false, typeof updateFailureMessage === 'function' ? updateFailureMessage(err) : updateFailureMessage);
|
|
140
151
|
if (printError) {
|
|
141
152
|
console.error(err);
|
|
142
153
|
}
|
|
@@ -146,11 +157,8 @@ function print(message, options) {
|
|
|
146
157
|
return Promise.reject(err);
|
|
147
158
|
});
|
|
148
159
|
}
|
|
149
|
-
function getMessage() {
|
|
150
|
-
return message;
|
|
151
|
-
}
|
|
152
160
|
if (requiredOptions.hideCursor) {
|
|
153
|
-
cli_cursor_1.hide();
|
|
161
|
+
(0, cli_cursor_1.hide)();
|
|
154
162
|
}
|
|
155
163
|
if (requiredOptions.spinner) {
|
|
156
164
|
startTimer();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "message-await",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A utility to print message with an async success or failure in node.js",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,20 +26,20 @@
|
|
|
26
26
|
"log-symbols": "^4.1.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^14.17.
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
31
|
-
"@typescript-eslint/parser": "^4.
|
|
32
|
-
"chalk": "^4.1.
|
|
29
|
+
"@types/node": "^14.17.9",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^4.29.0",
|
|
31
|
+
"@typescript-eslint/parser": "^4.29.0",
|
|
32
|
+
"chalk": "^4.1.2",
|
|
33
33
|
"concurrently": "^6.2.0",
|
|
34
|
-
"eslint": "^7.
|
|
34
|
+
"eslint": "^7.32.0",
|
|
35
35
|
"eslint-config-prettier": "^7.2.0",
|
|
36
|
-
"eslint-config-standard": "^16.0.
|
|
37
|
-
"eslint-plugin-import": "^2.
|
|
36
|
+
"eslint-config-standard": "^16.0.3",
|
|
37
|
+
"eslint-plugin-import": "^2.23.4",
|
|
38
38
|
"eslint-plugin-node": "^11.1.0",
|
|
39
|
-
"eslint-plugin-prettier": "^3.
|
|
40
|
-
"eslint-plugin-promise": "^4.
|
|
41
|
-
"prettier": "^2.2
|
|
39
|
+
"eslint-plugin-prettier": "^3.4.0",
|
|
40
|
+
"eslint-plugin-promise": "^4.3.1",
|
|
41
|
+
"prettier": "^2.3.2",
|
|
42
42
|
"rimraf": "^3.0.2",
|
|
43
|
-
"typescript": "^4.
|
|
43
|
+
"typescript": "^4.3.5"
|
|
44
44
|
}
|
|
45
45
|
}
|