UNPKG

@altostra/core

Version:

Core library for shared types and logic

94 lines (93 loc) 3.61 kB
/// <reference types="node" /> import type { ChildProcess, SpawnOptions } from 'child_process'; /** * A process exit status */ export interface ExitStatus { /** * Exit code of the process, or null if it was terminated */ code: number | null; /** * The signal (if any) that terminated the process */ signal: string | null; } export interface SuccessfulExitStatus extends ExitStatus { code: 0; signal: null; } export interface SpawnAndWaitOptions extends SpawnOptions { /** * If `true` reject the result promise on non-zero exit code. */ throwOnNoZeroExit?: boolean; handleChildProcess?: (childProc: ChildProcess) => unknown; } export interface SpawnAndWaitForSuccessOptions extends SpawnAndWaitOptions { /** * If `true` reject the result promise on non-zero exit code. */ throwOnNoZeroExit: true; } /** * Spawns a new process, and return a promise that is resolved when the process exists * @param cmd The command to execute * @param options Spawn options * @returns A promise that would be resolved with the process exit status when the process would exit or terminate. \ * If the process would exit with non-zero exit code, the promise would be rejected */ export declare function spawnAndWait(cmd: string, options: SpawnAndWaitForSuccessOptions): Promise<SuccessfulExitStatus>; /** * Spawns a new process, and return a promise that is resolved when the process exists * @param cmd The command to execute * @param options Spawn options * @returns A promise that would be resolved with the process exit status when the process would exit or terminate */ export declare function spawnAndWait(cmd: string, options?: SpawnAndWaitOptions): Promise<ExitStatus>; /** * Spawns a new process, and return a promise that is resolved when the process exists * @param cmd The command to execute * @param args Array of command arguments * @param options Spawn options * @returns A promise that would be resolved with the process exit status when the process would exit or terminate. \ * If the process would exit with non-zero exit code, the promise would be rejected */ export declare function spawnAndWait(cmd: string, args: string[], options: SpawnAndWaitForSuccessOptions): Promise<SuccessfulExitStatus>; /** * Spawns a new process, and return a promise that is resolved when the process exists * @param cmd The command to execute * @param args Array of command arguments * @param options Spawn options * @returns A promise that would be resolved with the process exit status when the process would exit or terminate */ export declare function spawnAndWait(cmd: string, args: string[], options?: SpawnAndWaitOptions): Promise<ExitStatus>; /** * Piping options for each io-stream */ export interface PipeChildProcStdioOptions { /** * Set to `false` to prevent piping of stdin */ stdin: boolean; /** * Set to `false` to prevent piping of stdout */ stdout: boolean; /** * Set to `false` to prevent piping of stderr */ stderr: boolean; } export interface Pipes { stdout: NodeJS.WriteStream; stderr: NodeJS.WriteStream; stdin: ReturnType<typeof process['stdin']['pipe']>; } /** * Pipes child process IO streams to this process streams * @param childProc The child-process to pipe io to and from * @param options Optional options to disable specific io * @returns Pipe streams of the piped io */ export declare function pipeChildProcStdio<FDs extends PipeChildProcStdioOptions = PipeChildProcStdioOptions>(childProc: ChildProcess, options?: Partial<FDs>): Partial<Pipes>;