diff --git a/scripts/utils/spinner.js b/scripts/utils/spinner.js index 91372a4c..03c8cfcc 100644 --- a/scripts/utils/spinner.js +++ b/scripts/utils/spinner.js @@ -2,14 +2,24 @@ const { loading: cliLoadingAnimation } = require('cli-loading-animation') +const { ENV } = require('@socketregistry/scripts/constants') + +function logAsync(...args) { + return setTimeout(() => console.log(...args), 80) +} + class Spinner { #message - #options + #claOptions #spinner + #spinnerOptions + #spinning constructor(message, options) { + const { ci = ENV.CI, ...claOptions } = { __proto__: null, ...options } + this.#claOptions = { __proto__: null, ...claOptions, clearOnEnd: true } this.#message = message - this.#options = { __proto__: null, ...options, clearOnEnd: true } - this.#spinner = cliLoadingAnimation(this.#message, this.#options) + this.#spinnerOptions = { __proto__: null, ci } + this.#spinner = cliLoadingAnimation(this.#message, this.#claOptions) } get message() { @@ -17,20 +27,38 @@ class Spinner { } set message(text) { - this.#spinner.stop() this.#message = text - this.#spinner = cliLoadingAnimation(this.#message, this.#options) + if (!this.#spinnerOptions.ci) { + this.#spinner.stop() + } + this.#spinner = cliLoadingAnimation(this.#message, this.#claOptions) + if (this.#spinnerOptions.ci) { + logAsync(this.#message) + } else { + this.#spinner.start() + } } start() { - this.#spinner.stop() - this.#spinner.start() + if (this.#spinning === false) { + this.#spinning = true + if (this.#spinnerOptions.ci) { + logAsync(this.#message) + } else { + this.#spinner.start() + } + } return this } stop(...args) { - this.#spinner.stop() - if (args.length) { - console.log(...args) + if (this.#spinning === true) { + this.#spinning = false + if (!this.#spinnerOptions.ci) { + this.#spinner.stop() + } + if (args.length) { + logAsync(...args) + } } return this }