1 |
|
2 |
|
3 |
|
4 |
|
5 | import { ChildProcess as BaseChildProcess, SpawnOptions } from 'child_process';
|
6 | import * as Rx from 'rxjs';
|
7 | import { EventEmitter, Writable } from 'stream';
|
8 |
|
9 |
|
10 |
|
11 | export type CommandIdentifier = string | number;
|
12 | export interface CommandInfo {
|
13 | |
14 |
|
15 |
|
16 | name: string;
|
17 | |
18 |
|
19 |
|
20 | command: string;
|
21 | |
22 |
|
23 |
|
24 | env?: Record<string, unknown>;
|
25 | |
26 |
|
27 |
|
28 | cwd?: string;
|
29 | |
30 |
|
31 |
|
32 | prefixColor?: string;
|
33 | |
34 |
|
35 |
|
36 | raw?: boolean;
|
37 | }
|
38 | export interface CloseEvent {
|
39 | command: CommandInfo;
|
40 | |
41 |
|
42 |
|
43 | index: number;
|
44 | |
45 |
|
46 |
|
47 | killed: boolean;
|
48 | |
49 |
|
50 |
|
51 | exitCode: string | number;
|
52 | timings: {
|
53 | startDate: Date;
|
54 | endDate: Date;
|
55 | durationSeconds: number;
|
56 | };
|
57 | }
|
58 | export interface TimerEvent {
|
59 | startDate: Date;
|
60 | endDate?: Date;
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 | export type ChildProcess = EventEmitter & Pick<BaseChildProcess, 'pid' | 'stdin' | 'stdout' | 'stderr'>;
|
66 |
|
67 |
|
68 |
|
69 | export type KillProcess = (pid: number, signal?: string) => void;
|
70 |
|
71 |
|
72 |
|
73 | export type SpawnCommand = (command: string, options: SpawnOptions) => ChildProcess;
|
74 | export declare class Command implements CommandInfo {
|
75 | private readonly killProcess;
|
76 | private readonly spawn;
|
77 | private readonly spawnOpts;
|
78 | readonly index: number;
|
79 |
|
80 | readonly name: string;
|
81 |
|
82 | readonly command: string;
|
83 |
|
84 | readonly prefixColor?: string;
|
85 |
|
86 | readonly env: Record<string, unknown>;
|
87 |
|
88 | readonly cwd?: string;
|
89 | readonly close: Rx.Subject<CloseEvent>;
|
90 | readonly error: Rx.Subject<unknown>;
|
91 | readonly stdout: Rx.Subject<Buffer>;
|
92 | readonly stderr: Rx.Subject<Buffer>;
|
93 | readonly timer: Rx.Subject<TimerEvent>;
|
94 | process?: ChildProcess;
|
95 | stdin?: Writable;
|
96 | pid?: number;
|
97 | killed: boolean;
|
98 | exited: boolean;
|
99 |
|
100 | get killable(): boolean;
|
101 | constructor({ index, name, command, prefixColor, env, cwd }: CommandInfo & {
|
102 | index: number;
|
103 | }, spawnOpts: SpawnOptions, spawn: SpawnCommand, killProcess: KillProcess);
|
104 | /**
|
105 | * Starts this command, piping output, error and close events onto the corresponding observables.
|
106 | */
|
107 | start(): void;
|
108 | /**
|
109 | * Kills this command, optionally specifying a signal to send to it.
|
110 | */
|
111 | kill(code?: string): void;
|
112 | /**
|
113 | * Detects whether a command can be killed.
|
114 | *
|
115 | * Also works as a type guard on the input `command`.
|
116 | */
|
117 | static canKill(command: Command): command is Command & {
|
118 | pid: number;
|
119 | process: ChildProcess;
|
120 | };
|
121 | }
|