Skip to content

Commit

Permalink
Make spinner less chatty in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Oct 2, 2024
1 parent 136965f commit 45c853c
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions scripts/utils/spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,63 @@

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() {
return this.#message
}

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
}
Expand Down

0 comments on commit 45c853c

Please sign in to comment.