message-await 1.1.0 → 2.0.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/.github/workflows/build.yml +3 -3
- package/.github/workflows/release.yml +4 -4
- package/eslint.config.js +26 -0
- package/package.json +48 -52
- package/tsconfig.json +12 -71
- package/.eslintrc.js +0 -32
- package/dist/src/constants.d.ts +0 -2
- package/dist/src/constants.js +0 -8
- package/dist/src/contracts.d.ts +0 -58
- package/dist/src/contracts.js +0 -2
- package/dist/src/index.d.ts +0 -9
- package/dist/src/index.js +0 -171
|
@@ -13,10 +13,10 @@ jobs:
|
|
|
13
13
|
runs-on: ubuntu-latest
|
|
14
14
|
|
|
15
15
|
steps:
|
|
16
|
-
- uses: actions/checkout@
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
17
|
- name: Use Node.js
|
|
18
|
-
uses: actions/setup-node@
|
|
18
|
+
uses: actions/setup-node@v4
|
|
19
19
|
with:
|
|
20
|
-
node-version:
|
|
20
|
+
node-version: 20.x
|
|
21
21
|
- run: npm ci
|
|
22
22
|
- run: npm run verify-release
|
|
@@ -6,12 +6,12 @@ jobs:
|
|
|
6
6
|
build:
|
|
7
7
|
runs-on: ubuntu-latest
|
|
8
8
|
steps:
|
|
9
|
-
- uses: actions/checkout@
|
|
9
|
+
- uses: actions/checkout@v4
|
|
10
10
|
# Setup .npmrc file to publish to npm
|
|
11
|
-
- uses: actions/setup-node@
|
|
11
|
+
- uses: actions/setup-node@v4
|
|
12
12
|
with:
|
|
13
|
-
node-version:
|
|
13
|
+
node-version: 20.x
|
|
14
14
|
- run: npm ci
|
|
15
|
-
- uses: JS-DevTools/npm-publish@
|
|
15
|
+
- uses: JS-DevTools/npm-publish@v3
|
|
16
16
|
with:
|
|
17
17
|
token: ${{ secrets.NPM_TOKEN }}
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import typescriptParser from '@typescript-eslint/parser';
|
|
2
|
+
import typescriptPlugin from '@typescript-eslint/eslint-plugin';
|
|
3
|
+
import prettierPlugin from 'eslint-plugin-prettier';
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{
|
|
7
|
+
ignores: ['dist/'],
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
languageOptions: {
|
|
11
|
+
parser: typescriptParser,
|
|
12
|
+
parserOptions: {
|
|
13
|
+
ecmaVersion: 2020,
|
|
14
|
+
sourceType: 'module',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
plugins: {
|
|
18
|
+
'@typescript-eslint': typescriptPlugin,
|
|
19
|
+
prettier: prettierPlugin,
|
|
20
|
+
},
|
|
21
|
+
rules: {
|
|
22
|
+
'prettier/prettier': ['error', { endOfLine: 'auto', tabWidth: 4, singleQuote: true, printWidth: 120 }],
|
|
23
|
+
},
|
|
24
|
+
files: ['**/*.ts', '**/*.js'],
|
|
25
|
+
},
|
|
26
|
+
];
|
package/package.json
CHANGED
|
@@ -1,54 +1,50 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"bugs": {
|
|
51
|
-
"url": "https://github.com/Roaders/message-await/issues"
|
|
52
|
-
},
|
|
53
|
-
"homepage": "https://github.com/Roaders/message-await#readme"
|
|
2
|
+
"name": "message-await",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "A utility to print message with an async success or failure in node.js",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "rimraf dist",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"build:watch": "tsc --watch",
|
|
10
|
+
"lint": "eslint .",
|
|
11
|
+
"lint:fix": "eslint . --fix",
|
|
12
|
+
"verify-release": "concurrently npm:lint npm:build",
|
|
13
|
+
"prepublishOnly": "npm run clean && npm run verify-release"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"async",
|
|
17
|
+
"node",
|
|
18
|
+
"await",
|
|
19
|
+
"print",
|
|
20
|
+
"message"
|
|
21
|
+
],
|
|
22
|
+
"author": "Giles Roadnight",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"cli-cursor": "^3.1.0",
|
|
26
|
+
"log-symbols": "^4.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^14.17.9",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^8.57.0",
|
|
31
|
+
"@typescript-eslint/parser": "^8.57.0",
|
|
32
|
+
"chalk": "^4.1.2",
|
|
33
|
+
"concurrently": "^9.2.1",
|
|
34
|
+
"eslint": "^10.0.3",
|
|
35
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
36
|
+
"prettier": "^3.0.0",
|
|
37
|
+
"rimraf": "^6.1.3",
|
|
38
|
+
"typescript": "^4.3.5"
|
|
39
|
+
},
|
|
40
|
+
"types": "./dist/src/index.d.ts",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/Roaders/message-await.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/Roaders/message-await/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/Roaders/message-await#readme",
|
|
49
|
+
"type": "module"
|
|
54
50
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,72 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
|
-
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
|
-
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
-
"outDir": "./dist", /* Redirect output structure to the directory. */
|
|
18
|
-
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
|
-
// "composite": true, /* Enable project compilation */
|
|
20
|
-
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
21
|
-
// "removeComments": true, /* Do not emit comments to output. */
|
|
22
|
-
// "noEmit": true, /* Do not emit outputs. */
|
|
23
|
-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
24
|
-
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
25
|
-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
26
|
-
|
|
27
|
-
/* Strict Type-Checking Options */
|
|
28
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
29
|
-
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
30
|
-
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
31
|
-
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
32
|
-
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
33
|
-
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
34
|
-
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
35
|
-
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
36
|
-
|
|
37
|
-
/* Additional Checks */
|
|
38
|
-
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
39
|
-
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
40
|
-
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
41
|
-
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
42
|
-
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
43
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
|
|
44
|
-
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
|
45
|
-
|
|
46
|
-
/* Module Resolution Options */
|
|
47
|
-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
48
|
-
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
49
|
-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
50
|
-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
51
|
-
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
52
|
-
// "types": [], /* Type declaration files to be included in compilation. */
|
|
53
|
-
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
54
|
-
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
55
|
-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
56
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
57
|
-
|
|
58
|
-
/* Source Map Options */
|
|
59
|
-
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
60
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
61
|
-
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
62
|
-
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
63
|
-
|
|
64
|
-
/* Experimental Options */
|
|
65
|
-
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
66
|
-
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
67
|
-
|
|
68
|
-
/* Advanced Options */
|
|
69
|
-
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
70
|
-
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
71
|
-
}
|
|
72
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"moduleResolution": "nodenext"
|
|
12
|
+
}
|
|
13
|
+
}
|
package/.eslintrc.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
browser: true,
|
|
4
|
-
node: true,
|
|
5
|
-
},
|
|
6
|
-
extends: [
|
|
7
|
-
'eslint:recommended',
|
|
8
|
-
'plugin:@typescript-eslint/eslint-recommended',
|
|
9
|
-
'plugin:@typescript-eslint/recommended',
|
|
10
|
-
'prettier',
|
|
11
|
-
'prettier/@typescript-eslint',
|
|
12
|
-
'plugin:prettier/recommended',
|
|
13
|
-
],
|
|
14
|
-
parser: '@typescript-eslint/parser',
|
|
15
|
-
parserOptions: {
|
|
16
|
-
ecmaVersion: 11,
|
|
17
|
-
sourceType: 'module',
|
|
18
|
-
},
|
|
19
|
-
plugins: ['@typescript-eslint'],
|
|
20
|
-
ignorePatterns: ['dist/'],
|
|
21
|
-
rules: {
|
|
22
|
-
'prettier/prettier': ['error', { endOfLine: 'auto', tabWidth: 4, singleQuote: true, printWidth: 120 }],
|
|
23
|
-
},
|
|
24
|
-
overrides: [
|
|
25
|
-
{
|
|
26
|
-
files: ['*.js'],
|
|
27
|
-
rules: {
|
|
28
|
-
'@typescript-eslint/no-var-requires': 'off',
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
};
|
package/dist/src/constants.d.ts
DELETED
package/dist/src/constants.js
DELETED
package/dist/src/contracts.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export declare type MessageAwaitOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* Display an animated ellipses (...) at the end of the message
|
|
4
|
-
* Defaults to false
|
|
5
|
-
*/
|
|
6
|
-
spinner: boolean;
|
|
7
|
-
/**
|
|
8
|
-
* An optional function to format the message. for example: chalk.blue
|
|
9
|
-
*/
|
|
10
|
-
format: (message: string) => string;
|
|
11
|
-
/**
|
|
12
|
-
* If true hides the cursor whilst the message is displayed to avoid flickering.
|
|
13
|
-
* Defaults to true.
|
|
14
|
-
*/
|
|
15
|
-
hideCursor: boolean;
|
|
16
|
-
};
|
|
17
|
-
export interface UpdateMessage {
|
|
18
|
-
/**
|
|
19
|
-
* marks the message as complete.
|
|
20
|
-
* @param success - defaults to true. Adds a tick or a cross to the message
|
|
21
|
-
* @param updateMessage - optionally updates the displayed message
|
|
22
|
-
*/
|
|
23
|
-
complete: (success?: boolean, updateMessage?: string) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Marks the message as complete with a tick.
|
|
26
|
-
* Optionally update the displayed message
|
|
27
|
-
*/
|
|
28
|
-
success: (updateMessage?: string) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Marks the message as failed with a cross.
|
|
31
|
-
* Optionally update the displayed message
|
|
32
|
-
*/
|
|
33
|
-
fail: (updateMessage?: string) => void;
|
|
34
|
-
/**
|
|
35
|
-
* logs a message whilst waiting for the main message to complete pass any number of items to be logged using console.log
|
|
36
|
-
*/
|
|
37
|
-
log: (message: string, ...optional: unknown[]) => void;
|
|
38
|
-
/**
|
|
39
|
-
* Updates the message. For example could display progress: updateMessage(`Loaded 3/4`);
|
|
40
|
-
* Optionally start or stop the spinner.
|
|
41
|
-
*/
|
|
42
|
-
updateMessage: (message: string, spinner?: boolean) => void;
|
|
43
|
-
/**
|
|
44
|
-
* gets the currently displayed message
|
|
45
|
-
*/
|
|
46
|
-
getMessage: () => string;
|
|
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/contracts.js
DELETED
package/dist/src/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MessageAwait, MessageAwaitOptions } from './contracts';
|
|
2
|
-
export * from './contracts';
|
|
3
|
-
/**
|
|
4
|
-
* prints the initial message
|
|
5
|
-
* @param message - message to display
|
|
6
|
-
* @param options - MessageAwaitOptions
|
|
7
|
-
* @returns MessageAwait - options to complete the message when done or update the message with progress info
|
|
8
|
-
*/
|
|
9
|
-
export default function print(message: string, options?: Partial<MessageAwaitOptions>): MessageAwait;
|
package/dist/src/index.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
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));
|
|
35
|
-
};
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
var readline_1 = require("readline");
|
|
38
|
-
var cli_cursor_1 = require("cli-cursor");
|
|
39
|
-
var constants_1 = require("./constants");
|
|
40
|
-
__exportStar(require("./contracts"), exports);
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
42
|
-
var logSymbols = require('log-symbols');
|
|
43
|
-
/**
|
|
44
|
-
* prints the initial message
|
|
45
|
-
* @param message - message to display
|
|
46
|
-
* @param options - MessageAwaitOptions
|
|
47
|
-
* @returns MessageAwait - options to complete the message when done or update the message with progress info
|
|
48
|
-
*/
|
|
49
|
-
function print(message, options) {
|
|
50
|
-
var requiredOptions = __assign(__assign({}, constants_1.defaultOptions), options);
|
|
51
|
-
var timeout;
|
|
52
|
-
var isComplete = false;
|
|
53
|
-
var dotCount = 3;
|
|
54
|
-
function generateMessage() {
|
|
55
|
-
var dots = Array.from({ length: dotCount })
|
|
56
|
-
.map(function () { return '.'; })
|
|
57
|
-
.join('');
|
|
58
|
-
while (dots.length < 3) {
|
|
59
|
-
dots = dots + ' ';
|
|
60
|
-
}
|
|
61
|
-
return requiredOptions.format(message + dots);
|
|
62
|
-
}
|
|
63
|
-
function resetCursor() {
|
|
64
|
-
(0, readline_1.cursorTo)(process.stdout, 0);
|
|
65
|
-
(0, readline_1.clearLine)(process.stdout, 1);
|
|
66
|
-
}
|
|
67
|
-
function writeMessage() {
|
|
68
|
-
resetCursor();
|
|
69
|
-
process.stdout.write(generateMessage());
|
|
70
|
-
}
|
|
71
|
-
function startTimer() {
|
|
72
|
-
dotCount = 0;
|
|
73
|
-
writeMessage();
|
|
74
|
-
timeout = setInterval(function () {
|
|
75
|
-
switch (dotCount) {
|
|
76
|
-
case 3:
|
|
77
|
-
dotCount = 0;
|
|
78
|
-
writeMessage();
|
|
79
|
-
break;
|
|
80
|
-
default:
|
|
81
|
-
dotCount++;
|
|
82
|
-
writeMessage();
|
|
83
|
-
}
|
|
84
|
-
}, 300).unref();
|
|
85
|
-
}
|
|
86
|
-
function updateMessage(messageUpdate, spinner) {
|
|
87
|
-
if (isComplete) {
|
|
88
|
-
throw new Error("Progress Message is complete");
|
|
89
|
-
}
|
|
90
|
-
if (spinner === true && timeout == null) {
|
|
91
|
-
startTimer();
|
|
92
|
-
}
|
|
93
|
-
else if (spinner === false && timeout != null) {
|
|
94
|
-
dotCount = 0;
|
|
95
|
-
clearInterval(timeout);
|
|
96
|
-
timeout = undefined;
|
|
97
|
-
}
|
|
98
|
-
message = messageUpdate;
|
|
99
|
-
writeMessage();
|
|
100
|
-
}
|
|
101
|
-
function log(logMessage) {
|
|
102
|
-
var optional = [];
|
|
103
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
104
|
-
optional[_i - 1] = arguments[_i];
|
|
105
|
-
}
|
|
106
|
-
if (isComplete) {
|
|
107
|
-
throw new Error("Progress Message is complete");
|
|
108
|
-
}
|
|
109
|
-
resetCursor();
|
|
110
|
-
console.log.apply(console, __spreadArray([logMessage], optional, false));
|
|
111
|
-
writeMessage();
|
|
112
|
-
}
|
|
113
|
-
function complete(success, updateMessage) {
|
|
114
|
-
if (success === void 0) { success = true; }
|
|
115
|
-
isComplete = true;
|
|
116
|
-
if (timeout != null) {
|
|
117
|
-
clearInterval(timeout);
|
|
118
|
-
}
|
|
119
|
-
dotCount = 3;
|
|
120
|
-
resetCursor();
|
|
121
|
-
message = updateMessage || message;
|
|
122
|
-
if (success) {
|
|
123
|
-
console.log("".concat(generateMessage(), " ").concat(logSymbols.success));
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
console.log("".concat(generateMessage(), " ").concat(logSymbols.error));
|
|
127
|
-
}
|
|
128
|
-
if (requiredOptions.hideCursor) {
|
|
129
|
-
(0, cli_cursor_1.show)();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function success(updateMessage) {
|
|
133
|
-
return complete(true, updateMessage);
|
|
134
|
-
}
|
|
135
|
-
function fail(updateMessage) {
|
|
136
|
-
return complete(false, updateMessage);
|
|
137
|
-
}
|
|
138
|
-
function getMessage() {
|
|
139
|
-
return message;
|
|
140
|
-
}
|
|
141
|
-
function await(promise, exitProcess, printError, updateSuccessMessage, updateFailureMessage) {
|
|
142
|
-
return (typeof promise === 'function'
|
|
143
|
-
? promise({ complete: complete, log: log, updateMessage: updateMessage, getMessage: getMessage, success: success, fail: fail })
|
|
144
|
-
: promise)
|
|
145
|
-
.then(function (value) {
|
|
146
|
-
complete(true, typeof updateSuccessMessage === 'function' ? updateSuccessMessage(value) : updateSuccessMessage);
|
|
147
|
-
return value;
|
|
148
|
-
})
|
|
149
|
-
.catch(function (err) {
|
|
150
|
-
complete(false, typeof updateFailureMessage === 'function' ? updateFailureMessage(err) : updateFailureMessage);
|
|
151
|
-
if (printError) {
|
|
152
|
-
console.error(err);
|
|
153
|
-
}
|
|
154
|
-
if (exitProcess) {
|
|
155
|
-
process.exit();
|
|
156
|
-
}
|
|
157
|
-
return Promise.reject(err);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
if (requiredOptions.hideCursor) {
|
|
161
|
-
(0, cli_cursor_1.hide)();
|
|
162
|
-
}
|
|
163
|
-
if (requiredOptions.spinner) {
|
|
164
|
-
startTimer();
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
writeMessage();
|
|
168
|
-
}
|
|
169
|
-
return { complete: complete, log: log, updateMessage: updateMessage, getMessage: getMessage, success: success, fail: fail, await: await };
|
|
170
|
-
}
|
|
171
|
-
exports.default = print;
|