MCPcopy Create free account
hub / github.com/code-pushup/cli / #spinner

Method #spinner

packages/utils/src/lib/logger.ts:397–476  ·  view source on GitHub ↗
(
    worker: () => Promise<T>,
    messages: {
      pending: string;
      success: (value: T) => string;
      failure: (error: unknown) => string;
    },
  )

Source from the content-addressed store, hash-verified

395
396 // eslint-disable-next-line max-lines-per-function
397 async #spinner<T>(
398 worker: () => Promise<T>,
399 messages: {
400 pending: string;
401 success: (value: T) => string;
402 failure: (error: unknown) => string;
403 },
404 ): Promise<T> {
405 if (this.#activeSpinner) {
406 throw new Error(
407 'Internal Logger error - concurrent spinners are not supported',
408 );
409 }
410
411 process.removeListener('SIGINT', this.#sigintListener);
412 process.addListener('SIGINT', this.#sigintListener);
413
414 if (this.#groupColor) {
415 this.#activeSpinner = ora({
416 text: messages.pending,
417 spinner: 'line',
418 color: this.#groupColor,
419 stream: process.stdout,
420 });
421 if (this.#isCI) {
422 console.log(this.#format(messages.pending, undefined));
423 } else {
424 this.#activeSpinner.start();
425 }
426 } else {
427 this.#activeSpinner = ora({
428 text: messages.pending,
429 stream: process.stdout,
430 });
431 this.#activeSpinner.start();
432 }
433
434 this.#endsWithBlankLine = false;
435
436 const start = performance.now();
437 const result = await settlePromise(worker());
438 const end = performance.now();
439
440 const text =
441 result.status === 'fulfilled'
442 ? [
443 messages.success(result.value),
444 this.#formatDurationSuffix({ start, end }),
445 ].join(' ')
446 : messages.failure(stringifyError(result.reason, { oneline: true }));
447
448 if (this.#activeSpinner) {
449 if (this.#groupColor) {
450 this.#activeSpinner.stopAndPersist({
451 text,
452 symbol: this.#colorize(this.#groupSymbols.middle, this.#groupColor),
453 });
454 } else {

Callers 2

taskMethod · 0.95
commandMethod · 0.95

Calls 8

#formatMethod · 0.95
#formatDurationSuffixMethod · 0.95
#colorizeMethod · 0.95
#logMethod · 0.95
settlePromiseFunction · 0.85
workerFunction · 0.85
indentLinesFunction · 0.85
stringifyErrorFunction · 0.70

Tested by

no test coverage detected