Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.
This commit is contained in:
332
node_modules/ora/index.d.ts
generated
vendored
Normal file
332
node_modules/ora/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,332 @@
|
||||
import {type SpinnerName} from 'cli-spinners';
|
||||
|
||||
export type Spinner = {
|
||||
readonly interval?: number;
|
||||
readonly frames: string[];
|
||||
};
|
||||
|
||||
export type Color =
|
||||
| 'black'
|
||||
| 'red'
|
||||
| 'green'
|
||||
| 'yellow'
|
||||
| 'blue'
|
||||
| 'magenta'
|
||||
| 'cyan'
|
||||
| 'white'
|
||||
| 'gray';
|
||||
|
||||
export type PrefixTextGenerator = () => string;
|
||||
|
||||
export type SuffixTextGenerator = () => string;
|
||||
|
||||
export type Options = {
|
||||
/**
|
||||
The text to display next to the spinner.
|
||||
*/
|
||||
readonly text?: string;
|
||||
|
||||
/**
|
||||
Text or a function that returns text to display before the spinner. No prefix text will be displayed if set to an empty string.
|
||||
*/
|
||||
readonly prefixText?: string | PrefixTextGenerator;
|
||||
|
||||
/**
|
||||
Text or a function that returns text to display after the spinner text. No suffix text will be displayed if set to an empty string.
|
||||
*/
|
||||
readonly suffixText?: string | SuffixTextGenerator;
|
||||
|
||||
/**
|
||||
The name of one of the provided spinners. See [`example.js`](https://github.com/BendingBender/ora/blob/main/example.js) in this repo if you want to test out different spinners. On Windows (expect for Windows Terminal), it will always use the line spinner as the Windows command-line doesn't have proper Unicode support.
|
||||
|
||||
@default 'dots'
|
||||
|
||||
Or an object like:
|
||||
|
||||
@example
|
||||
```
|
||||
{
|
||||
frames: ['-', '+', '-'],
|
||||
interval: 80 // Optional
|
||||
}
|
||||
```
|
||||
*/
|
||||
readonly spinner?: SpinnerName | Spinner;
|
||||
|
||||
/**
|
||||
The color of the spinner.
|
||||
|
||||
@default 'cyan'
|
||||
*/
|
||||
readonly color?: Color | boolean;
|
||||
|
||||
/**
|
||||
Set to `false` to stop Ora from hiding the cursor.
|
||||
|
||||
@default true
|
||||
*/
|
||||
readonly hideCursor?: boolean;
|
||||
|
||||
/**
|
||||
Indent the spinner with the given number of spaces.
|
||||
|
||||
@default 0
|
||||
*/
|
||||
readonly indent?: number;
|
||||
|
||||
/**
|
||||
Interval between each frame.
|
||||
|
||||
Spinners provide their own recommended interval, so you don't really need to specify this.
|
||||
|
||||
Default: Provided by the spinner or `100`.
|
||||
*/
|
||||
readonly interval?: number;
|
||||
|
||||
/**
|
||||
Stream to write the output.
|
||||
|
||||
You could for example set this to `process.stdout` instead.
|
||||
|
||||
@default process.stderr
|
||||
*/
|
||||
readonly stream?: NodeJS.WritableStream;
|
||||
|
||||
/**
|
||||
Force enable/disable the spinner. If not specified, the spinner will be enabled if the `stream` is being run inside a TTY context (not spawned or piped) and/or not in a CI environment.
|
||||
|
||||
Note that `{isEnabled: false}` doesn't mean it won't output anything. It just means it won't output the spinner, colors, and other ansi escape codes. It will still log text.
|
||||
*/
|
||||
readonly isEnabled?: boolean;
|
||||
|
||||
/**
|
||||
Disable the spinner and all log text. All output is suppressed and `isEnabled` will be considered `false`.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly isSilent?: boolean;
|
||||
|
||||
/**
|
||||
Discard stdin input (except Ctrl+C) while running if it's TTY. This prevents the spinner from twitching on input, outputting broken lines on `Enter` key presses, and prevents buffering of input while the spinner is running.
|
||||
|
||||
This has no effect on Windows as there's no good way to implement discarding stdin properly there.
|
||||
|
||||
@default true
|
||||
*/
|
||||
readonly discardStdin?: boolean;
|
||||
};
|
||||
|
||||
export type PersistOptions = {
|
||||
/**
|
||||
Symbol to replace the spinner with.
|
||||
|
||||
@default ' '
|
||||
*/
|
||||
readonly symbol?: string;
|
||||
|
||||
/**
|
||||
Text to be persisted after the symbol.
|
||||
|
||||
Default: Current `text`.
|
||||
*/
|
||||
readonly text?: string;
|
||||
|
||||
/**
|
||||
Text or a function that returns text to be persisted before the symbol. No prefix text will be displayed if set to an empty string.
|
||||
|
||||
Default: Current `prefixText`.
|
||||
*/
|
||||
readonly prefixText?: string | PrefixTextGenerator;
|
||||
|
||||
/**
|
||||
Text or a function that returns text to be persisted after the text after the symbol. No suffix text will be displayed if set to an empty string.
|
||||
|
||||
Default: Current `suffixText`.
|
||||
*/
|
||||
readonly suffixText?: string | SuffixTextGenerator;
|
||||
};
|
||||
|
||||
export type PromiseOptions<T> = {
|
||||
/**
|
||||
The new text of the spinner when the promise is resolved.
|
||||
|
||||
Keeps the existing text if `undefined`.
|
||||
*/
|
||||
successText?: string | ((result: T) => string) | undefined;
|
||||
|
||||
/**
|
||||
The new text of the spinner when the promise is rejected.
|
||||
|
||||
Keeps the existing text if `undefined`.
|
||||
*/
|
||||
failText?: string | ((error: Error) => string) | undefined;
|
||||
} & Options;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
export interface Ora {
|
||||
/**
|
||||
Change the text after the spinner.
|
||||
*/
|
||||
text: string;
|
||||
|
||||
/**
|
||||
Change the text or function that returns text before the spinner.
|
||||
|
||||
No prefix text will be displayed if set to an empty string.
|
||||
*/
|
||||
prefixText: string;
|
||||
|
||||
/**
|
||||
Change the text or function that returns text after the spinner text.
|
||||
|
||||
No suffix text will be displayed if set to an empty string.
|
||||
*/
|
||||
suffixText: string;
|
||||
|
||||
/**
|
||||
Change the spinner color.
|
||||
*/
|
||||
color: Color | boolean;
|
||||
|
||||
/**
|
||||
Change the spinner indent.
|
||||
*/
|
||||
indent: number;
|
||||
|
||||
/**
|
||||
Get the spinner.
|
||||
*/
|
||||
get spinner(): Spinner;
|
||||
|
||||
/**
|
||||
Set the spinner.
|
||||
*/
|
||||
set spinner(spinner: SpinnerName | Spinner);
|
||||
|
||||
/**
|
||||
A boolean indicating whether the instance is currently spinning.
|
||||
*/
|
||||
get isSpinning(): boolean;
|
||||
|
||||
/**
|
||||
The interval between each frame.
|
||||
|
||||
The interval is decided by the chosen spinner.
|
||||
*/
|
||||
get interval(): number;
|
||||
|
||||
/**
|
||||
Start the spinner.
|
||||
|
||||
@param text - Set the current text.
|
||||
@returns The spinner instance.
|
||||
*/
|
||||
start(text?: string): this;
|
||||
|
||||
/**
|
||||
Stop and clear the spinner.
|
||||
|
||||
@returns The spinner instance.
|
||||
*/
|
||||
stop(): this;
|
||||
|
||||
/**
|
||||
Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided.
|
||||
|
||||
@param text - Will persist text if provided.
|
||||
@returns The spinner instance.
|
||||
*/
|
||||
succeed(text?: string): this;
|
||||
|
||||
/**
|
||||
Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided.
|
||||
|
||||
@param text - Will persist text if provided.
|
||||
@returns The spinner instance.
|
||||
*/
|
||||
fail(text?: string): this;
|
||||
|
||||
/**
|
||||
Stop the spinner, change it to a yellow `⚠` and persist the current text, or `text` if provided.
|
||||
|
||||
@param text - Will persist text if provided.
|
||||
@returns The spinner instance.
|
||||
*/
|
||||
warn(text?: string): this;
|
||||
|
||||
/**
|
||||
Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided.
|
||||
|
||||
@param text - Will persist text if provided.
|
||||
@returns The spinner instance.
|
||||
*/
|
||||
info(text?: string): this;
|
||||
|
||||
/**
|
||||
Stop the spinner and change the symbol or text.
|
||||
|
||||
@returns The spinner instance.
|
||||
*/
|
||||
stopAndPersist(options?: PersistOptions): this;
|
||||
|
||||
/**
|
||||
Clear the spinner.
|
||||
|
||||
@returns The spinner instance.
|
||||
*/
|
||||
clear(): this;
|
||||
|
||||
/**
|
||||
Manually render a new frame.
|
||||
|
||||
@returns The spinner instance.
|
||||
*/
|
||||
render(): this;
|
||||
|
||||
/**
|
||||
Get a new frame.
|
||||
|
||||
@returns The spinner instance text.
|
||||
*/
|
||||
frame(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
Elegant terminal spinner.
|
||||
|
||||
@param options - If a string is provided, it is treated as a shortcut for `options.text`.
|
||||
|
||||
@example
|
||||
```
|
||||
import ora from 'ora';
|
||||
|
||||
const spinner = ora('Loading unicorns').start();
|
||||
|
||||
setTimeout(() => {
|
||||
spinner.color = 'yellow';
|
||||
spinner.text = 'Loading rainbows';
|
||||
}, 1000);
|
||||
```
|
||||
*/
|
||||
export default function ora(options?: string | Options): Ora;
|
||||
|
||||
/**
|
||||
Starts a spinner for a promise or promise-returning function. The spinner is stopped with `.succeed()` if the promise fulfills or with `.fail()` if it rejects.
|
||||
|
||||
@param action - The promise to start the spinner for or a promise-returning function.
|
||||
@param options - If a string is provided, it is treated as a shortcut for `options.text`.
|
||||
@returns The given promise.
|
||||
|
||||
@example
|
||||
```
|
||||
import {oraPromise} from 'ora';
|
||||
|
||||
await oraPromise(somePromise);
|
||||
```
|
||||
*/
|
||||
export function oraPromise<T>(
|
||||
action: PromiseLike<T> | ((spinner: Ora) => PromiseLike<T>),
|
||||
options?: string | PromiseOptions<T>
|
||||
): Promise<T>;
|
||||
|
||||
export {default as spinners} from 'cli-spinners';
|
424
node_modules/ora/index.js
generated
vendored
Normal file
424
node_modules/ora/index.js
generated
vendored
Normal file
@@ -0,0 +1,424 @@
|
||||
import process from 'node:process';
|
||||
import chalk from 'chalk';
|
||||
import cliCursor from 'cli-cursor';
|
||||
import cliSpinners from 'cli-spinners';
|
||||
import logSymbols from 'log-symbols';
|
||||
import stripAnsi from 'strip-ansi';
|
||||
import stringWidth from 'string-width';
|
||||
import isInteractive from 'is-interactive';
|
||||
import isUnicodeSupported from 'is-unicode-supported';
|
||||
import stdinDiscarder from 'stdin-discarder';
|
||||
|
||||
class Ora {
|
||||
#linesToClear = 0;
|
||||
#isDiscardingStdin = false;
|
||||
#lineCount = 0;
|
||||
#frameIndex = -1;
|
||||
#lastSpinnerFrameTime = 0;
|
||||
#options;
|
||||
#spinner;
|
||||
#stream;
|
||||
#id;
|
||||
#initialInterval;
|
||||
#isEnabled;
|
||||
#isSilent;
|
||||
#indent;
|
||||
#text;
|
||||
#prefixText;
|
||||
#suffixText;
|
||||
color;
|
||||
|
||||
constructor(options) {
|
||||
if (typeof options === 'string') {
|
||||
options = {
|
||||
text: options,
|
||||
};
|
||||
}
|
||||
|
||||
this.#options = {
|
||||
color: 'cyan',
|
||||
stream: process.stderr,
|
||||
discardStdin: true,
|
||||
hideCursor: true,
|
||||
...options,
|
||||
};
|
||||
|
||||
// Public
|
||||
this.color = this.#options.color;
|
||||
|
||||
// It's important that these use the public setters.
|
||||
this.spinner = this.#options.spinner;
|
||||
|
||||
this.#initialInterval = this.#options.interval;
|
||||
this.#stream = this.#options.stream;
|
||||
this.#isEnabled = typeof this.#options.isEnabled === 'boolean' ? this.#options.isEnabled : isInteractive({stream: this.#stream});
|
||||
this.#isSilent = typeof this.#options.isSilent === 'boolean' ? this.#options.isSilent : false;
|
||||
|
||||
// Set *after* `this.#stream`.
|
||||
// It's important that these use the public setters.
|
||||
this.text = this.#options.text;
|
||||
this.prefixText = this.#options.prefixText;
|
||||
this.suffixText = this.#options.suffixText;
|
||||
this.indent = this.#options.indent;
|
||||
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
this._stream = this.#stream;
|
||||
this._isEnabled = this.#isEnabled;
|
||||
|
||||
Object.defineProperty(this, '_linesToClear', {
|
||||
get() {
|
||||
return this.#linesToClear;
|
||||
},
|
||||
set(newValue) {
|
||||
this.#linesToClear = newValue;
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(this, '_frameIndex', {
|
||||
get() {
|
||||
return this.#frameIndex;
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(this, '_lineCount', {
|
||||
get() {
|
||||
return this.#lineCount;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
get indent() {
|
||||
return this.#indent;
|
||||
}
|
||||
|
||||
set indent(indent = 0) {
|
||||
if (!(indent >= 0 && Number.isInteger(indent))) {
|
||||
throw new Error('The `indent` option must be an integer from 0 and up');
|
||||
}
|
||||
|
||||
this.#indent = indent;
|
||||
this.#updateLineCount();
|
||||
}
|
||||
|
||||
get interval() {
|
||||
return this.#initialInterval ?? this.#spinner.interval ?? 100;
|
||||
}
|
||||
|
||||
get spinner() {
|
||||
return this.#spinner;
|
||||
}
|
||||
|
||||
set spinner(spinner) {
|
||||
this.#frameIndex = -1;
|
||||
this.#initialInterval = undefined;
|
||||
|
||||
if (typeof spinner === 'object') {
|
||||
if (spinner.frames === undefined) {
|
||||
throw new Error('The given spinner must have a `frames` property');
|
||||
}
|
||||
|
||||
this.#spinner = spinner;
|
||||
} else if (!isUnicodeSupported()) {
|
||||
this.#spinner = cliSpinners.line;
|
||||
} else if (spinner === undefined) {
|
||||
// Set default spinner
|
||||
this.#spinner = cliSpinners.dots;
|
||||
} else if (spinner !== 'default' && cliSpinners[spinner]) {
|
||||
this.#spinner = cliSpinners[spinner];
|
||||
} else {
|
||||
throw new Error(`There is no built-in spinner named '${spinner}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`);
|
||||
}
|
||||
}
|
||||
|
||||
get text() {
|
||||
return this.#text;
|
||||
}
|
||||
|
||||
set text(value = '') {
|
||||
this.#text = value;
|
||||
this.#updateLineCount();
|
||||
}
|
||||
|
||||
get prefixText() {
|
||||
return this.#prefixText;
|
||||
}
|
||||
|
||||
set prefixText(value = '') {
|
||||
this.#prefixText = value;
|
||||
this.#updateLineCount();
|
||||
}
|
||||
|
||||
get suffixText() {
|
||||
return this.#suffixText;
|
||||
}
|
||||
|
||||
set suffixText(value = '') {
|
||||
this.#suffixText = value;
|
||||
this.#updateLineCount();
|
||||
}
|
||||
|
||||
get isSpinning() {
|
||||
return this.#id !== undefined;
|
||||
}
|
||||
|
||||
#getFullPrefixText(prefixText = this.#prefixText, postfix = ' ') {
|
||||
if (typeof prefixText === 'string' && prefixText !== '') {
|
||||
return prefixText + postfix;
|
||||
}
|
||||
|
||||
if (typeof prefixText === 'function') {
|
||||
return prefixText() + postfix;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
#getFullSuffixText(suffixText = this.#suffixText, prefix = ' ') {
|
||||
if (typeof suffixText === 'string' && suffixText !== '') {
|
||||
return prefix + suffixText;
|
||||
}
|
||||
|
||||
if (typeof suffixText === 'function') {
|
||||
return prefix + suffixText();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
#updateLineCount() {
|
||||
const columns = this.#stream.columns ?? 80;
|
||||
const fullPrefixText = this.#getFullPrefixText(this.#prefixText, '-');
|
||||
const fullSuffixText = this.#getFullSuffixText(this.#suffixText, '-');
|
||||
const fullText = ' '.repeat(this.#indent) + fullPrefixText + '--' + this.#text + '--' + fullSuffixText;
|
||||
|
||||
this.#lineCount = 0;
|
||||
for (const line of stripAnsi(fullText).split('\n')) {
|
||||
this.#lineCount += Math.max(1, Math.ceil(stringWidth(line, {countAnsiEscapeCodes: true}) / columns));
|
||||
}
|
||||
}
|
||||
|
||||
get isEnabled() {
|
||||
return this.#isEnabled && !this.#isSilent;
|
||||
}
|
||||
|
||||
set isEnabled(value) {
|
||||
if (typeof value !== 'boolean') {
|
||||
throw new TypeError('The `isEnabled` option must be a boolean');
|
||||
}
|
||||
|
||||
this.#isEnabled = value;
|
||||
}
|
||||
|
||||
get isSilent() {
|
||||
return this.#isSilent;
|
||||
}
|
||||
|
||||
set isSilent(value) {
|
||||
if (typeof value !== 'boolean') {
|
||||
throw new TypeError('The `isSilent` option must be a boolean');
|
||||
}
|
||||
|
||||
this.#isSilent = value;
|
||||
}
|
||||
|
||||
frame() {
|
||||
// Ensure we only update the spinner frame at the wanted interval,
|
||||
// even if the render method is called more often.
|
||||
const now = Date.now();
|
||||
if (this.#frameIndex === -1 || now - this.#lastSpinnerFrameTime >= this.interval) {
|
||||
this.#frameIndex = ++this.#frameIndex % this.#spinner.frames.length;
|
||||
this.#lastSpinnerFrameTime = now;
|
||||
}
|
||||
|
||||
const {frames} = this.#spinner;
|
||||
let frame = frames[this.#frameIndex];
|
||||
|
||||
if (this.color) {
|
||||
frame = chalk[this.color](frame);
|
||||
}
|
||||
|
||||
const fullPrefixText = (typeof this.#prefixText === 'string' && this.#prefixText !== '') ? this.#prefixText + ' ' : '';
|
||||
const fullText = typeof this.text === 'string' ? ' ' + this.text : '';
|
||||
const fullSuffixText = (typeof this.#suffixText === 'string' && this.#suffixText !== '') ? ' ' + this.#suffixText : '';
|
||||
|
||||
return fullPrefixText + frame + fullText + fullSuffixText;
|
||||
}
|
||||
|
||||
clear() {
|
||||
if (!this.#isEnabled || !this.#stream.isTTY) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this.#stream.cursorTo(0);
|
||||
|
||||
for (let index = 0; index < this.#linesToClear; index++) {
|
||||
if (index > 0) {
|
||||
this.#stream.moveCursor(0, -1);
|
||||
}
|
||||
|
||||
this.#stream.clearLine(1);
|
||||
}
|
||||
|
||||
if (this.#indent || this.lastIndent !== this.#indent) {
|
||||
this.#stream.cursorTo(this.#indent);
|
||||
}
|
||||
|
||||
this.lastIndent = this.#indent;
|
||||
this.#linesToClear = 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.#isSilent) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this.clear();
|
||||
this.#stream.write(this.frame());
|
||||
this.#linesToClear = this.#lineCount;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
start(text) {
|
||||
if (text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
if (this.#isSilent) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (!this.#isEnabled) {
|
||||
if (this.text) {
|
||||
this.#stream.write(`- ${this.text}\n`);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
if (this.isSpinning) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (this.#options.hideCursor) {
|
||||
cliCursor.hide(this.#stream);
|
||||
}
|
||||
|
||||
if (this.#options.discardStdin && process.stdin.isTTY) {
|
||||
this.#isDiscardingStdin = true;
|
||||
stdinDiscarder.start();
|
||||
}
|
||||
|
||||
this.render();
|
||||
this.#id = setInterval(this.render.bind(this), this.interval);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (!this.#isEnabled) {
|
||||
return this;
|
||||
}
|
||||
|
||||
clearInterval(this.#id);
|
||||
this.#id = undefined;
|
||||
this.#frameIndex = 0;
|
||||
this.clear();
|
||||
if (this.#options.hideCursor) {
|
||||
cliCursor.show(this.#stream);
|
||||
}
|
||||
|
||||
if (this.#options.discardStdin && process.stdin.isTTY && this.#isDiscardingStdin) {
|
||||
stdinDiscarder.stop();
|
||||
this.#isDiscardingStdin = false;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
succeed(text) {
|
||||
return this.stopAndPersist({symbol: logSymbols.success, text});
|
||||
}
|
||||
|
||||
fail(text) {
|
||||
return this.stopAndPersist({symbol: logSymbols.error, text});
|
||||
}
|
||||
|
||||
warn(text) {
|
||||
return this.stopAndPersist({symbol: logSymbols.warning, text});
|
||||
}
|
||||
|
||||
info(text) {
|
||||
return this.stopAndPersist({symbol: logSymbols.info, text});
|
||||
}
|
||||
|
||||
stopAndPersist(options = {}) {
|
||||
if (this.#isSilent) {
|
||||
return this;
|
||||
}
|
||||
|
||||
const prefixText = options.prefixText ?? this.#prefixText;
|
||||
const fullPrefixText = this.#getFullPrefixText(prefixText, ' ');
|
||||
|
||||
const symbolText = options.symbol ?? ' ';
|
||||
|
||||
const text = options.text ?? this.text;
|
||||
const separatorText = symbolText ? ' ' : '';
|
||||
const fullText = (typeof text === 'string') ? separatorText + text : '';
|
||||
|
||||
const suffixText = options.suffixText ?? this.#suffixText;
|
||||
const fullSuffixText = this.#getFullSuffixText(suffixText, ' ');
|
||||
|
||||
const textToWrite = fullPrefixText + symbolText + fullText + fullSuffixText + '\n';
|
||||
|
||||
this.stop();
|
||||
this.#stream.write(textToWrite);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export default function ora(options) {
|
||||
return new Ora(options);
|
||||
}
|
||||
|
||||
export async function oraPromise(action, options) {
|
||||
const actionIsFunction = typeof action === 'function';
|
||||
const actionIsPromise = typeof action.then === 'function';
|
||||
|
||||
if (!actionIsFunction && !actionIsPromise) {
|
||||
throw new TypeError('Parameter `action` must be a Function or a Promise');
|
||||
}
|
||||
|
||||
const {successText, failText} = typeof options === 'object'
|
||||
? options
|
||||
: {successText: undefined, failText: undefined};
|
||||
|
||||
const spinner = ora(options).start();
|
||||
|
||||
try {
|
||||
const promise = actionIsFunction ? action(spinner) : action;
|
||||
const result = await promise;
|
||||
|
||||
spinner.succeed(
|
||||
successText === undefined
|
||||
? undefined
|
||||
: (typeof successText === 'string' ? successText : successText(result)),
|
||||
);
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
spinner.fail(
|
||||
failText === undefined
|
||||
? undefined
|
||||
: (typeof failText === 'string' ? failText : failText(error)),
|
||||
);
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export {default as spinners} from 'cli-spinners';
|
9
node_modules/ora/license
generated
vendored
Normal file
9
node_modules/ora/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
64
node_modules/ora/package.json
generated
vendored
Normal file
64
node_modules/ora/package.json
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"name": "ora",
|
||||
"version": "8.2.0",
|
||||
"description": "Elegant terminal spinner",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/ora",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"cli",
|
||||
"spinner",
|
||||
"spinners",
|
||||
"terminal",
|
||||
"term",
|
||||
"console",
|
||||
"ascii",
|
||||
"unicode",
|
||||
"loading",
|
||||
"indicator",
|
||||
"progress",
|
||||
"busy",
|
||||
"wait",
|
||||
"idle"
|
||||
],
|
||||
"dependencies": {
|
||||
"chalk": "^5.3.0",
|
||||
"cli-cursor": "^5.0.0",
|
||||
"cli-spinners": "^2.9.2",
|
||||
"is-interactive": "^2.0.0",
|
||||
"is-unicode-supported": "^2.0.0",
|
||||
"log-symbols": "^6.0.0",
|
||||
"stdin-discarder": "^0.2.2",
|
||||
"string-width": "^7.2.0",
|
||||
"strip-ansi": "^7.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.5.0",
|
||||
"ava": "^5.3.1",
|
||||
"get-stream": "^9.0.1",
|
||||
"transform-tty": "^1.0.11",
|
||||
"tsd": "^0.31.1",
|
||||
"xo": "^0.59.3"
|
||||
}
|
||||
}
|
329
node_modules/ora/readme.md
generated
vendored
Normal file
329
node_modules/ora/readme.md
generated
vendored
Normal file
@@ -0,0 +1,329 @@
|
||||
# ora
|
||||
|
||||
> Elegant terminal spinner
|
||||
|
||||
<p align="center">
|
||||
<br>
|
||||
<img src="screenshot.svg" width="500">
|
||||
<br>
|
||||
</p>
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install ora
|
||||
```
|
||||
|
||||
*Check out [`yocto-spinner`](https://github.com/sindresorhus/yocto-spinner) for a smaller alternative.*
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import ora from 'ora';
|
||||
|
||||
const spinner = ora('Loading unicorns').start();
|
||||
|
||||
setTimeout(() => {
|
||||
spinner.color = 'yellow';
|
||||
spinner.text = 'Loading rainbows';
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### ora(text)
|
||||
### ora(options)
|
||||
|
||||
If a string is provided, it is treated as a shortcut for [`options.text`](#text).
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### text
|
||||
|
||||
Type: `string`
|
||||
|
||||
The text to display next to the spinner.
|
||||
|
||||
##### prefixText
|
||||
|
||||
Type: `string | () => string`
|
||||
|
||||
Text or a function that returns text to display before the spinner. No prefix text will be displayed if set to an empty string.
|
||||
|
||||
##### suffixText
|
||||
|
||||
Type: `string | () => string`
|
||||
|
||||
Text or a function that returns text to display after the spinner text. No suffix text will be displayed if set to an empty string.
|
||||
|
||||
##### spinner
|
||||
|
||||
Type: `string | object`\
|
||||
Default: `'dots'` <img src="screenshot-spinner.gif" width="14">
|
||||
|
||||
The name of one of the [provided spinners](#spinners). See `example.js` in this repo if you want to test out different spinners. On Windows (except for Windows Terminal), it will always use the `line` spinner as the Windows command-line doesn't have proper Unicode support.
|
||||
|
||||
Or an object like:
|
||||
|
||||
```js
|
||||
{
|
||||
frames: ['-', '+', '-'],
|
||||
interval: 80 // Optional
|
||||
}
|
||||
```
|
||||
|
||||
##### color
|
||||
|
||||
Type: `string | boolean`\
|
||||
Default: `'cyan'`\
|
||||
Values: `'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' | boolean`
|
||||
|
||||
The color of the spinner.
|
||||
|
||||
##### hideCursor
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Set to `false` to stop Ora from hiding the cursor.
|
||||
|
||||
##### indent
|
||||
|
||||
Type: `number`\
|
||||
Default: `0`
|
||||
|
||||
Indent the spinner with the given number of spaces.
|
||||
|
||||
##### interval
|
||||
|
||||
Type: `number`\
|
||||
Default: Provided by the spinner or `100`
|
||||
|
||||
Interval between each frame.
|
||||
|
||||
Spinners provide their own recommended interval, so you don't really need to specify this.
|
||||
|
||||
##### stream
|
||||
|
||||
Type: `stream.Writable`\
|
||||
Default: `process.stderr`
|
||||
|
||||
Stream to write the output.
|
||||
|
||||
You could for example set this to `process.stdout` instead.
|
||||
|
||||
##### isEnabled
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Force enable/disable the spinner. If not specified, the spinner will be enabled if the `stream` is being run inside a TTY context (not spawned or piped) and/or not in a CI environment.
|
||||
|
||||
Note that `{isEnabled: false}` doesn't mean it won't output anything. It just means it won't output the spinner, colors, and other ansi escape codes. It will still log text.
|
||||
|
||||
##### isSilent
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Disable the spinner and all log text. All output is suppressed and `isEnabled` will be considered `false`.
|
||||
|
||||
##### discardStdin
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Discard stdin input (except Ctrl+C) while running if it's TTY. This prevents the spinner from twitching on input, outputting broken lines on <kbd>Enter</kbd> key presses, and prevents buffering of input while the spinner is running.
|
||||
|
||||
This has no effect on Windows as there is no good way to implement discarding stdin properly there.
|
||||
|
||||
### Instance
|
||||
|
||||
#### .text <sup>get/set</sup>
|
||||
|
||||
Change the text displayed after the spinner.
|
||||
|
||||
#### .prefixText <sup>get/set</sup>
|
||||
|
||||
Change the text before the spinner.
|
||||
|
||||
No prefix text will be displayed if set to an empty string.
|
||||
|
||||
#### .suffixText <sup>get/set</sup>
|
||||
|
||||
Change the text after the spinner text.
|
||||
|
||||
No suffix text will be displayed if set to an empty string.
|
||||
|
||||
#### .color <sup>get/set</sup>
|
||||
|
||||
Change the spinner color.
|
||||
|
||||
#### .spinner <sup>get/set</sup>
|
||||
|
||||
Change the spinner.
|
||||
|
||||
#### .indent <sup>get/set</sup>
|
||||
|
||||
Change the spinner indent.
|
||||
|
||||
#### .isSpinning <sup>get</sup>
|
||||
|
||||
A boolean indicating whether the instance is currently spinning.
|
||||
|
||||
#### .interval <sup>get</sup>
|
||||
|
||||
The interval between each frame.
|
||||
|
||||
The interval is decided by the chosen spinner.
|
||||
|
||||
#### .start(text?)
|
||||
|
||||
Start the spinner. Returns the instance. Set the current text if `text` is provided.
|
||||
|
||||
#### .stop()
|
||||
|
||||
Stop and clear the spinner. Returns the instance.
|
||||
|
||||
#### .succeed(text?)
|
||||
|
||||
Stop the spinner, change it to a green `✔` and persist the current text, or `text` if provided. Returns the instance. See the GIF below.
|
||||
|
||||
#### .fail(text?)
|
||||
|
||||
Stop the spinner, change it to a red `✖` and persist the current text, or `text` if provided. Returns the instance. See the GIF below.
|
||||
|
||||
#### .warn(text?)
|
||||
|
||||
Stop the spinner, change it to a yellow `⚠` and persist the current text, or `text` if provided. Returns the instance.
|
||||
|
||||
#### .info(text?)
|
||||
|
||||
Stop the spinner, change it to a blue `ℹ` and persist the current text, or `text` if provided. Returns the instance.
|
||||
|
||||
#### .stopAndPersist(options?)
|
||||
|
||||
Stop the spinner and change the symbol or text. Returns the instance. See the GIF below.
|
||||
|
||||
##### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
###### symbol
|
||||
|
||||
Type: `string`\
|
||||
Default: `' '`
|
||||
|
||||
Symbol to replace the spinner with.
|
||||
|
||||
###### text
|
||||
|
||||
Type: `string`\
|
||||
Default: Current `'text'`
|
||||
|
||||
Text to be persisted after the symbol.
|
||||
|
||||
###### prefixText
|
||||
|
||||
Type: `string | () => string`\
|
||||
Default: Current `prefixText`
|
||||
|
||||
Text or a function that returns text to be persisted before the symbol. No prefix text will be displayed if set to an empty string.
|
||||
|
||||
###### suffixText
|
||||
|
||||
Type: `string | () => string`\
|
||||
Default: Current `suffixText`
|
||||
|
||||
Text or a function that returns text to be persisted after the text after the symbol. No suffix text will be displayed if set to an empty string.
|
||||
|
||||
<img src="screenshot-2.gif" width="480">
|
||||
|
||||
#### .clear()
|
||||
|
||||
Clear the spinner. Returns the instance.
|
||||
|
||||
#### .render()
|
||||
|
||||
Manually render a new frame. Returns the instance.
|
||||
|
||||
#### .frame()
|
||||
|
||||
Get a new frame.
|
||||
|
||||
### oraPromise(action, text)
|
||||
### oraPromise(action, options)
|
||||
|
||||
Starts a spinner for a promise or promise-returning function. The spinner is stopped with `.succeed()` if the promise fulfills or with `.fail()` if it rejects. Returns the promise.
|
||||
|
||||
```js
|
||||
import {oraPromise} from 'ora';
|
||||
|
||||
await oraPromise(somePromise);
|
||||
```
|
||||
|
||||
#### action
|
||||
|
||||
Type: `Promise | ((spinner: ora.Ora) => Promise)`
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
All of the [options](#options) plus the following:
|
||||
|
||||
##### successText
|
||||
|
||||
Type: `string | ((result: T) => string) | undefined`
|
||||
|
||||
The new text of the spinner when the promise is resolved.
|
||||
|
||||
Keeps the existing text if `undefined`.
|
||||
|
||||
##### failText
|
||||
|
||||
Type: `string | ((error: Error) => string) | undefined`
|
||||
|
||||
The new text of the spinner when the promise is rejected.
|
||||
|
||||
Keeps the existing text if `undefined`.
|
||||
|
||||
### spinners
|
||||
|
||||
Type: `Record<string, Spinner>`
|
||||
|
||||
All [provided spinners](https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json).
|
||||
|
||||
## FAQ
|
||||
|
||||
### How do I change the color of the text?
|
||||
|
||||
Use [`chalk`](https://github.com/chalk/chalk) or [`yoctocolors`](https://github.com/sindresorhus/yoctocolors):
|
||||
|
||||
```js
|
||||
import ora from 'ora';
|
||||
import chalk from 'chalk';
|
||||
|
||||
const spinner = ora(`Loading ${chalk.red('unicorns')}`).start();
|
||||
```
|
||||
|
||||
### Why does the spinner freeze?
|
||||
|
||||
JavaScript is single-threaded, so any synchronous operations will block the spinner's animation. To avoid this, prefer using asynchronous operations.
|
||||
|
||||
## Related
|
||||
|
||||
- [yocto-spinner](https://github.com/sindresorhus/yocto-spinner) - Tiny terminal spinner
|
||||
- [cli-spinners](https://github.com/sindresorhus/cli-spinners) - Spinners for use in the terminal
|
||||
|
||||
**Ports**
|
||||
|
||||
- [CLISpinner](https://github.com/kiliankoe/CLISpinner) - Terminal spinner library for Swift
|
||||
- [halo](https://github.com/ManrajGrover/halo) - Python port
|
||||
- [spinners](https://github.com/FGRibreau/spinners) - Terminal spinners for Rust
|
||||
- [marquee-ora](https://github.com/joeycozza/marquee-ora) - Scrolling marquee spinner for Ora
|
||||
- [briandowns/spinner](https://github.com/briandowns/spinner) - Terminal spinner/progress indicator for Go
|
||||
- [tj/go-spin](https://github.com/tj/go-spin) - Terminal spinner package for Go
|
||||
- [observablehq.com/@victordidenko/ora](https://observablehq.com/@victordidenko/ora) - Ora port to Observable notebooks
|
||||
- [kia](https://github.com/HarryPeach/kia) - Simple terminal spinners for Deno 🦕
|
Reference in New Issue
Block a user