This commit is contained in:
Lukáš Kaňka
2023-08-15 18:35:50 +02:00
commit ea3e372146
10019 changed files with 2548539 additions and 0 deletions

View File

@ -0,0 +1,2 @@
export declare const CLEAR_LINE_REGEX = "(?:\\u001b|\\u009b)\\[[\\=><~/#&.:=?%@~_-]*[0-9]*[\\a-ln-tqyz=><~/#&.:=?%@~_-]+";
export declare const BELL_REGEX: RegExp;

View File

@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BELL_REGEX = exports.CLEAR_LINE_REGEX = void 0;
/* eslint-disable no-control-regex */
exports.CLEAR_LINE_REGEX = '(?:\\u001b|\\u009b)\\[[\\=><~/#&.:=?%@~_-]*[0-9]*[\\a-ln-tqyz=><~/#&.:=?%@~_-]+';
exports.BELL_REGEX = /\u0007/;

View File

@ -0,0 +1,9 @@
/** Type of listr internal events. */
export declare enum ListrEventType {
TITLE = "TITLE",
STATE = "STATE",
ENABLED = "ENABLED",
SUBTASK = "SUBTASK",
DATA = "DATA",
MESSAGE = "MESSAGE"
}

View File

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListrEventType = void 0;
/** Type of listr internal events. */
var ListrEventType;
(function (ListrEventType) {
ListrEventType["TITLE"] = "TITLE";
ListrEventType["STATE"] = "STATE";
ListrEventType["ENABLED"] = "ENABLED";
ListrEventType["SUBTASK"] = "SUBTASK";
ListrEventType["DATA"] = "DATA";
ListrEventType["MESSAGE"] = "MESSAGE";
})(ListrEventType = exports.ListrEventType || (exports.ListrEventType = {}));

View File

@ -0,0 +1,2 @@
export * from './state.constants';
export * from './event.constants';

View File

@ -0,0 +1,14 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./state.constants"), exports);
__exportStar(require("./event.constants"), exports);

View File

@ -0,0 +1,10 @@
/** Available task states. */
export declare enum ListrTaskState {
PENDING = "PENDING",
COMPLETED = "COMPLETED",
FAILED = "FAILED",
SKIPPED = "SKIPPED",
ROLLING_BACK = "ROLLING_BACK",
ROLLED_BACK = "ROLLED_BACK",
RETRY = "RETRY"
}

View File

@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListrTaskState = void 0;
/** Available task states. */
var ListrTaskState;
(function (ListrTaskState) {
ListrTaskState["PENDING"] = "PENDING";
ListrTaskState["COMPLETED"] = "COMPLETED";
ListrTaskState["FAILED"] = "FAILED";
ListrTaskState["SKIPPED"] = "SKIPPED";
ListrTaskState["ROLLING_BACK"] = "ROLLING_BACK";
ListrTaskState["ROLLED_BACK"] = "ROLLED_BACK";
ListrTaskState["RETRY"] = "RETRY";
})(ListrTaskState = exports.ListrTaskState || (exports.ListrTaskState = {}));

9
CyLukTs/lukan/node_modules/listr2/dist/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,9 @@
export * from './listr';
export * from './manager';
export * from './constants/index';
export * from './interfaces/index';
export * from './utils/logger';
export * from './utils/logger.constants';
export * from './utils/prompt.interface';
export * from './utils/prompt';
export * from './utils/figures';

21
CyLukTs/lukan/node_modules/listr2/dist/index.js generated vendored Normal file
View File

@ -0,0 +1,21 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./listr"), exports);
__exportStar(require("./manager"), exports);
__exportStar(require("./constants/index"), exports);
__exportStar(require("./interfaces/index"), exports);
__exportStar(require("./utils/logger"), exports);
__exportStar(require("./utils/logger.constants"), exports);
__exportStar(require("./utils/prompt.interface"), exports);
__exportStar(require("./utils/prompt"), exports);
__exportStar(require("./utils/figures"), exports);

View File

@ -0,0 +1,4 @@
export * from './listr.interface';
export * from './listr-error.interface';
export * from './task.interface';
export * from './renderer.interface';

View File

@ -0,0 +1,16 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./listr.interface"), exports);
__exportStar(require("./listr-error.interface"), exports);
__exportStar(require("./task.interface"), exports);
__exportStar(require("./renderer.interface"), exports);

View File

@ -0,0 +1,29 @@
import { ListrRendererFactory } from './renderer.interface';
import { Task } from '../lib/task';
/** The internal error handling mechanism.. */
export declare class ListrError<Ctx extends Record<PropertyKey, any> = Record<PropertyKey, any>> extends Error {
error: Error;
type?: ListrErrorTypes;
ctx?: Ctx;
task?: Task<Ctx, ListrRendererFactory>;
constructor(error: Error, type?: ListrErrorTypes, ctx?: Ctx, task?: Task<Ctx, ListrRendererFactory>);
}
/**
* The actual error type that is collected and to help identify where the error is triggered from.
*/
export declare enum ListrErrorTypes {
/** Task has failed and will try to retry. */
WILL_RETRY = "WILL_RETRY",
/** Task has failed and will try to rollback. */
WILL_ROLLBACK = "WILL_ROLLBACK",
/** Task has failed, ran the rollback action but the rollback action itself has failed. */
HAS_FAILED_TO_ROLLBACK = "HAS_FAILED_TO_ROLLBACK",
/** Task has failed. */
HAS_FAILED = "HAS_FAILED",
/** Task has failed, but exitOnError is set to false, so will ignore this error. */
HAS_FAILED_WITHOUT_ERROR = "HAS_FAILED_WITHOUT_ERROR"
}
/** The internal error handling mechanism for prompts only. */
export declare class PromptError extends Error {
constructor(message: string);
}

View File

@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PromptError = exports.ListrErrorTypes = exports.ListrError = void 0;
/** The internal error handling mechanism.. */
class ListrError extends Error {
constructor(error, type, ctx, task) {
super(error.message);
this.error = error;
this.type = type;
this.ctx = ctx;
this.task = task;
this.stack = error === null || error === void 0 ? void 0 : error.stack;
this.name = 'ListrError';
}
}
exports.ListrError = ListrError;
/**
* The actual error type that is collected and to help identify where the error is triggered from.
*/
var ListrErrorTypes;
(function (ListrErrorTypes) {
/** Task has failed and will try to retry. */
ListrErrorTypes["WILL_RETRY"] = "WILL_RETRY";
/** Task has failed and will try to rollback. */
ListrErrorTypes["WILL_ROLLBACK"] = "WILL_ROLLBACK";
/** Task has failed, ran the rollback action but the rollback action itself has failed. */
ListrErrorTypes["HAS_FAILED_TO_ROLLBACK"] = "HAS_FAILED_TO_ROLLBACK";
/** Task has failed. */
ListrErrorTypes["HAS_FAILED"] = "HAS_FAILED";
/** Task has failed, but exitOnError is set to false, so will ignore this error. */
ListrErrorTypes["HAS_FAILED_WITHOUT_ERROR"] = "HAS_FAILED_WITHOUT_ERROR";
})(ListrErrorTypes = exports.ListrErrorTypes || (exports.ListrErrorTypes = {}));
/** The internal error handling mechanism for prompts only. */
class PromptError extends Error {
constructor(message) {
super(message);
this.name = 'PromptError';
}
}
exports.PromptError = PromptError;

View File

@ -0,0 +1,170 @@
/// <reference types="node" />
import type * as Enquirer from 'enquirer';
import type { Observable } from 'rxjs';
import { Readable } from 'stream';
import { ListrDefaultNonTTYRendererOptions, ListrDefaultRendererOptions, ListrDefaultRendererValue, ListrFallbackRendererValue, ListrGetRendererTaskOptions, ListrRendererFactory, ListrRendererValue } from './renderer.interface';
import { ListrEventType } from '../constants/event.constants';
import { Task } from '../lib/task';
import { TaskWrapper } from '../lib/task-wrapper';
import { Listr } from '../listr';
/** Listr Default Context */
export declare type ListrContext = any | undefined;
/**
* ListrTask.
*
* Defines the task, conditions and options to run a specific task in the listr.
*/
export interface ListrTask<Ctx = ListrContext, Renderer extends ListrRendererFactory = any> {
/**
* Title of the task.
*
* Give this task a title if you want to track it by name in the current renderer.
*
* Tasks without a title will hide in the default renderer and are useful for running a background instance.
* On verbose renderer, state changes from these tasks will log as 'Task without a title.'
*/
title?: string;
/**
* The task itself.
*
* Task can be a sync or async function, an Observable, or a Stream.
* Task will be executed, if the certain criteria of the state are met and whenever the time for that specific task has come.
*/
task: (ctx: Ctx, task: TaskWrapper<Ctx, Renderer>) => void | ListrTaskResult<Ctx>;
/**
* Skip this task depending on the context.
*
* The function that has been passed in will be evaluated at the runtime when the task tries to initially run.
*/
skip?: boolean | string | ((ctx: Ctx) => boolean | string | Promise<boolean | string>);
/**
* Enable a task depending on the context.
*
* The function that has been passed in will be evaluated at the initial creation of the Listr class for rendering purposes,
* as well as re-evaluated when the time for that specific task has come.
*/
enabled?: boolean | ((ctx: Ctx) => boolean | Promise<boolean>);
/**
* Adds the given number of retry attempts to the task if the task fails.
*/
retry?: number;
/**
* Runs a specific event if the current task or any of the subtasks has failed.
*
* Mostly useful for rollback purposes for subtasks.
* But can also be useful whenever a task is failed and some measures have to be taken to ensure the state is not changed.
*/
rollback?: (ctx: Ctx, task: TaskWrapper<Ctx, Renderer>) => void | ListrTaskResult<Ctx>;
/**
* Set exit on the error option from task-level instead of setting it for all the subtasks.
*/
exitOnError?: boolean | ((ctx: Ctx) => boolean | Promise<boolean>);
/**
* Per task options, that depends on the selected renderer.
*
* These options depend on the implementation of the selected renderer. If the selected renderer has no options it will
* be displayed as never.
*/
options?: ListrGetRendererTaskOptions<Renderer>;
}
/**
* Options to set the behavior of this base task.
*/
export interface ListrOptions<Ctx = ListrContext> {
/**
* To inject a context through this options wrapper. Context can also be defined in run time.
*
* @default {}
*/
ctx?: Ctx;
/**
* Concurrency sets how many tasks will be run at the same time in parallel.
*
* @default false > Default is to run everything synchronously.
*
* `true` will set it to `Infinity`, `false` will set it to synchronous.
*
* If you pass in a `number` it will limit it to that number.
*/
concurrent?: boolean | number;
/**
* Determine the default behavior of exiting on errors.
*
* @default true > exit on any error coming from the tasks.
*/
exitOnError?: boolean;
/**
* Determine the behavior of exiting after rollback actions.
*
* This is independent of exitOnError, since failure of a rollback can be a more critical operation comparing to
* failing a single task.
*
* @default true > exit after rolling back tasks
*/
exitAfterRollback?: boolean;
/**
* By default, Listr2 will track SIGINIT signal to update the renderer one last time before completely failing.
*
* @default true
*/
registerSignalListeners?: boolean;
/**
* Determine the certain condition required to use the non-TTY renderer.
*
* @default null > handled internally
*/
rendererFallback?: boolean | (() => boolean);
/**
* Determine the certain condition required to use the silent renderer.
*
* @default null > handled internally
*/
rendererSilent?: boolean | (() => boolean);
/**
* Disabling the color, useful for tests and such.
*
* @default false
*/
disableColor?: boolean;
/**
* Inject data directly to TaskWrapper.
*/
injectWrapper?: {
enquirer?: Enquirer<object>;
};
}
/**
* Task can be set of sync or async function, an Observable or a stream.
*/
export declare type ListrTaskResult<Ctx> = string | Promise<any> | Listr<Ctx, ListrRendererValue, any> | Readable | NodeJS.ReadableStream | Observable<any>;
/**
* Parent class options.
*
* Parent class has more options where you can also select the and set renderer and non-tty renderer.
*
* Any subtasks will respect those options so they will be stripped of that properties.
*/
export declare type ListrBaseClassOptions<Ctx = ListrContext, Renderer extends ListrRendererValue = ListrDefaultRendererValue, FallbackRenderer extends ListrRendererValue = ListrFallbackRendererValue> = ListrOptions<Ctx> & ListrDefaultRendererOptions<Renderer> & ListrDefaultNonTTYRendererOptions<FallbackRenderer>;
/**
* Sub class options.
*
* Subtasks has reduced set options where the missing ones are explicitly set by the base class.
*/
export declare type ListrSubClassOptions<Ctx = ListrContext, Renderer extends ListrRendererValue = ListrDefaultRendererValue> = ListrOptions<Ctx> & Omit<ListrDefaultRendererOptions<Renderer>, 'renderer'>;
/** The internal communication event. */
export declare type ListrEvent = {
type: Exclude<ListrEventType, 'MESSAGE' | 'DATA'>;
data?: string | boolean;
} | {
type: ListrEventType.DATA;
data: string;
} | {
type: ListrEventType.MESSAGE;
data: Task<any, any>['message'];
};
/**
* Used to match event.type to ListrEvent permutations
*/
export declare type ListrEventFromType<T extends ListrEventType, E = ListrEvent> = E extends {
type: infer U;
} ? T extends U ? E : never : never;

View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -0,0 +1,92 @@
import { Subject } from 'rxjs';
import { Task } from '../lib/task';
import { DefaultRenderer } from '../renderer/default.renderer';
import { SilentRenderer } from '../renderer/silent.renderer';
import { SimpleRenderer } from '../renderer/simple.renderer';
import { VerboseRenderer } from '../renderer/verbose.renderer';
/** The default renderer value used in Listr2 applications */
export declare type ListrDefaultRendererValue = 'default';
/** Type of default renderer */
export declare type ListrDefaultRenderer = typeof DefaultRenderer;
/** Name of default fallback renderer */
export declare type ListrFallbackRendererValue = 'verbose';
/** Type of default fallback renderer */
export declare type ListrFallbackRenderer = typeof VerboseRenderer;
/** Silent rendere for internal usage */
export declare type ListrSilentRendererValue = 'silent';
/** Typeof silent renderer */
export declare type ListrSilentRenderer = typeof SilentRenderer;
/** Simple renderer that simplifies things */
export declare type ListrSimpleRendererValue = 'simple';
/** Typeof simple renderer */
export declare type ListrSimpleRenderer = typeof SimpleRenderer;
/**
* Listr2 can process either the integrated renderers as string aliases,
* or utilize a compatible style renderer that extends the ListrRenderer abstract class.
*/
export declare type ListrRendererValue = ListrSilentRendererValue | ListrDefaultRendererValue | ListrSimpleRendererValue | ListrFallbackRendererValue | ListrRendererFactory;
/**
* Returns the class type from friendly names of the renderers.
*/
export declare type ListrGetRendererClassFromValue<T extends ListrRendererValue> = T extends ListrDefaultRendererValue ? ListrDefaultRenderer : T extends ListrSimpleRendererValue ? ListrSimpleRenderer : T extends ListrFallbackRendererValue ? ListrFallbackRenderer : T extends ListrSilentRenderer ? ListrSilentRenderer : T extends ListrRendererFactory ? T : never;
/**
* Returns the friendly names from the type of renderer classes.
*/
export declare type ListrGetRendererValueFromClass<T extends ListrRendererFactory> = T extends DefaultRenderer ? ListrDefaultRendererValue : T extends SimpleRenderer ? ListrSimpleRendererValue : T extends VerboseRenderer ? ListrFallbackRendererValue : T extends SilentRenderer ? ListrSilentRenderer : T extends ListrRendererFactory ? T : never;
/**
* Returns renderer global options depending on the renderer type.
*/
export declare type ListrGetRendererOptions<T extends ListrRendererValue> = T extends ListrDefaultRendererValue ? ListrDefaultRenderer['rendererOptions'] : T extends ListrSimpleRendererValue ? ListrSimpleRenderer['rendererOptions'] : T extends ListrFallbackRendererValue ? ListrFallbackRenderer['rendererOptions'] : T extends ListrSilentRenderer ? ListrSilentRenderer['rendererOptions'] : T extends ListrRendererFactory ? T['rendererOptions'] : never;
/**
* Returns renderer per task options depending on the renderer type.
*/
export declare type ListrGetRendererTaskOptions<T extends ListrRendererValue> = T extends ListrDefaultRendererValue ? ListrDefaultRenderer['rendererTaskOptions'] : T extends ListrSimpleRendererValue ? ListrSimpleRenderer : T extends ListrFallbackRendererValue ? ListrFallbackRenderer['rendererTaskOptions'] : T extends ListrSilentRenderer ? ListrSilentRenderer['rendererTaskOptions'] : T extends ListrRendererFactory ? T['rendererTaskOptions'] : never;
/** Select renderer as default renderer */
export interface ListrDefaultRendererOptions<T extends ListrRendererValue> {
/** the default renderer */
renderer?: T;
/** Renderer options depending on the current renderer */
rendererOptions?: ListrGetRendererOptions<T>;
}
/** Select a fallback renderer to fallback to in non-tty conditions */
export interface ListrDefaultNonTTYRendererOptions<T extends ListrRendererValue> {
/** the fallback renderer to fallback to on non-tty conditions */
nonTTYRenderer?: T;
/** Renderer options depending on the current renderer */
nonTTYRendererOptions?: ListrGetRendererOptions<T>;
}
/** Renderer options for the base class, including setup for selecting default and fallback renderers. */
export declare type ListrRendererOptions<Renderer extends ListrRendererValue, FallbackRenderer extends ListrRendererValue> = ListrDefaultRendererOptions<Renderer> & ListrDefaultNonTTYRendererOptions<FallbackRenderer>;
/** The bones of a listr renderer. */
export declare class ListrRenderer {
/** designate renderer global options that is specific to the current renderer */
static rendererOptions: Record<PropertyKey, any>;
/** designate renderer per task options that is specific to the current renderer */
static rendererTaskOptions: Record<PropertyKey, any>;
/** designate whether this renderer can work in non-tty environments */
static nonTTY: boolean;
/** A function to what to do on render */
render: () => void;
/** A function to what to do on end of the render */
end: (err?: Error) => void;
/** create a new renderer */
constructor(tasks: readonly Task<any, ListrRendererFactory>[], options: typeof ListrRenderer.rendererOptions, renderHook$?: Subject<void>);
}
/** Exported for javascript applications to extend the base renderer */
export declare class ListrBaseRenderer implements ListrRenderer {
static rendererOptions: Record<PropertyKey, any>;
static rendererTaskOptions: Record<PropertyKey, any>;
static nonTTY: boolean;
tasks: Task<any, typeof ListrBaseRenderer>[];
options: typeof ListrBaseRenderer.rendererOptions;
render: () => void;
end: (err?: Error) => void;
constructor(tasks: Task<any, typeof ListrBaseRenderer>[], options: typeof ListrBaseRenderer.rendererOptions);
}
/** A renderer factory from the current type */
export declare type ListrRendererFactory = typeof ListrRenderer;
/** Supported type of renderers for each type in the listr. */
export interface SupportedRenderer {
renderer: ListrRendererFactory;
nonTTY: boolean;
}

View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -0,0 +1,4 @@
import type { Task } from '../lib/task';
import type { TaskWrapper } from '../lib/task-wrapper';
export { Task as ListrTaskObject };
export { TaskWrapper as ListrTaskWrapper };

View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -0,0 +1,51 @@
/// <reference types="node" />
import { ListrError, ListrErrorTypes } from '../interfaces/listr-error.interface';
import { ListrBaseClassOptions, ListrSubClassOptions, ListrTask } from '../interfaces/listr.interface';
import { ListrRendererFactory } from '../interfaces/renderer.interface';
import { Task } from './task';
import { Listr } from '../listr';
import { PromptOptions } from '../utils/prompt.interface';
/**
* Extend the task to have more functionality while accesing from the outside.
*/
export declare class TaskWrapper<Ctx, Renderer extends ListrRendererFactory> {
task: Task<Ctx, ListrRendererFactory>;
errors: ListrError<Ctx>[];
private options;
constructor(task: Task<Ctx, ListrRendererFactory>, errors: ListrError<Ctx>[], options: ListrBaseClassOptions<Ctx, any, any>);
/** Change the title of the current task. */
set title(data: string);
/** Get the title of the current task. */
get title(): string;
/** Send a output to the output channel. */
set output(data: string);
/** Get the output from the output channel. */
get output(): string;
/** Create a new subtask with given renderer selection from the parent task. */
newListr<NewCtx = Ctx>(task: ListrTask<NewCtx, Renderer> | ListrTask<NewCtx, Renderer>[] | ((parent: Omit<this, 'skip' | 'enabled'>) => ListrTask<NewCtx, Renderer> | ListrTask<NewCtx, Renderer>[]), options?: ListrSubClassOptions<NewCtx, Renderer>): Listr<NewCtx, any, any>;
/** Report a error in process for error collection. */
report(error: Error, type: ListrErrorTypes): void;
/** Skip current task. */
skip(message?: string): void;
/** Get the number of retrying, else returns false */
isRetrying(): Task<Ctx, Renderer>['retry'];
/**
* Create a new Enquirer prompt using prompt options.
*
* Since process.stdout is controlled by Listr, this will passthrough all Enquirer data through internal stdout.
*/
prompt<T = any>(options: PromptOptions | PromptOptions<true>[]): Promise<T>;
/** Cancels the current prompt attach to this task. */
cancelPrompt(throwError?: boolean): void;
/**
* Pass stream of data to internal stdout.
*
* Since Listr2 takes control of process.stdout utilizing the default renderer, any data outputted to process.stdout
* will corupt its looks.
*
* This returns a fake stream to pass any stream inside Listr as task data.
*/
stdout(): NodeJS.WriteStream & NodeJS.WritableStream;
/** Run this task. */
run(ctx: Ctx): Promise<void>;
}

View File

@ -0,0 +1,101 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskWrapper = void 0;
const through = require("through");
const clearline_regex_constants_1 = require("../constants/clearline-regex.constants");
const state_constants_1 = require("../constants/state.constants");
const listr_error_interface_1 = require("../interfaces/listr-error.interface");
const listr_1 = require("../listr");
const general_1 = require("../utils/general");
const prompt_1 = require("../utils/prompt");
/**
* Extend the task to have more functionality while accesing from the outside.
*/
class TaskWrapper {
constructor(task, errors, options) {
this.task = task;
this.errors = errors;
this.options = options;
}
/** Change the title of the current task. */
set title(data) {
this.task.title$ = data;
}
/** Get the title of the current task. */
get title() {
return this.task.title;
}
/** Send a output to the output channel. */
set output(data) {
this.task.output$ = data;
}
/** Get the output from the output channel. */
get output() {
return this.task.output;
}
/** Create a new subtask with given renderer selection from the parent task. */
newListr(task, options) {
let tasks;
if (typeof task === 'function') {
tasks = task(this);
}
else {
tasks = task;
}
return new listr_1.Listr(tasks, options);
}
/** Report a error in process for error collection. */
report(error, type) {
var _a, _b, _c;
this.errors.push(new listr_error_interface_1.ListrError(error, type, (0, general_1.cloneObject)(this.task.listr.ctx), (0, general_1.cloneObject)(this.task)));
this.task.message$ = { error: (_c = (_a = error.message) !== null && _a !== void 0 ? _a : (_b = this.task) === null || _b === void 0 ? void 0 : _b.title) !== null && _c !== void 0 ? _c : 'Task with no title.' };
}
/** Skip current task. */
skip(message) {
var _a, _b;
this.task.state$ = state_constants_1.ListrTaskState.SKIPPED;
if (message) {
this.task.message$ = { skip: (_b = message !== null && message !== void 0 ? message : (_a = this.task) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : 'Task with no title.' };
}
}
/** Get the number of retrying, else returns false */
isRetrying() {
return this.task.isRetrying() ? this.task.retry : { count: 0 };
}
/**
* Create a new Enquirer prompt using prompt options.
*
* Since process.stdout is controlled by Listr, this will passthrough all Enquirer data through internal stdout.
*/
async prompt(options) {
var _a;
return prompt_1.createPrompt.bind(this)(options, { ...(_a = this.options) === null || _a === void 0 ? void 0 : _a.injectWrapper });
}
/** Cancels the current prompt attach to this task. */
cancelPrompt(throwError = false) {
return prompt_1.destroyPrompt.bind(this)(throwError);
}
/**
* Pass stream of data to internal stdout.
*
* Since Listr2 takes control of process.stdout utilizing the default renderer, any data outputted to process.stdout
* will corupt its looks.
*
* This returns a fake stream to pass any stream inside Listr as task data.
*/
stdout() {
return through((chunk) => {
chunk = chunk.toString();
chunk = chunk.replace(new RegExp(clearline_regex_constants_1.CLEAR_LINE_REGEX, 'gmi'), '');
chunk = chunk.replace(new RegExp(clearline_regex_constants_1.BELL_REGEX, 'gmi'), '');
if (chunk !== '') {
this.output = chunk;
}
});
}
/** Run this task. */
run(ctx) {
return this.task.run(ctx, this);
}
}
exports.TaskWrapper = TaskWrapper;

98
CyLukTs/lukan/node_modules/listr2/dist/lib/task.d.ts generated vendored Normal file
View File

@ -0,0 +1,98 @@
import { Subject } from 'rxjs';
import { TaskWrapper } from './task-wrapper';
import { ListrTaskState } from '../constants/state.constants';
import { PromptError } from '../interfaces/listr-error.interface';
import { ListrEvent, ListrOptions, ListrTask, ListrTaskResult } from '../interfaces/listr.interface';
import { ListrGetRendererOptions, ListrGetRendererTaskOptions, ListrRendererFactory } from '../interfaces/renderer.interface';
import { Listr } from '../listr';
import { PromptInstance } from '../utils/prompt.interface';
/**
* Create a task from the given set of variables and make it runnable.
*/
export declare class Task<Ctx, Renderer extends ListrRendererFactory> extends Subject<ListrEvent> {
listr: Listr<Ctx, any, any>;
tasks: ListrTask<Ctx, any>;
options: ListrOptions;
rendererOptions: ListrGetRendererOptions<Renderer>;
/** Unique id per task, randomly generated in the uuid v4 format */
id: string;
/** The current state of the task. */
state: string;
/** The task object itself, to further utilize it. */
task: (ctx: Ctx, task: TaskWrapper<Ctx, Renderer>) => void | ListrTaskResult<Ctx>;
/** Extend current task with multiple subtasks. */
subtasks: Task<Ctx, any>[];
/** Title of the task */
title?: string;
/** Untouched unchanged title of the task */
initialTitle?: string;
/** Output data from the task. */
output?: string;
/** Skip current task. */
skip: boolean | string | ((ctx: Ctx) => boolean | string | Promise<boolean | string>);
/** Current retry number of the task if retrying */
retry?: {
count: number;
withError?: any;
};
/**
* A channel for messages.
*
* This requires a separate channel for messages like error, skip or runtime messages to further utilize in the renderers.
*/
message: {
/** Run time of the task, if it has been successfully resolved. */
duration?: number;
/** Error message of the task, if it has been failed. */
error?: string;
/** Skip message of the task, if it has been skipped. */
skip?: string;
/** Rollback message of the task, if the rollback finishes */
rollback?: string;
/** Retry messages */
retry?: {
count: number;
withError?: any;
};
};
/** Per task options for the current renderer of the task. */
rendererTaskOptions: ListrGetRendererTaskOptions<Renderer>;
/** This will be triggered each time a new render should happen. */
renderHook$: Subject<void>;
prompt: undefined | PromptInstance | PromptError;
private enabled;
private enabledFn;
constructor(listr: Listr<Ctx, any, any>, tasks: ListrTask<Ctx, any>, options: ListrOptions, rendererOptions: ListrGetRendererOptions<Renderer>);
set state$(state: ListrTaskState);
set output$(data: string);
set message$(data: Task<Ctx, Renderer>['message']);
set title$(title: string);
/**
* A function to check whether this task should run at all via enable.
*/
check(ctx: Ctx): Promise<void>;
/** Returns whether this task has subtasks. */
hasSubtasks(): boolean;
/** Returns whether this task is in progress. */
isPending(): boolean;
/** Returns whether this task is skipped. */
isSkipped(): boolean;
/** Returns whether this task has been completed. */
isCompleted(): boolean;
/** Returns whether this task has been failed. */
hasFailed(): boolean;
/** Returns whether this task has an active rollback task going on. */
isRollingBack(): boolean;
/** Returns whether the rollback action was successful. */
hasRolledBack(): boolean;
/** Returns whether this task has an actively retrying task going on. */
isRetrying(): boolean;
/** Returns whether enabled function resolves to true. */
isEnabled(): boolean;
/** Returns whether this task actually has a title. */
hasTitle(): boolean;
/** Returns whether this task has a prompt inside. */
isPrompt(): boolean;
/** Run the current task. */
run(context: Ctx, wrapper: TaskWrapper<Ctx, Renderer>): Promise<void>;
}

281
CyLukTs/lukan/node_modules/listr2/dist/lib/task.js generated vendored Normal file
View File

@ -0,0 +1,281 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Task = void 0;
const rxjs_1 = require("rxjs");
const stream_1 = require("stream");
const event_constants_1 = require("../constants/event.constants");
const state_constants_1 = require("../constants/state.constants");
const listr_error_interface_1 = require("../interfaces/listr-error.interface");
const listr_1 = require("../listr");
const assert_1 = require("../utils/assert");
const renderer_1 = require("../utils/renderer");
const uuid_1 = require("../utils/uuid");
/**
* Create a task from the given set of variables and make it runnable.
*/
class Task extends rxjs_1.Subject {
constructor(listr, tasks, options, rendererOptions) {
var _a, _b, _c, _d, _e, _f;
super();
this.listr = listr;
this.tasks = tasks;
this.options = options;
this.rendererOptions = rendererOptions;
/**
* A channel for messages.
*
* This requires a separate channel for messages like error, skip or runtime messages to further utilize in the renderers.
*/
this.message = {};
// this kind of randomness is enough for task ids
this.id = (0, uuid_1.generateUUID)();
this.title = (_a = this.tasks) === null || _a === void 0 ? void 0 : _a.title;
this.initialTitle = (_b = this.tasks) === null || _b === void 0 ? void 0 : _b.title;
this.task = this.tasks.task;
// parse functions
this.skip = (_d = (_c = this.tasks) === null || _c === void 0 ? void 0 : _c.skip) !== null && _d !== void 0 ? _d : false;
this.enabledFn = (_f = (_e = this.tasks) === null || _e === void 0 ? void 0 : _e.enabled) !== null && _f !== void 0 ? _f : true;
// task options
this.rendererTaskOptions = this.tasks.options;
this.renderHook$ = this.listr.renderHook$;
this.subscribe(() => {
this.renderHook$.next();
});
}
set state$(state) {
this.state = state;
this.next({
type: event_constants_1.ListrEventType.STATE,
data: state
});
// cancel the subtasks if this has already failed
if (this.hasSubtasks() && this.hasFailed()) {
for (const subtask of this.subtasks) {
if (subtask.state === state_constants_1.ListrTaskState.PENDING) {
subtask.state$ = state_constants_1.ListrTaskState.FAILED;
}
}
}
}
set output$(data) {
this.output = data;
this.next({
type: event_constants_1.ListrEventType.DATA,
data
});
}
set message$(data) {
this.message = { ...this.message, ...data };
this.next({
type: event_constants_1.ListrEventType.MESSAGE,
data
});
}
set title$(title) {
this.title = title;
this.next({
type: event_constants_1.ListrEventType.TITLE,
data: title
});
}
/**
* A function to check whether this task should run at all via enable.
*/
async check(ctx) {
// Check if a task is enabled or disabled
if (this.state === undefined) {
this.enabled = await (0, assert_1.assertFunctionOrSelf)(this.enabledFn, ctx);
this.next({
type: event_constants_1.ListrEventType.ENABLED,
data: this.enabled
});
}
}
/** Returns whether this task has subtasks. */
hasSubtasks() {
var _a;
return ((_a = this.subtasks) === null || _a === void 0 ? void 0 : _a.length) > 0;
}
/** Returns whether this task is in progress. */
isPending() {
return this.state === state_constants_1.ListrTaskState.PENDING;
}
/** Returns whether this task is skipped. */
isSkipped() {
return this.state === state_constants_1.ListrTaskState.SKIPPED;
}
/** Returns whether this task has been completed. */
isCompleted() {
return this.state === state_constants_1.ListrTaskState.COMPLETED;
}
/** Returns whether this task has been failed. */
hasFailed() {
return this.state === state_constants_1.ListrTaskState.FAILED;
}
/** Returns whether this task has an active rollback task going on. */
isRollingBack() {
return this.state === state_constants_1.ListrTaskState.ROLLING_BACK;
}
/** Returns whether the rollback action was successful. */
hasRolledBack() {
return this.state === state_constants_1.ListrTaskState.ROLLED_BACK;
}
/** Returns whether this task has an actively retrying task going on. */
isRetrying() {
return this.state === state_constants_1.ListrTaskState.RETRY;
}
/** Returns whether enabled function resolves to true. */
isEnabled() {
return this.enabled;
}
/** Returns whether this task actually has a title. */
hasTitle() {
return typeof (this === null || this === void 0 ? void 0 : this.title) === 'string';
}
/** Returns whether this task has a prompt inside. */
isPrompt() {
return !!this.prompt;
}
/** Run the current task. */
async run(context, wrapper) {
var _a, _b, _c, _d, _e;
const handleResult = (result) => {
if (result instanceof listr_1.Listr) {
// Detect the subtask
// assign options
result.options = { ...this.options, ...result.options };
// switch to silent renderer since already rendering
result.rendererClass = (0, renderer_1.getRenderer)('silent').renderer;
result.renderHook$.subscribe(() => {
this.renderHook$.next();
});
// assign subtasks
this.subtasks = result.tasks;
result.err = this.listr.err;
this.next({ type: event_constants_1.ListrEventType.SUBTASK });
result = result.run(context);
}
else if (this.isPrompt()) {
// do nothing, it is already being handled
}
else if (result instanceof Promise) {
// Detect promise
result = result.then(handleResult);
}
else if (result instanceof stream_1.Readable) {
// Detect stream
result = new Promise((resolve, reject) => {
result.on('data', (data) => {
this.output$ = data.toString();
});
result.on('error', (error) => reject(error));
result.on('end', () => resolve(null));
});
}
else if (result instanceof rxjs_1.Observable) {
// Detect Observable
result = new Promise((resolve, reject) => {
result.subscribe({
next: (data) => {
this.output$ = data;
},
error: reject,
complete: resolve
});
});
}
return result;
};
const startTime = Date.now();
// finish the task first
this.state$ = state_constants_1.ListrTaskState.PENDING;
// check if this function wants to be skipped
const skipped = await (0, assert_1.assertFunctionOrSelf)(this.skip, context);
if (skipped) {
if (typeof skipped === 'string') {
this.message$ = { skip: skipped };
}
else if (this.hasTitle()) {
this.message$ = { skip: this.title };
}
else {
this.message$ = { skip: 'Skipped task without a title.' };
}
this.state$ = state_constants_1.ListrTaskState.SKIPPED;
return;
}
try {
// add retry functionality
const retryCount = ((_a = this.tasks) === null || _a === void 0 ? void 0 : _a.retry) && ((_b = this.tasks) === null || _b === void 0 ? void 0 : _b.retry) > 0 ? this.tasks.retry + 1 : 1;
for (let retries = 1; retries <= retryCount; retries++) {
try {
// handle the results
await handleResult(this.task(context, wrapper));
break;
}
catch (err) {
if (retries !== retryCount) {
this.retry = { count: retries, withError: err };
this.message$ = { retry: this.retry };
this.title$ = this.initialTitle;
this.output = undefined;
wrapper.report(err, listr_error_interface_1.ListrErrorTypes.WILL_RETRY);
this.state$ = state_constants_1.ListrTaskState.RETRY;
}
else {
throw err;
}
}
}
if (this.isPending() || this.isRetrying()) {
this.message$ = { duration: Date.now() - startTime };
this.state$ = state_constants_1.ListrTaskState.COMPLETED;
}
}
catch (error) {
// catch prompt error, this was the best i could do without going crazy
if (this.prompt instanceof listr_error_interface_1.PromptError) {
// eslint-disable-next-line no-ex-assign
error = new Error(this.prompt.message);
}
// execute the task on error function
if ((_c = this.tasks) === null || _c === void 0 ? void 0 : _c.rollback) {
wrapper.report(error, listr_error_interface_1.ListrErrorTypes.WILL_ROLLBACK);
try {
this.state$ = state_constants_1.ListrTaskState.ROLLING_BACK;
await this.tasks.rollback(context, wrapper);
this.state$ = state_constants_1.ListrTaskState.ROLLED_BACK;
this.message$ = { rollback: this.title };
}
catch (err) {
this.state$ = state_constants_1.ListrTaskState.FAILED;
wrapper.report(err, listr_error_interface_1.ListrErrorTypes.HAS_FAILED_TO_ROLLBACK);
throw err;
}
if (((_d = this.listr.options) === null || _d === void 0 ? void 0 : _d.exitAfterRollback) !== false) {
// Do not exit when explicitly set to `false`
throw new Error(this.title);
}
}
else {
// mark task as failed
this.state$ = state_constants_1.ListrTaskState.FAILED;
if (this.listr.options.exitOnError !== false && await (0, assert_1.assertFunctionOrSelf)((_e = this.tasks) === null || _e === void 0 ? void 0 : _e.exitOnError, context) !== false) {
// Do not exit when explicitly set to `false`
// report error
wrapper.report(error, listr_error_interface_1.ListrErrorTypes.HAS_FAILED);
throw error;
}
else if (!this.hasSubtasks()) {
// subtasks will handle and report their own errors
wrapper.report(error, listr_error_interface_1.ListrErrorTypes.HAS_FAILED_WITHOUT_ERROR);
}
}
}
finally {
// Mark the observable as completed
this.complete();
}
}
}
exports.Task = Task;

24
CyLukTs/lukan/node_modules/listr2/dist/listr.d.ts generated vendored Normal file
View File

@ -0,0 +1,24 @@
import { ListrError } from './interfaces/listr-error.interface';
import { ListrBaseClassOptions, ListrContext, ListrTask } from './interfaces/listr.interface';
import { ListrDefaultRendererValue, ListrFallbackRendererValue, ListrGetRendererClassFromValue, ListrGetRendererOptions, ListrRendererFactory, ListrRendererValue } from './interfaces/renderer.interface';
import { Task } from './lib/task';
/**
* Creates a new set of Listr2 task list.
*/
export declare class Listr<Ctx = ListrContext, Renderer extends ListrRendererValue = ListrDefaultRendererValue, FallbackRenderer extends ListrRendererValue = ListrFallbackRendererValue> {
task: ListrTask<Ctx, ListrGetRendererClassFromValue<Renderer>> | ListrTask<Ctx, ListrGetRendererClassFromValue<Renderer>>[];
options?: ListrBaseClassOptions<Ctx, Renderer, FallbackRenderer>;
tasks: Task<Ctx, ListrGetRendererClassFromValue<Renderer>>[];
err: ListrError<Ctx>[];
ctx: Ctx;
rendererClass: ListrRendererFactory;
rendererClassOptions: ListrGetRendererOptions<ListrRendererFactory>;
renderHook$: Task<any, any>['renderHook$'];
private concurrency;
private renderer;
constructor(task: ListrTask<Ctx, ListrGetRendererClassFromValue<Renderer>> | ListrTask<Ctx, ListrGetRendererClassFromValue<Renderer>>[], options?: ListrBaseClassOptions<Ctx, Renderer, FallbackRenderer>);
add(task: ListrTask<Ctx, ListrGetRendererClassFromValue<Renderer>> | ListrTask<Ctx, ListrGetRendererClassFromValue<Renderer>>[]): void;
run(context?: Ctx): Promise<Ctx>;
private checkAll;
private runTask;
}

122
CyLukTs/lukan/node_modules/listr2/dist/listr.js generated vendored Normal file
View File

@ -0,0 +1,122 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Listr = void 0;
const pMap = require("p-map");
const rxjs_1 = require("rxjs");
const state_constants_1 = require("./constants/state.constants");
const task_1 = require("./lib/task");
const task_wrapper_1 = require("./lib/task-wrapper");
const renderer_1 = require("./utils/renderer");
/**
* Creates a new set of Listr2 task list.
*/
class Listr {
constructor(task, options) {
var _a, _b, _c;
this.task = task;
this.options = options;
this.tasks = [];
this.err = [];
this.renderHook$ = new rxjs_1.Subject();
// assign over default options
this.options = {
...{
concurrent: false,
renderer: 'default',
nonTTYRenderer: 'verbose',
exitOnError: true,
exitAfterRollback: true,
registerSignalListeners: true
},
...options
};
// define parallel options
if (this.options.concurrent === true) {
this.concurrency = Infinity;
}
else if (typeof this.options.concurrent === 'number') {
this.concurrency = this.options.concurrent;
}
else {
this.concurrency = 1;
}
// get renderer class
const renderer = (0, renderer_1.getRenderer)(this.options.renderer, this.options.nonTTYRenderer, (_a = this.options) === null || _a === void 0 ? void 0 : _a.rendererFallback, (_b = this.options) === null || _b === void 0 ? void 0 : _b.rendererSilent);
this.rendererClass = renderer.renderer;
// depending on the result pass the given options in
if (!renderer.nonTTY) {
this.rendererClassOptions = this.options.rendererOptions;
}
else {
this.rendererClassOptions = this.options.nonTTYRendererOptions;
}
// parse and add tasks
/* istanbul ignore next */
this.add(task !== null && task !== void 0 ? task : []);
// Graceful interrupt for render cleanup
/* istanbul ignore if */
if (this.options.registerSignalListeners) {
process
.once('SIGINT', () => {
this.tasks.forEach(async (task) => {
if (task.isPending()) {
task.state$ = state_constants_1.ListrTaskState.FAILED;
}
});
this.renderer.end(new Error('Interrupted.'));
process.exit(127);
})
.setMaxListeners(0);
}
// disable color programatically for CI purposes
/* istanbul ignore if */
if ((_c = this.options) === null || _c === void 0 ? void 0 : _c.disableColor) {
process.env.LISTR_DISABLE_COLOR = '1';
}
}
add(task) {
const tasks = Array.isArray(task) ? task : [task];
tasks.forEach((task) => {
this.tasks.push(new task_1.Task(this, task, this.options, { ...this.rendererClassOptions, ...task.options }));
});
}
async run(context) {
var _a, _b, _c;
// start the renderer
if (!this.renderer) {
this.renderer = new this.rendererClass(this.tasks, this.rendererClassOptions, this.renderHook$);
}
this.renderer.render();
// create a new context
this.ctx = (_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.ctx) !== null && _b !== void 0 ? _b : context) !== null && _c !== void 0 ? _c : {};
// check if the items are enabled
await this.checkAll(this.ctx);
// run tasks
try {
await pMap(this.tasks, async (task) => {
// check this item is enabled, conditions may change depending on context
await task.check(this.ctx);
return this.runTask(task, this.ctx, this.err);
}, { concurrency: this.concurrency });
this.renderer.end();
}
catch (err) {
if (this.options.exitOnError !== false) {
this.renderer.end(err);
// Do not exit when explicitly set to `false`
throw err;
}
}
return this.ctx;
}
checkAll(context) {
return Promise.all(this.tasks.map((task) => task.check(context)));
}
runTask(task, context, errors) {
if (!task.isEnabled()) {
return Promise.resolve();
}
return new task_wrapper_1.TaskWrapper(task, errors, this.options).run(context);
}
}
exports.Listr = Listr;

22
CyLukTs/lukan/node_modules/listr2/dist/manager.d.ts generated vendored Normal file
View File

@ -0,0 +1,22 @@
import { Listr } from './listr';
import { ListrError } from './interfaces/listr-error.interface';
import { ListrBaseClassOptions, ListrContext, ListrSubClassOptions, ListrTask } from './interfaces/listr.interface';
import { ListrGetRendererClassFromValue, ListrRendererValue } from './interfaces/renderer.interface';
/**
* Creates a new Listr2 task manager.
*
* Useful for creating a single instace of Listr2 with pre-set settings.
*/
export declare class Manager<Ctx = ListrContext, Renderer extends ListrRendererValue = 'default', FallbackRenderer extends ListrRendererValue = 'verbose'> {
options?: ListrBaseClassOptions<Ctx, Renderer, FallbackRenderer>;
err: ListrError[];
private tasks;
constructor(options?: ListrBaseClassOptions<Ctx, Renderer, FallbackRenderer>);
set ctx(ctx: Ctx);
add<InjectCtx = Ctx>(tasks: ListrTask<InjectCtx, ListrGetRendererClassFromValue<Renderer>>[] | ((ctx?: InjectCtx) => ListrTask<InjectCtx, ListrGetRendererClassFromValue<Renderer>>[]), options?: ListrSubClassOptions<InjectCtx, Renderer>): void;
runAll<InjectCtx = Ctx>(options?: ListrBaseClassOptions<InjectCtx, Renderer, FallbackRenderer>): Promise<InjectCtx>;
newListr<InjectCtx, InjectRenderer extends ListrRendererValue = Renderer, InjectFallbackRenderer extends ListrRendererValue = FallbackRenderer>(tasks: ListrTask<InjectCtx, ListrGetRendererClassFromValue<InjectRenderer>>[], options?: ListrBaseClassOptions<InjectCtx, InjectRenderer, InjectFallbackRenderer>): Listr<InjectCtx, InjectRenderer, InjectFallbackRenderer>;
indent<InjectCtx = Ctx>(tasks: ListrTask<InjectCtx, ListrGetRendererClassFromValue<Renderer>>[] | ((ctx?: InjectCtx) => ListrTask<InjectCtx, ListrGetRendererClassFromValue<Renderer>>[]), options?: ListrBaseClassOptions<InjectCtx, Renderer, FallbackRenderer>, taskOptions?: Omit<ListrTask<InjectCtx, ListrGetRendererClassFromValue<Renderer>>, 'task'>): ListrTask<InjectCtx, ListrGetRendererClassFromValue<Renderer>>;
run<InjectCtx = Ctx>(tasks: ListrTask<InjectCtx, ListrGetRendererClassFromValue<Renderer>>[], options?: ListrBaseClassOptions<InjectCtx, Renderer, FallbackRenderer>): Promise<InjectCtx>;
getRuntime(pipetime: number): string;
}

67
CyLukTs/lukan/node_modules/listr2/dist/manager.js generated vendored Normal file
View File

@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Manager = void 0;
const listr_1 = require("./listr");
/**
* Creates a new Listr2 task manager.
*
* Useful for creating a single instace of Listr2 with pre-set settings.
*/
class Manager {
constructor(options) {
this.options = options;
this.err = [];
this.tasks = [];
}
set ctx(ctx) {
this.options.ctx = ctx;
}
add(tasks, options) {
options = { ...this.options, ...options };
this.tasks = [...this.tasks, this.indent(tasks, options)];
}
async runAll(options) {
options = { ...this.options, ...options };
const ctx = await this.run(this.tasks, options);
// clear out queues
this.tasks = [];
return ctx;
}
newListr(tasks, options) {
return new listr_1.Listr(tasks, options);
}
indent(tasks, options, taskOptions) {
options = { ...this.options, ...options };
let newTask;
// type function or directly
if (typeof tasks === 'function') {
newTask = {
...taskOptions,
task: (ctx) => this.newListr(tasks(ctx), options)
};
}
else {
newTask = {
...taskOptions,
task: () => this.newListr(tasks, options)
};
}
return newTask;
}
async run(tasks, options) {
options = { ...this.options, ...options };
// create task
const task = this.newListr(tasks, options);
// run task
const ctx = await task.run();
// reset error queue
this.err = task.err;
return ctx;
}
// general utils
/* istanbul ignore next */
getRuntime(pipetime) {
return `${Math.round(Date.now() - pipetime) / 1000}s`;
}
}
exports.Manager = Manager;

View File

@ -0,0 +1,160 @@
import { ListrRenderer } from '../interfaces/renderer.interface';
import { Task } from '../lib/task';
/** Default updating renderer for Listr2 */
export declare class DefaultRenderer implements ListrRenderer {
tasks: Task<any, typeof DefaultRenderer>[];
options: typeof DefaultRenderer['rendererOptions'];
renderHook$?: Task<any, any>['renderHook$'];
/** designates whether this renderer can output to a non-tty console */
static nonTTY: boolean;
/** renderer options for the defauult renderer */
static rendererOptions: {
/**
* indentation per level of subtask
*
* @default 2
*/
indentation?: number;
/**
* clear all the output generated by the renderer when the task finishes its execution
*
* @default false
* @global global option that can not be temperated with subtasks
*/
clearOutput?: boolean;
/**
* show the subtasks of the current task
*
* @default true
*/
showSubtasks?: boolean;
/**
* collapse subtasks after current task completes its execution
*
* @default true
*/
collapse?: boolean;
/**
* show skip messages or show the original title of the task, this will also disable collapseSkips mode
*
* You can disable showing the skip messages, even though you passed in a message by settings this option,
* if you want to keep the original task title intact.
*
* @default true
*/
showSkipMessage?: boolean;
/**
* collapse skip messages into a single message and overwrite the task title
*
* @default true
*/
collapseSkips?: boolean;
/**
* suffix skip messages with [SKIPPED] when in collapseSkips mode
*
* @default true
*/
suffixSkips?: boolean;
/**
* shows the thrown error message or show the original title of the task, this will also disable collapseErrors mode
* You can disable showing the error messages, even though you passed in a message by settings this option,
* if you want to keep the original task title intact.
*
* @default true
*/
showErrorMessage?: boolean;
/**
* collapse error messages into a single message and overwrite the task title
*
* @default true
*/
collapseErrors?: boolean;
/**
* suffix retry messages with [RETRY-${COUNT}] when retry is enabled for a task
*
* @default true
*/
suffixRetries?: boolean;
/**
* only update through triggers from renderhook
*
* useful for tests and stuff. this will disable showing spinner and only update the screen if something else has
* happened in the task worthy to show
*
* @default false
* @global global option that can not be temperated with subtasks
*/
lazy?: boolean;
/**
* show duration for all tasks
*
* @default false
* @global global option that can not be temperated with subtasks
*/
showTimer?: boolean;
/**
* removes empty lines from the data output
*
* @default true
*/
removeEmptyLines?: boolean;
/**
* formats data output depending on your requirements.
*
* @default 'truncate'
* @global global option that can not be temperated with subtasks
*/
formatOutput?: 'truncate' | 'wrap';
};
/** per task options for the default renderer */
static rendererTaskOptions: {
/**
* write task output to the bottom bar instead of the gap under the task title itself.
* useful for a stream of data.
* @default false
*
* `true` only keep 1 line of the latest data outputted by the task.
* `false` only keep 1 line of the latest data outputted by the task.
* `number` will keep designated data of the latest data outputted by the task.
*/
bottomBar?: boolean | number;
/**
* keep output after task finishes
* @default false
*
* works both for the bottom bar and the default behavior
*/
persistentOutput?: boolean;
/**
* show the task time if it was successful
*/
showTimer?: boolean;
};
private id?;
private bottomBar;
private promptBar;
private readonly spinner;
private spinnerPosition;
constructor(tasks: Task<any, typeof DefaultRenderer>[], options: typeof DefaultRenderer['rendererOptions'], renderHook$?: Task<any, any>['renderHook$']);
getTaskOptions(task: Task<any, typeof DefaultRenderer>): typeof DefaultRenderer['rendererTaskOptions'];
isBottomBar(task: Task<any, typeof DefaultRenderer>): boolean;
hasPersistentOutput(task: Task<any, typeof DefaultRenderer>): boolean;
hasTimer(task: Task<any, typeof DefaultRenderer>): boolean;
getSelfOrParentOption<T extends keyof typeof DefaultRenderer['rendererOptions']>(task: Task<any, typeof DefaultRenderer>, key: T): typeof DefaultRenderer['rendererOptions'][T];
getTaskTime(task: Task<any, typeof DefaultRenderer>): string;
createRender(options?: {
tasks?: boolean;
bottomBar?: boolean;
prompt?: boolean;
}): string;
render(): void;
end(): void;
private multiLineRenderer;
private renderBottomBar;
private renderPrompt;
private dumpData;
private formatString;
private indentMultilineOutput;
private getSymbol;
private addSuffixToMessage;
}

View File

@ -0,0 +1,363 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultRenderer = void 0;
const cliTruncate = require("cli-truncate");
const logUpdate = require("log-update");
const os_1 = require("os");
const cliWrap = require("wrap-ansi");
const colorette_1 = require("../utils/colorette");
const figures_1 = require("../utils/figures");
const indent_string_1 = require("../utils/indent-string");
const is_unicode_supported_1 = require("../utils/is-unicode-supported");
const parse_time_1 = require("../utils/parse-time");
/** Default updating renderer for Listr2 */
class DefaultRenderer {
constructor(tasks, options, renderHook$) {
this.tasks = tasks;
this.options = options;
this.renderHook$ = renderHook$;
this.bottomBar = {};
this.spinner = !(0, is_unicode_supported_1.isUnicodeSupported)() ? ['-', '\\', '|', '/'] : ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
this.spinnerPosition = 0;
this.options = { ...DefaultRenderer.rendererOptions, ...this.options };
}
getTaskOptions(task) {
return { ...DefaultRenderer.rendererTaskOptions, ...task.rendererTaskOptions };
}
isBottomBar(task) {
const bottomBar = this.getTaskOptions(task).bottomBar;
return typeof bottomBar === 'number' && bottomBar !== 0 || typeof bottomBar === 'boolean' && bottomBar !== false;
}
hasPersistentOutput(task) {
return this.getTaskOptions(task).persistentOutput === true;
}
hasTimer(task) {
return this.getTaskOptions(task).showTimer === true;
}
getSelfOrParentOption(task, key) {
var _a, _b, _c;
return (_b = (_a = task === null || task === void 0 ? void 0 : task.rendererOptions) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : (_c = this.options) === null || _c === void 0 ? void 0 : _c[key];
}
/* istanbul ignore next */
getTaskTime(task) {
return colorette_1.default.dim(`[${(0, parse_time_1.parseTaskTime)(task.message.duration)}]`);
}
createRender(options) {
options = {
...{
tasks: true,
bottomBar: true,
prompt: true
},
...options
};
const render = [];
const renderTasks = this.multiLineRenderer(this.tasks);
const renderBottomBar = this.renderBottomBar();
const renderPrompt = this.renderPrompt();
if (options.tasks && (renderTasks === null || renderTasks === void 0 ? void 0 : renderTasks.trim().length) > 0) {
render.push(renderTasks);
}
if (options.bottomBar && (renderBottomBar === null || renderBottomBar === void 0 ? void 0 : renderBottomBar.trim().length) > 0) {
render.push((render.length > 0 ? os_1.EOL : '') + renderBottomBar);
}
if (options.prompt && (renderPrompt === null || renderPrompt === void 0 ? void 0 : renderPrompt.trim().length) > 0) {
render.push((render.length > 0 ? os_1.EOL : '') + renderPrompt);
}
return render.length > 0 ? render.join(os_1.EOL) : '';
}
render() {
var _a;
// Do not render if we are already rendering
if (this.id) {
return;
}
const updateRender = () => logUpdate(this.createRender());
/* istanbul ignore if */
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lazy)) {
this.id = setInterval(() => {
this.spinnerPosition = ++this.spinnerPosition % this.spinner.length;
updateRender();
}, 100);
}
this.renderHook$.subscribe(() => {
updateRender();
});
}
end() {
clearInterval(this.id);
if (this.id) {
this.id = undefined;
}
// clear log updater
logUpdate.clear();
logUpdate.done();
// directly write to process.stdout, since logupdate only can update the seen height of terminal
if (!this.options.clearOutput) {
process.stdout.write(this.createRender({ prompt: false }) + os_1.EOL);
}
}
// eslint-disable-next-line
multiLineRenderer(tasks, level = 0) {
var _a, _b;
let output = [];
for (const task of tasks) {
if (task.isEnabled()) {
// Current Task Title
if (task.hasTitle()) {
if (!(tasks.some((task) => task.hasFailed()) && !task.hasFailed() && task.options.exitOnError !== false && !(task.isCompleted() || task.isSkipped()))) {
// if task is skipped
if (task.hasFailed() && this.getSelfOrParentOption(task, 'collapseErrors')) {
// current task title and skip change the title
output = [
...output,
this.formatString(!task.hasSubtasks() && task.message.error && this.getSelfOrParentOption(task, 'showErrorMessage') ? task.message.error : task.title, this.getSymbol(task), level)
];
}
else if (task.isSkipped() && this.getSelfOrParentOption(task, 'collapseSkips')) {
// current task title and skip change the title
output = [
...output,
this.formatString(this.addSuffixToMessage(task.message.skip && this.getSelfOrParentOption(task, 'showSkipMessage') ? task.message.skip : task.title, 'SKIPPED', this.getSelfOrParentOption(task, 'suffixSkips')), this.getSymbol(task), level)
];
}
else if (task.isRetrying() && this.getSelfOrParentOption(task, 'suffixRetries')) {
output = [...output, this.formatString(this.addSuffixToMessage(task.title, `RETRYING-${task.message.retry.count}`), this.getSymbol(task), level)];
}
else if (task.isCompleted() && task.hasTitle() && (this.getSelfOrParentOption(task, 'showTimer') || this.hasTimer(task))) {
// task with timer
output = [...output, this.formatString(`${task === null || task === void 0 ? void 0 : task.title} ${this.getTaskTime(task)}`, this.getSymbol(task), level)];
}
else {
// normal state
output = [...output, this.formatString(task.title, this.getSymbol(task), level)];
}
}
else {
// some sibling task but self has failed and this has stopped
output = [...output, this.formatString(task.title, colorette_1.default.red(figures_1.figures.squareSmallFilled), level)];
}
}
// task should not have subtasks since subtasks will handle the error already
// maybe it is a better idea to show the error or skip messages when show subtasks is disabled.
if (!task.hasSubtasks() || !this.getSelfOrParentOption(task, 'showSubtasks')) {
// without the collapse option for skip and errors
if (task.hasFailed() &&
this.getSelfOrParentOption(task, 'collapseErrors') === false &&
(this.getSelfOrParentOption(task, 'showErrorMessage') || !this.getSelfOrParentOption(task, 'showSubtasks'))) {
// show skip data if collapsing is not defined
output = [...output, this.dumpData(task, level, 'error')];
}
else if (task.isSkipped() &&
this.getSelfOrParentOption(task, 'collapseSkips') === false &&
(this.getSelfOrParentOption(task, 'showSkipMessage') || !this.getSelfOrParentOption(task, 'showSubtasks'))) {
// show skip data if collapsing is not defined
output = [...output, this.dumpData(task, level, 'skip')];
}
}
// Current Task Output
if (task === null || task === void 0 ? void 0 : task.output) {
if ((task.isPending() || task.isRetrying() || task.isRollingBack()) && task.isPrompt()) {
// data output to prompt bar if prompt
this.promptBar = task.output;
}
else if (this.isBottomBar(task) || !task.hasTitle()) {
// data output to bottom bar
const data = [this.dumpData(task, -1)];
// create new if there is no persistent storage created for bottom bar
if (!this.bottomBar[task.id]) {
this.bottomBar[task.id] = {};
this.bottomBar[task.id].data = [];
const bottomBar = this.getTaskOptions(task).bottomBar;
if (typeof bottomBar === 'boolean') {
this.bottomBar[task.id].items = 1;
}
else {
this.bottomBar[task.id].items = bottomBar;
}
}
// persistent bottom bar and limit items in it
if (!((_b = (_a = this.bottomBar[task.id]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.some((element) => data.includes(element))) && !task.isSkipped()) {
this.bottomBar[task.id].data = [...this.bottomBar[task.id].data, ...data];
}
}
else if (task.isPending() || task.isRetrying() || task.isRollingBack() || this.hasPersistentOutput(task)) {
// keep output if persistent output is set
output = [...output, this.dumpData(task, level)];
}
}
// render subtasks, some complicated conditionals going on
if (
// check if renderer option is on first
this.getSelfOrParentOption(task, 'showSubtasks') !== false &&
// if it doesnt have subtasks no need to check
task.hasSubtasks() &&
(task.isPending() ||
task.hasFailed() ||
task.isCompleted() && !task.hasTitle() ||
// have to be completed and have subtasks
task.isCompleted() && this.getSelfOrParentOption(task, 'collapse') === false && !task.subtasks.some((subtask) => subtask.rendererOptions.collapse === true) ||
// if any of the subtasks have the collapse option of
task.subtasks.some((subtask) => subtask.rendererOptions.collapse === false) ||
// if any of the subtasks has failed
task.subtasks.some((subtask) => subtask.hasFailed()) ||
// if any of the subtasks rolled back
task.subtasks.some((subtask) => subtask.hasRolledBack()))) {
// set level
const subtaskLevel = !task.hasTitle() ? level : level + 1;
// render the subtasks as in the same way
const subtaskRender = this.multiLineRenderer(task.subtasks, subtaskLevel);
if ((subtaskRender === null || subtaskRender === void 0 ? void 0 : subtaskRender.trim()) !== '' && !task.subtasks.every((subtask) => !subtask.hasTitle())) {
output = [...output, subtaskRender];
}
}
// after task is finished actions
if (task.isCompleted() || task.hasFailed() || task.isSkipped() || task.hasRolledBack()) {
// clean up prompts
this.promptBar = null;
// clean up bottom bar items if not indicated otherwise
if (!this.hasPersistentOutput(task)) {
delete this.bottomBar[task.id];
}
}
}
}
output = output.filter(Boolean);
if (output.length > 0) {
return output.join(os_1.EOL);
}
else {
return;
}
}
renderBottomBar() {
// parse through all objects return only the last mentioned items
if (Object.keys(this.bottomBar).length > 0) {
this.bottomBar = Object.keys(this.bottomBar).reduce((o, key) => {
if (!(o === null || o === void 0 ? void 0 : o[key])) {
o[key] = {};
}
o[key] = this.bottomBar[key];
this.bottomBar[key].data = this.bottomBar[key].data.slice(-this.bottomBar[key].items);
o[key].data = this.bottomBar[key].data;
return o;
}, {});
return Object.values(this.bottomBar)
.reduce((o, value) => o = [...o, ...value.data], [])
.filter(Boolean)
.join(os_1.EOL);
}
}
renderPrompt() {
if (this.promptBar) {
return this.promptBar;
}
}
dumpData(task, level, source = 'output') {
let data;
switch (source) {
case 'output':
data = task.output;
break;
case 'skip':
data = task.message.skip;
break;
case 'error':
data = task.message.error;
break;
}
// dont return anything on some occasions
if (task.hasTitle() && source === 'error' && data === task.title) {
return;
}
if (typeof data === 'string') {
return this.formatString(data, this.getSymbol(task, true), level + 1);
}
}
formatString(str, icon, level) {
// we dont like empty data around here
if (str.trim() === '') {
return;
}
str = `${icon} ${str}`;
let parsedStr;
let columns = process.stdout.columns ? process.stdout.columns : 80;
columns = columns - level * this.options.indentation - 2;
switch (this.options.formatOutput) {
case 'truncate':
parsedStr = str.split(os_1.EOL).map((s, i) => {
return cliTruncate(this.indentMultilineOutput(s, i), columns);
});
break;
case 'wrap':
parsedStr = cliWrap(str, columns, { hard: true })
.split(os_1.EOL)
.map((s, i) => this.indentMultilineOutput(s, i));
break;
default:
throw new Error('Format option for the renderer is wrong.');
}
// this removes the empty lines
if (this.options.removeEmptyLines) {
parsedStr = parsedStr.filter(Boolean);
}
return (0, indent_string_1.indentString)(parsedStr.join(os_1.EOL), level * this.options.indentation);
}
indentMultilineOutput(str, i) {
return i > 0 ? (0, indent_string_1.indentString)(str.trim(), 2) : str.trim();
}
// eslint-disable-next-line complexity
getSymbol(task, data = false) {
var _a, _b, _c;
if (task.isPending() && !data) {
return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.lazy) || this.getSelfOrParentOption(task, 'showSubtasks') !== false && task.hasSubtasks() && !task.subtasks.every((subtask) => !subtask.hasTitle())
? colorette_1.default.yellow(figures_1.figures.pointer)
: colorette_1.default.yellowBright(this.spinner[this.spinnerPosition]);
}
else if (task.isCompleted() && !data) {
return task.hasSubtasks() && task.subtasks.some((subtask) => subtask.hasFailed()) ? colorette_1.default.yellow(figures_1.figures.warning) : colorette_1.default.green(figures_1.figures.tick);
}
else if (task.isRetrying() && !data) {
return ((_b = this.options) === null || _b === void 0 ? void 0 : _b.lazy) ? colorette_1.default.yellow(figures_1.figures.warning) : colorette_1.default.yellow(this.spinner[this.spinnerPosition]);
}
else if (task.isRollingBack() && !data) {
return ((_c = this.options) === null || _c === void 0 ? void 0 : _c.lazy) ? colorette_1.default.red(figures_1.figures.warning) : colorette_1.default.red(this.spinner[this.spinnerPosition]);
}
else if (task.hasRolledBack() && !data) {
return colorette_1.default.red(figures_1.figures.arrowLeft);
}
else if (task.hasFailed() && !data) {
return task.hasSubtasks() ? colorette_1.default.red(figures_1.figures.pointer) : colorette_1.default.red(figures_1.figures.cross);
}
else if (task.isSkipped() && !data && this.getSelfOrParentOption(task, 'collapseSkips') === false) {
return colorette_1.default.yellow(figures_1.figures.warning);
}
else if (task.isSkipped() && (data || this.getSelfOrParentOption(task, 'collapseSkips'))) {
return colorette_1.default.yellow(figures_1.figures.arrowDown);
}
return !data ? colorette_1.default.dim(figures_1.figures.squareSmallFilled) : figures_1.figures.pointerSmall;
}
addSuffixToMessage(message, suffix, condition) {
return (condition !== null && condition !== void 0 ? condition : true) ? message + colorette_1.default.dim(` [${suffix}]`) : message;
}
}
exports.DefaultRenderer = DefaultRenderer;
/** designates whether this renderer can output to a non-tty console */
DefaultRenderer.nonTTY = false;
/** renderer options for the defauult renderer */
DefaultRenderer.rendererOptions = {
indentation: 2,
clearOutput: false,
showSubtasks: true,
collapse: true,
collapseSkips: true,
showSkipMessage: true,
suffixSkips: true,
collapseErrors: true,
showErrorMessage: true,
suffixRetries: true,
lazy: false,
showTimer: false,
removeEmptyLines: true,
formatOutput: 'truncate'
};

View File

@ -0,0 +1,15 @@
import { ListrRenderer } from '../interfaces/renderer.interface';
import { Task } from '../lib/task';
export declare class SilentRenderer implements ListrRenderer {
tasks: Task<any, typeof SilentRenderer>[];
options: typeof SilentRenderer['rendererOptions'];
/** designates whether this renderer can output to a non-tty console */
static nonTTY: boolean;
/** renderer options for the silent renderer */
static rendererOptions: never;
/** per task options for the silent renderer */
static rendererTaskOptions: never;
constructor(tasks: Task<any, typeof SilentRenderer>[], options: typeof SilentRenderer['rendererOptions']);
render(): void;
end(): void;
}

View File

@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SilentRenderer = void 0;
class SilentRenderer {
constructor(tasks, options) {
this.tasks = tasks;
this.options = options;
}
render() { }
end() { }
}
exports.SilentRenderer = SilentRenderer;
/** designates whether this renderer can output to a non-tty console */
SilentRenderer.nonTTY = true;

View File

@ -0,0 +1,48 @@
import { ListrEventType } from '../constants/event.constants';
import { ListrEventFromType } from '../interfaces/listr.interface';
import { ListrRenderer } from '../interfaces/renderer.interface';
import { Task } from '../lib/task';
/**
* This is the default renderer which is neither verbose or updating.
* It provides short output like update renderer, but does not disturb
* stdin during execution of listr tasks
*/
export declare class SimpleRenderer implements ListrRenderer {
readonly tasks: Task<any, typeof SimpleRenderer>[];
options: typeof SimpleRenderer['rendererOptions'];
static nonTTY: boolean;
static rendererOptions: {
/**
* if true this will add
* timestamp at the begin of the rendered line
*
* @example
*
* ```bash
* [12:33:44] ✔ Do something important
* ```
*
* @default false
*/
prefixWithTimestamp?: boolean;
/**
* choose between process.stdout and process.stderr
*
* @default stdout
*/
output?: 'stdout' | 'stderr';
};
static rendererTaskOptions: never;
/**
* Event type renderer map contains functions to process different task events
*/
eventTypeRendererMap: Partial<{
[P in ListrEventType]: (t: Task<any, typeof SimpleRenderer>, event: ListrEventFromType<P>) => void;
}>;
constructor(tasks: Task<any, typeof SimpleRenderer>[], options: typeof SimpleRenderer['rendererOptions']);
static now(): Date;
static formatTitle(task?: Task<any, typeof SimpleRenderer>): string;
log(output?: string): void;
end(): void;
render(tasks?: Task<any, typeof SimpleRenderer>[]): void;
}

View File

@ -0,0 +1,119 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleRenderer = void 0;
const log_update_1 = require("log-update");
const os_1 = require("os");
const event_constants_1 = require("../constants/event.constants");
const colorette_1 = require("../utils/colorette");
const figures_1 = require("../utils/figures");
/**
* This is the default renderer which is neither verbose or updating.
* It provides short output like update renderer, but does not disturb
* stdin during execution of listr tasks
*/
class SimpleRenderer {
constructor(tasks, options) {
this.tasks = tasks;
this.options = options;
/**
* Event type renderer map contains functions to process different task events
*/
this.eventTypeRendererMap = {
[event_constants_1.ListrEventType.SUBTASK]: (task) => {
if (task.hasTitle()) {
// if Task has subtasks where we want to log the group indication
this.log(`${colorette_1.default.blue(figures_1.figures.pointer)} ${task.title}`);
}
if (task.hasSubtasks()) {
this.render(task.subtasks);
}
},
[event_constants_1.ListrEventType.STATE]: (task) => {
if (task.isCompleted() && task.hasTitle()) {
// The title is only logged at the end of the task execution
this.log(`${colorette_1.default.green(figures_1.figures.tick)} ${task.title}`);
}
},
[event_constants_1.ListrEventType.DATA]: (task, event) => {
// ! This is where it gets dirty
// * We want the prompt to stay visible after confirmation
if (task.isPrompt() && !String(event.data).match(/^\n$/)) {
(0, log_update_1.stderr)(`${event.data}`);
}
else {
this.log(`${figures_1.figures.pointerSmall} ${event.data}`);
}
},
[event_constants_1.ListrEventType.MESSAGE]: (task, event) => {
if (event.data.error) {
// error message
const title = SimpleRenderer.formatTitle(task);
this.log(`${colorette_1.default.red(figures_1.figures.cross)}${title}: ${event.data.error}`);
}
else if (event.data.skip) {
// Skip message
const title = SimpleRenderer.formatTitle(task);
const skip = task.title !== event.data.skip ? `: ${event.data.skip}` : '';
this.log(`${colorette_1.default.yellow(figures_1.figures.arrowDown)}${title} [${colorette_1.default.yellow(`skipped${skip}`)}]`);
}
else if (event.data.rollback) {
// rollback message
const title = SimpleRenderer.formatTitle(task);
this.log(`${colorette_1.default.red(figures_1.figures.arrowLeft)}${title}: ${event.data.rollback}`);
}
else if (event.data.retry) {
// Retry Message
const title = SimpleRenderer.formatTitle(task);
this.log(`[${colorette_1.default.yellow(`${event.data.retry.count}`)}]${title}`);
}
}
// * We do not log out initial title. Only the final one.
// [ListrEventType.TITLE]: (t, e) => this.renderTitle(t, e),
};
this.options = { ...SimpleRenderer.rendererOptions, ...options };
}
// This is used for mocks, since mocking Date is cumbesome
static now() {
return new Date();
}
// Used to sanitize title output
static formatTitle(task) {
return (task === null || task === void 0 ? void 0 : task.title) ? ` ${task.title}` : '';
}
// Writes sanitized output
log(output) {
const logOut = (msg) => {
// Need appent \n to mimic console.log
process[this.options.output].write(msg.endsWith(os_1.EOL) ? msg : `${msg}${os_1.EOL}`);
};
if (!this.options.prefixWithTimestamp) {
logOut(`${output}`);
return;
}
const now = SimpleRenderer.now();
const timestamp = String(now.getHours()).padStart(2, '0') + ':' + String(now.getMinutes()).padStart(2, '0') + ':' + String(now.getSeconds()).padStart(2, '0');
logOut(`${colorette_1.default.dim(`[${timestamp}]`)} ${output}`);
}
// eslint-disable-next-line
end() { }
// yes this is a misuse :)
render(tasks) {
if (tasks === null || tasks === void 0 ? void 0 : tasks.length) {
tasks.forEach((task) => {
task.subscribe((event) => {
var _a, _b;
// Here event type will match event.type anyway
(_b = (_a = this.eventTypeRendererMap)[event.type]) === null || _b === void 0 ? void 0 : _b.call(_a, task, event);
}, this.log);
});
}
else {
this.render(this.tasks);
}
}
}
exports.SimpleRenderer = SimpleRenderer;
// Designate this renderer as tty or nonTTY
SimpleRenderer.nonTTY = true;
// designate your renderer options that will be showed inside the `ListrOptions` as rendererOptions
SimpleRenderer.rendererOptions = { prefixWithTimestamp: false, output: 'stdout' };

View File

@ -0,0 +1,47 @@
import { ListrRenderer } from '../interfaces/renderer.interface';
import { Task } from '../lib/task';
import { Logger } from '../utils/logger';
export declare class VerboseRenderer implements ListrRenderer {
tasks: Task<any, typeof VerboseRenderer>[];
options: typeof VerboseRenderer['rendererOptions'];
/** designates whether this renderer can output to a non-tty console */
static nonTTY: boolean;
/** renderer options for the verbose renderer */
static rendererOptions: ({
/**
* useIcons instead of text for log level
* @default false
*/
useIcons?: boolean;
/**
* log tasks with empty titles
* @default true
*/
logEmptyTitle?: boolean;
/**
* log title changes
* @default true
*/
logTitleChange?: boolean;
/**
* show duration for all tasks
*/
showTimer?: boolean;
} & {
/**
* inject a custom logger
*/
logger?: new (...args: any) => Logger;
/**
* inject options to custom logger
*/
options?: any;
});
/** per task options for the verbose renderer */
static rendererTaskOptions: never;
private logger;
constructor(tasks: Task<any, typeof VerboseRenderer>[], options: typeof VerboseRenderer['rendererOptions']);
render(): void;
end(): void;
private verboseRenderer;
}

View File

@ -0,0 +1,94 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VerboseRenderer = void 0;
const event_constants_1 = require("../constants/event.constants");
const logger_1 = require("../utils/logger");
const parse_time_1 = require("../utils/parse-time");
class VerboseRenderer {
constructor(tasks, options) {
var _a, _b, _c, _d;
this.tasks = tasks;
this.options = options;
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.logger) && ((_b = this.options) === null || _b === void 0 ? void 0 : _b.options)) {
this.logger = new this.options.logger(this.options.options);
}
else if ((_c = this.options) === null || _c === void 0 ? void 0 : _c.logger) {
this.logger = new this.options.logger();
}
else {
this.logger = new logger_1.Logger({ useIcons: (_d = this.options) === null || _d === void 0 ? void 0 : _d.useIcons });
}
this.options = { ...VerboseRenderer.rendererOptions, ...this.options };
}
render() {
this.verboseRenderer(this.tasks);
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
end() { }
// verbose renderer multi-level
verboseRenderer(tasks) {
return tasks === null || tasks === void 0 ? void 0 : tasks.forEach((task) => {
task.subscribe(
// eslint-disable-next-line complexity
(event) => {
var _a, _b, _c, _d, _e, _f, _g, _h;
if (task.isEnabled()) {
// render depending on the state
const taskTitle = task.hasTitle() ? task.title : 'Task without title.';
if (event.type === event_constants_1.ListrEventType.SUBTASK && task.hasSubtasks()) {
// render lower level if multi-level
this.verboseRenderer(task.subtasks);
}
else if (event.type === event_constants_1.ListrEventType.STATE) {
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.logEmptyTitle) !== false || task.hasTitle()) {
if (task.isPending()) {
this.logger.start(taskTitle);
}
else if (task.isCompleted()) {
this.logger.success(taskTitle + (((_b = this.options) === null || _b === void 0 ? void 0 : _b.showTimer) && ((_c = task.message) === null || _c === void 0 ? void 0 : _c.duration) ? ` [${(0, parse_time_1.parseTaskTime)(task.message.duration)}]` : ''));
}
}
}
else if (event.type === event_constants_1.ListrEventType.DATA && !!event.data) {
this.logger.data(String(event.data));
}
else if (event.type === event_constants_1.ListrEventType.TITLE) {
if (((_d = this.options) === null || _d === void 0 ? void 0 : _d.logTitleChange) !== false) {
this.logger.title(String(event.data));
}
}
else if (event.type === event_constants_1.ListrEventType.MESSAGE) {
if ((_e = event.data) === null || _e === void 0 ? void 0 : _e.error) {
// error message
this.logger.fail(String(event.data.error));
}
else if ((_f = event.data) === null || _f === void 0 ? void 0 : _f.skip) {
// skip message
this.logger.skip(String(event.data.skip));
}
else if ((_g = event.data) === null || _g === void 0 ? void 0 : _g.rollback) {
// rollback message
this.logger.rollback(String(event.data.rollback));
}
else if ((_h = event.data) === null || _h === void 0 ? void 0 : _h.retry) {
// inform of retry count
this.logger.retry(`[${event.data.retry.count}] ` + String(taskTitle));
}
}
}
},
/* istanbul ignore next */ (err) => {
this.logger.fail(err);
});
});
}
}
exports.VerboseRenderer = VerboseRenderer;
/** designates whether this renderer can output to a non-tty console */
VerboseRenderer.nonTTY = true;
/** renderer options for the verbose renderer */
VerboseRenderer.rendererOptions = {
useIcons: false,
logEmptyTitle: true,
logTitleChange: true
};

View File

@ -0,0 +1,6 @@
/**
* This function asserts the given value as a function or itself.
* If the value itself is a function it will evaluate it with the passed in arguments,
* elsewise it will directly return itself.
*/
export declare function assertFunctionOrSelf<T>(functionOrSelf: T, ...args: T extends (...args: any[]) => any ? Parameters<T> : never): T extends (...args: any[]) => any ? ReturnType<T> : T;

17
CyLukTs/lukan/node_modules/listr2/dist/utils/assert.js generated vendored Normal file
View File

@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertFunctionOrSelf = void 0;
/**
* This function asserts the given value as a function or itself.
* If the value itself is a function it will evaluate it with the passed in arguments,
* elsewise it will directly return itself.
*/
function assertFunctionOrSelf(functionOrSelf, ...args) {
if (typeof functionOrSelf === 'function') {
return functionOrSelf(...args);
}
else {
return functionOrSelf;
}
}
exports.assertFunctionOrSelf = assertFunctionOrSelf;

View File

@ -0,0 +1,3 @@
/// <reference types="colorette" />
declare const _default: import("colorette").Colorette;
export default _default;

View File

@ -0,0 +1,5 @@
"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
const colorette_1 = require("colorette");
exports.default = (0, colorette_1.createColors)({ useColor: ((_a = process.env) === null || _a === void 0 ? void 0 : _a.LISTR_DISABLE_COLOR) !== '1' });

View File

@ -0,0 +1,12 @@
export declare const figures: {
warning: string;
cross: string;
arrowDown: string;
tick: string;
arrowRight: string;
pointer: string;
checkboxOn: string;
arrowLeft: string;
squareSmallFilled: string;
pointerSmall: string;
};

View File

@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.figures = void 0;
const is_unicode_supported_1 = require("./is-unicode-supported");
const FIGURES_MAIN = {
warning: '⚠',
cross: '✖',
arrowDown: '↓',
tick: '✔',
arrowRight: '→',
pointer: '',
checkboxOn: '☒',
arrowLeft: '←',
squareSmallFilled: '◼',
pointerSmall: ''
};
const FIGURES_FALLBACK = {
...FIGURES_MAIN,
warning: '‼',
cross: '×',
tick: '√',
pointer: '>',
checkboxOn: '[×]',
squareSmallFilled: '■'
};
exports.figures = (0, is_unicode_supported_1.isUnicodeSupported)() ? FIGURES_MAIN : FIGURES_FALLBACK;

View File

@ -0,0 +1,4 @@
/**
* Deep clones a object in the most easiest manner.
*/
export declare function cloneObject<T extends Record<PropertyKey, any>>(obj: T): T;

View File

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cloneObject = void 0;
const rfdc = require("rfdc");
const clone = rfdc({ circles: true });
/**
* Deep clones a object in the most easiest manner.
*/
function cloneObject(obj) {
return clone(obj);
}
exports.cloneObject = cloneObject;

View File

@ -0,0 +1 @@
export declare function indentString(string: string, count: number): string;

View File

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.indentString = void 0;
function indentString(string, count) {
return string.replace(/^(?!\s*$)/gm, ' '.repeat(count));
}
exports.indentString = indentString;

View File

@ -0,0 +1 @@
export declare function isUnicodeSupported(): boolean;

View File

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isUnicodeSupported = void 0;
function isUnicodeSupported() {
if (process.platform !== 'win32') {
return true;
}
/* istanbul ignore next */
return (Boolean(process.env.CI) || Boolean(process.env.WT_SESSION) || process.env.TERM_PROGRAM === 'vscode' || process.env.TERM === 'xterm-256color' || process.env.TERM === 'alacritty');
}
exports.isUnicodeSupported = isUnicodeSupported;

View File

@ -0,0 +1,12 @@
/** Default loglevels for the logger */
export declare enum LogLevels {
SILENT = "SILENT",
FAILED = "FAILED",
SKIPPED = "SKIPPED",
SUCCESS = "SUCCESS",
DATA = "DATA",
STARTED = "STARTED",
TITLE = "TITLE",
RETRY = "RETRY",
ROLLBACK = "ROLLBACK"
}

View File

@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LogLevels = void 0;
/** Default loglevels for the logger */
var LogLevels;
(function (LogLevels) {
LogLevels["SILENT"] = "SILENT";
LogLevels["FAILED"] = "FAILED";
LogLevels["SKIPPED"] = "SKIPPED";
LogLevels["SUCCESS"] = "SUCCESS";
LogLevels["DATA"] = "DATA";
LogLevels["STARTED"] = "STARTED";
LogLevels["TITLE"] = "TITLE";
LogLevels["RETRY"] = "RETRY";
LogLevels["ROLLBACK"] = "ROLLBACK";
})(LogLevels = exports.LogLevels || (exports.LogLevels = {}));

View File

@ -0,0 +1,23 @@
import { LogLevels } from './logger.constants';
import { LoggerOptions } from './logger.interface';
/**
* A internal logger for using in the verbose renderer mostly.
*/
export declare class Logger {
private options?;
constructor(options?: LoggerOptions);
fail(message: string): void;
skip(message: string): void;
success(message: string): void;
data(message: string): void;
start(message: string): void;
title(message: string): void;
retry(message: string): void;
rollback(message: string): void;
protected parseMessage(level: LogLevels, message: string): string;
protected logColoring({ level, message }: {
level: LogLevels;
message: string;
}): string;
private wrapInBrackets;
}

View File

@ -0,0 +1,6 @@
/**
* Options for the logger
*/
export interface LoggerOptions {
useIcons: boolean;
}

View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

159
CyLukTs/lukan/node_modules/listr2/dist/utils/logger.js generated vendored Normal file
View File

@ -0,0 +1,159 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
/* eslint-disable no-console */
const figures_1 = require("./figures");
const logger_constants_1 = require("./logger.constants");
const colorette_1 = require("./colorette");
/**
* A internal logger for using in the verbose renderer mostly.
*/
class Logger {
constructor(options) {
this.options = options;
}
fail(message) {
message = this.parseMessage(logger_constants_1.LogLevels.FAILED, message);
console.error(message);
}
skip(message) {
message = this.parseMessage(logger_constants_1.LogLevels.SKIPPED, message);
console.info(message);
}
success(message) {
message = this.parseMessage(logger_constants_1.LogLevels.SUCCESS, message);
console.log(message);
}
data(message) {
message = this.parseMessage(logger_constants_1.LogLevels.DATA, message);
console.info(message);
}
start(message) {
message = this.parseMessage(logger_constants_1.LogLevels.STARTED, message);
console.log(message);
}
title(message) {
message = this.parseMessage(logger_constants_1.LogLevels.TITLE, message);
console.info(message);
}
retry(message) {
message = this.parseMessage(logger_constants_1.LogLevels.RETRY, message);
console.warn(message);
}
rollback(message) {
message = this.parseMessage(logger_constants_1.LogLevels.ROLLBACK, message);
console.warn(message);
}
parseMessage(level, message) {
// parse multi line messages
let multiLineMessage;
try {
multiLineMessage = message.split('\n');
}
catch /* istanbul ignore next */ {
multiLineMessage = [message];
}
multiLineMessage = multiLineMessage.map((msg) => {
// format messages
return this.logColoring({
level,
message: msg
});
});
// join back multi line messages
message = multiLineMessage.join('\n');
return message;
}
logColoring({ level, message }) {
var _a, _b, _c, _d, _e, _f, _g, _h;
let icon;
// do the coloring
let coloring = (input) => {
return input;
};
switch (level) {
case logger_constants_1.LogLevels.FAILED:
/* istanbul ignore if */
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.useIcons) {
coloring = colorette_1.default.red;
icon = figures_1.figures.cross;
}
else {
icon = this.wrapInBrackets(level);
}
break;
case logger_constants_1.LogLevels.SKIPPED:
/* istanbul ignore if */
if ((_b = this.options) === null || _b === void 0 ? void 0 : _b.useIcons) {
coloring = colorette_1.default.yellow;
icon = figures_1.figures.arrowDown;
}
else {
icon = this.wrapInBrackets(level);
}
break;
case logger_constants_1.LogLevels.SUCCESS:
/* istanbul ignore if */
if ((_c = this.options) === null || _c === void 0 ? void 0 : _c.useIcons) {
coloring = colorette_1.default.green;
icon = figures_1.figures.tick;
}
else {
icon = this.wrapInBrackets(level);
}
break;
case logger_constants_1.LogLevels.DATA:
/* istanbul ignore if */
if ((_d = this.options) === null || _d === void 0 ? void 0 : _d.useIcons) {
icon = figures_1.figures.arrowRight;
}
else {
icon = this.wrapInBrackets(level);
}
break;
case logger_constants_1.LogLevels.STARTED:
/* istanbul ignore if */
if ((_e = this.options) === null || _e === void 0 ? void 0 : _e.useIcons) {
icon = figures_1.figures.pointer;
}
else {
icon = this.wrapInBrackets(level);
}
break;
case logger_constants_1.LogLevels.TITLE:
/* istanbul ignore if */
if ((_f = this.options) === null || _f === void 0 ? void 0 : _f.useIcons) {
icon = figures_1.figures.checkboxOn;
}
else {
icon = this.wrapInBrackets(level);
}
break;
case logger_constants_1.LogLevels.RETRY:
/* istanbul ignore if */
if ((_g = this.options) === null || _g === void 0 ? void 0 : _g.useIcons) {
coloring = colorette_1.default.yellow;
icon = figures_1.figures.pointer;
}
else {
icon = this.wrapInBrackets(level);
}
break;
case logger_constants_1.LogLevels.ROLLBACK:
/* istanbul ignore if */
if ((_h = this.options) === null || _h === void 0 ? void 0 : _h.useIcons) {
coloring = colorette_1.default.red;
icon = figures_1.figures.arrowLeft;
}
else {
icon = this.wrapInBrackets(level);
}
break;
}
return coloring(`${icon} ${message}`);
}
wrapInBrackets(level) {
return `[${level}]`;
}
}
exports.Logger = Logger;

View File

@ -0,0 +1 @@
export declare function parseTaskTime(duration: number): string;

View File

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseTaskTime = void 0;
function parseTaskTime(duration) {
const seconds = Math.floor(duration / 1000);
const minutes = Math.floor(seconds / 60);
let parsedTime;
if (seconds === 0 && minutes === 0) {
parsedTime = `0.${Math.floor(duration / 100)}s`;
}
if (seconds > 0) {
parsedTime = `${seconds % 60}s`;
}
if (minutes > 0) {
parsedTime = `${minutes}m${parsedTime}`;
}
return parsedTime;
}
exports.parseTaskTime = parseTaskTime;

View File

@ -0,0 +1,12 @@
import { PromptOptions, PromptSettings } from './prompt.interface';
import { TaskWrapper } from '../lib/task-wrapper';
/**
* Create a new prompt with Enquirer externally.
* This extends enquirer so you dont have to give a name to single prompts and such so it is also
* useful to use externally.
* @param this
* @param options
* @param settings
*/
export declare function createPrompt(this: any, options: PromptOptions | PromptOptions<true>[], settings?: PromptSettings): Promise<any>;
export declare function destroyPrompt(this: TaskWrapper<any, any>, throwError?: boolean): void;

View File

@ -0,0 +1,129 @@
/// <reference types="node" />
import * as Enquirer from 'enquirer';
import { WriteStream } from 'fs';
import { Writable } from 'stream';
import { PromptError } from '../interfaces/listr-error.interface';
/** Returns all the prompt options depending on the type selected. */
export declare type PromptOptions<T extends boolean = false> = Unionize<{
[K in PromptTypes]-?: T extends true ? {
type: K;
} & PromptOptionsType<K> & {
name: string | (() => string);
} : {
type: K;
} & PromptOptionsType<K>;
}> | ({
type: string;
} & T extends true ? PromptOptionsType<string> & {
name: string | (() => string);
} : PromptOptionsType<string>);
export declare type Unionize<T extends Record<PropertyKey, unknown>> = {
[P in keyof T]: T[P];
}[keyof T];
interface BasePromptOptions {
message: string | (() => string) | (() => Promise<string>);
initial?: boolean | number | number[] | string | (() => string) | (() => Promise<string>);
required?: boolean;
stdin?: NodeJS.ReadStream;
stdout?: NodeJS.WriteStream;
header?: string;
footer?: string;
skip?(value: any): boolean | Promise<boolean>;
format?(value: any): any | Promise<any>;
result?(value: any): any | Promise<any>;
validate?(value: any, state: any): boolean | Promise<boolean> | string | Promise<string> | Promise<string | boolean>;
onSubmit?(name: any, value: any, prompt: Enquirer.Prompt): boolean | Promise<boolean>;
onCancel?(name: any, value: any, prompt: Enquirer.Prompt): boolean | Promise<boolean>;
}
interface BasePromptOptionsWithName extends BasePromptOptions {
name: string | (() => string);
}
interface ArrayPromptOptions extends BasePromptOptions {
choices: string[] | BasePromptOptionsWithName[];
maxChoices?: number;
multiple?: boolean;
initial?: number | number[];
delay?: number;
separator?: boolean;
sort?: boolean;
linebreak?: boolean;
edgeLength?: number;
align?: 'left' | 'right';
scroll?: boolean;
}
interface BooleanPromptOptions extends BasePromptOptions {
initial?: boolean | (() => string) | (() => Promise<string>);
}
interface StringPromptOptions extends BasePromptOptions {
initial?: string;
multiline?: boolean;
}
interface ScalePromptOptions extends ArrayPromptOptions {
scale: StringPromptOptions[];
margin?: [number, number, number, number];
}
interface NumberPromptOptions extends BasePromptOptions {
min?: number;
max?: number;
delay?: number;
float?: boolean;
round?: boolean;
major?: number;
minor?: number;
initial?: number;
}
interface SnippetPromptOptions extends BasePromptOptions {
newline?: string;
fields: Partial<BasePromptOptionsWithName>[];
template: string;
}
interface SortPromptOptions extends BasePromptOptions {
hint?: string;
drag?: boolean;
numbered?: boolean;
}
interface SurveyPromptOptions extends ArrayPromptOptions {
scale: BasePromptOptionsWithName[];
margin: [number, number, number, number];
}
interface QuizPromptOptions extends ArrayPromptOptions {
correctChoice: number;
}
interface TogglePromptOptions extends BasePromptOptions {
enabled?: string;
disabled?: string;
}
export declare type PromptTypes = 'AutoComplete' | 'BasicAuth' | 'Confirm' | 'Editable' | 'Form' | 'Input' | 'Invisible' | 'List' | 'MultiSelect' | 'Numeral' | 'Password' | 'Quiz' | 'Scale' | 'Select' | 'Snippet' | 'Sort' | 'Survey' | 'Text' | 'Toggle';
export declare type PromptOptionsType<T> = T extends keyof PromptOptionsMap ? PromptOptionsMap[T] : T extends string ? BasePromptOptions & Record<PropertyKey, unknown> : any;
export declare class PromptOptionsMap implements Record<PromptTypes, Record<PropertyKey, any>> {
AutoComplete: ArrayPromptOptions;
BasicAuth: StringPromptOptions;
Confirm: BooleanPromptOptions;
Editable: ArrayPromptOptions;
Form: ArrayPromptOptions;
Input: StringPromptOptions;
Invisible: StringPromptOptions;
List: ArrayPromptOptions;
MultiSelect: ArrayPromptOptions;
Numeral: NumberPromptOptions;
Password: StringPromptOptions;
Quiz: QuizPromptOptions;
Scale: ScalePromptOptions;
Select: ArrayPromptOptions;
Snippet: SnippetPromptOptions;
Sort: SortPromptOptions;
Survey: SurveyPromptOptions;
Text: StringPromptOptions;
Toggle: TogglePromptOptions;
}
export interface PromptSettings {
error?: boolean;
cancelCallback?: (settings?: PromptSettings) => string | Error | PromptError | void;
stdout?: WriteStream | Writable;
enquirer?: Enquirer;
}
export interface PromptInstance extends Omit<BasePromptOptions, 'onCancel' | 'onSubmit'> {
submit(): void;
cancel(err?: string): void;
}
export {};

View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

110
CyLukTs/lukan/node_modules/listr2/dist/utils/prompt.js generated vendored Normal file
View File

@ -0,0 +1,110 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.destroyPrompt = exports.createPrompt = void 0;
const event_constants_1 = require("../constants/event.constants");
const state_constants_1 = require("../constants/state.constants");
const listr_error_interface_1 = require("../interfaces/listr-error.interface");
const task_wrapper_1 = require("../lib/task-wrapper");
/**
* Create a new prompt with Enquirer externally.
* This extends enquirer so you dont have to give a name to single prompts and such so it is also
* useful to use externally.
* @param this
* @param options
* @param settings
*/
async function createPrompt(options, settings) {
// override cancel callback
let cancelCallback;
/* istanbul ignore if */
if (settings === null || settings === void 0 ? void 0 : settings.cancelCallback) {
cancelCallback = settings.cancelCallback;
} /* istanbul ignore next */
else {
cancelCallback = defaultCancelCallback;
}
// assign default if there is single prompt
if (!Array.isArray(options)) {
options = [{ ...options, name: 'default' }];
} /* istanbul ignore next */
else if (options.length === 1) {
options = options.reduce((o, option) => {
return [...o, Object.assign(option, { name: 'default' })];
}, []);
}
// assign default enquirer options
options = options.reduce((o, option) => {
var _a;
return [
...o,
Object.assign(option, {
// this is for outside calls, if it is not called from taskwrapper with bind
stdout: this instanceof task_wrapper_1.TaskWrapper ? (_a = settings === null || settings === void 0 ? void 0 : settings.stdout) !== null && _a !== void 0 ? _a : this.stdout() : process.stdout,
onCancel: cancelCallback.bind(this, settings)
})
];
}, []);
let enquirer;
if (settings === null || settings === void 0 ? void 0 : settings.enquirer) {
// injected enquirer
enquirer = settings.enquirer;
}
else {
try {
enquirer = new (await Promise.resolve().then(() => require('enquirer')))();
} /* istanbul ignore next */
catch (e) {
this.task.prompt = new listr_error_interface_1.PromptError('Enquirer is a peer dependency that must be installed separately.');
throw new Error(e);
}
}
// i use this externally as well, this is a bandaid
if (this instanceof task_wrapper_1.TaskWrapper) {
// Capture the prompt instance so we can use it later
enquirer.on('prompt', (prompt) => this.task.prompt = prompt);
// Clear the prompt instance once it's submitted
// Can't use on cancel, since that might hold a PromptError object
enquirer.on('submit', () => this.task.prompt = undefined);
this.task.subscribe((event) => {
if (event.type === event_constants_1.ListrEventType.STATE && event.data === state_constants_1.ListrTaskState.SKIPPED) {
if (this.task.prompt && !(this.task.prompt instanceof listr_error_interface_1.PromptError)) {
this.task.prompt.submit();
}
}
});
}
const response = (await enquirer.prompt(options));
// return default name if it is single prompt
if (options.length === 1) {
return response.default;
}
else {
return response;
}
}
exports.createPrompt = createPrompt;
function destroyPrompt(throwError = false) {
if (!this.task.prompt || this.task.prompt instanceof listr_error_interface_1.PromptError) {
// If there's no prompt, can't cancel
return;
}
if (throwError) {
this.task.prompt.cancel();
}
else {
this.task.prompt.submit();
}
}
exports.destroyPrompt = destroyPrompt;
function defaultCancelCallback(settings) {
const errorMsg = 'Cancelled prompt.';
if (this instanceof task_wrapper_1.TaskWrapper) {
this.task.prompt = new listr_error_interface_1.PromptError(errorMsg);
} /* istanbul ignore next */
else if ((settings === null || settings === void 0 ? void 0 : settings.error) !== false) {
throw new Error(errorMsg);
} /* istanbul ignore next */
else {
return errorMsg;
}
}

View File

@ -0,0 +1,3 @@
import { ListrOptions } from '../interfaces/listr.interface';
import { SupportedRenderer, ListrRendererValue } from '../interfaces/renderer.interface';
export declare function getRenderer(renderer: ListrRendererValue, fallbackRenderer?: ListrRendererValue, fallbackCondition?: ListrOptions['rendererFallback'], silentCondition?: ListrOptions['rendererSilent']): SupportedRenderer;

View File

@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRenderer = void 0;
const default_renderer_1 = require("../renderer/default.renderer");
const silent_renderer_1 = require("../renderer/silent.renderer");
const simple_renderer_1 = require("../renderer/simple.renderer");
const verbose_renderer_1 = require("../renderer/verbose.renderer");
const assert_1 = require("./assert");
const renderers = {
default: default_renderer_1.DefaultRenderer,
simple: simple_renderer_1.SimpleRenderer,
verbose: verbose_renderer_1.VerboseRenderer,
silent: silent_renderer_1.SilentRenderer
};
function isRendererSupported(renderer) {
return process.stdout.isTTY === true || renderer.nonTTY === true;
}
function getRendererClass(renderer) {
if (typeof renderer === 'string') {
return renderers[renderer] || renderers.default;
}
return typeof renderer === 'function' ? renderer : renderers.default;
}
function getRenderer(renderer, fallbackRenderer, fallbackCondition, silentCondition) {
let returnValue;
let ret = getRendererClass(renderer);
returnValue = { renderer: ret, nonTTY: false };
const evaluateSilent = (0, assert_1.assertFunctionOrSelf)(silentCondition);
const evaluateFallback = (0, assert_1.assertFunctionOrSelf)(fallbackCondition);
if (evaluateSilent) {
ret = getRendererClass('silent');
returnValue = { renderer: ret, nonTTY: true };
}
else if (!isRendererSupported(ret) || evaluateFallback) {
ret = getRendererClass(fallbackRenderer);
returnValue = { renderer: ret, nonTTY: true };
}
return returnValue;
}
exports.getRenderer = getRenderer;

View File

@ -0,0 +1,2 @@
/** Generate a basic uuid with no requirement of being unbelievable unique. */
export declare function generateUUID(): string;

12
CyLukTs/lukan/node_modules/listr2/dist/utils/uuid.js generated vendored Normal file
View File

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateUUID = void 0;
/** Generate a basic uuid with no requirement of being unbelievable unique. */
function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 || 0;
const v = c === 'x' ? r : r && 0x3 || 0x8;
return v.toString(16);
});
}
exports.generateUUID = generateUUID;