@schummar/runp
Version:
Neat parallel task execution
71 lines (70 loc) • 2.65 kB
TypeScript
import { RenderOptions } from '@schummar/react-terminal';
export interface RunpCommonOptions {
/** Maximum number of lines for each command output
* @default 10
*/
outputLength?: number;
/** Keep output of successful commands visible
* @default false
*/
keepOutput?: boolean;
/** Task will run forever. It won't display a spinner but a different symbol instead */
forever?: boolean;
/** Display time in status line if the task took more than the given ms */
displayTimeOver?: number;
linearOutput?: boolean;
}
export interface RunpCommand extends RunpCommonOptions {
/** Used to indentify dependencies */
id: string | number;
/** Command name. Only for display purposes. */
name?: string;
/** Program to execute */
cmd: string | ((feedback: RunpFeedback) => Promise<void>);
/** Args to pass into program */
args: string[];
/** Environment variables to set
* @default process.env
*/
env: NodeJS.ProcessEnv;
/** Wait with execution until job at that index is done
* @default false
*/
dependsOn: Array<string | number>;
/** Set cwd for command */
cwd: string;
subCommands?: RunpCommand[];
}
export interface RunpFeedback {
updateStatus(status: string): void;
updateTitle(title: string): void;
updateOutput(output: string): void;
}
export interface RunpCommandRaw extends Omit<Partial<RunpCommand>, 'args' | 'dependsOn' | 'subCommands'> {
cmd?: RunpCommand['cmd'];
args?: (string | false | undefined | null)[];
dependsOn?: string | number | Array<string | number>;
subCommands?: RunpCommandArg[];
}
export type RunpCommandArg = string | [cmd: string, ...args: string[]] | RunpCommandRaw | false | undefined | null;
export type RunpResult = {
result: 'success';
output: string;
} | {
result: 'error';
output: string;
};
export interface RunpOptions<TCommands extends RunpCommandArg[] = RunpCommandArg[]> extends RunpCommonOptions {
/** A list of command to execute in parallel */
commands: TCommands;
/** Maximum number of parallel tasks */
parallelTasks?: number;
target?: RenderOptions['target'];
}
export declare const DEFAULT_OUTPUT_LENGTH = 10;
export declare const RUNP_TASK_V = "N1BLAX3xSn-WvsKuLatw0";
export declare const RUNP_TASK_DELEGATE = "__runp_task__N1BLAX3xSn-WvsKuLatw0__";
export declare function runp<const TCommands extends RunpCommandArg[] = RunpCommandArg[]>(options: RunpOptions<TCommands>): Promise<{
[K in keyof TCommands]: RunpResult;
}>;
export declare function resolveCommands(options: RunpOptions): Promise<RunpCommand[]>;