diff options
author | Minteck <nekostarfan@gmail.com> | 2021-08-24 14:41:48 +0200 |
---|---|---|
committer | Minteck <nekostarfan@gmail.com> | 2021-08-24 14:41:48 +0200 |
commit | d25e11bee6ca5ca523884da132d18e1400e077b9 (patch) | |
tree | 8af39fde19f7ed640a60fb397c7edd647dff1c4c /node_modules/nexe/lib/logger.js | |
download | kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.gz kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.tar.bz2 kartik-iridium-d25e11bee6ca5ca523884da132d18e1400e077b9.zip |
Initial commit
Diffstat (limited to 'node_modules/nexe/lib/logger.js')
-rw-r--r-- | node_modules/nexe/lib/logger.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/node_modules/nexe/lib/logger.js b/node_modules/nexe/lib/logger.js new file mode 100644 index 0000000..31f33a2 --- /dev/null +++ b/node_modules/nexe/lib/logger.js @@ -0,0 +1,56 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const chalk_1 = require("chalk"); +const ora_1 = require("ora"); +const frameLength = 120; +class Logger { + constructor(level) { + this.verbose = level === 'verbose'; + this.silent = level === 'silent'; + if (!this.silent) { + this.ora = ora_1.default({ + text: 'Starting...', + color: 'blue', + spinner: 'dots', + }); + this.ora.stop(); + } + const noop = () => { }; + this.modify = this.silent ? noop : this._modify.bind(this); + this.write = this.silent ? noop : this._write.bind(this); + } + flush() { + !this.silent && this.ora.succeed(); + return new Promise((resolve) => setTimeout(resolve, frameLength)); + } + _write(update, color = 'green') { + this.ora.succeed().text = chalk_1.default[color](update); + this.ora.start(); + } + _modify(update, color = this.ora.color) { + this.ora.text = update; + this.ora.color = color; + } + step(text, method = 'succeed') { + if (this.silent) { + return { modify() { }, log() { }, pause() { }, resume() { } }; + } + if (!this.ora.id) { + this.ora.start().text = text; + if (method !== 'succeed') { + this.ora[method](); + } + } + else { + this.ora[method]().text = text; + this.ora.start(); + } + return { + modify: this.modify, + log: this.verbose ? this.write : this.modify, + pause: () => this.ora.stopAndPersist(), + resume: () => this.ora.start(), + }; + } +} +exports.Logger = Logger; |