@@ -2,39 +2,59 @@ import { ChildProcess as BaseChildProcess, SpawnOptions } from 'child_process';
22import * as Rx from 'rxjs' ;
33import { EventEmitter , Writable } from 'stream' ;
44
5- /** Identifier for a command; if string, it's the command's name, if number, it's the index.*/
5+ /**
6+ * Identifier for a command; if string, it's the command's name, if number, it's the index.
7+ */
68export type CommandIdentifier = string | number ;
79
810export interface CommandInfo {
9- /** Command's name. */
11+ /**
12+ * Command's name.
13+ */
1014 name : string ;
1115
12- /** Which command line the command has. */
16+ /**
17+ * Which command line the command has.
18+ */
1319 command : string ;
1420
15- /** Which environment variables should the spawned process have.*/
21+ /**
22+ * Which environment variables should the spawned process have.
23+ */
1624 env ?: Record < string , unknown > ;
1725
18- /** The current working directory of the process when spawned.*/
26+ /**
27+ * The current working directory of the process when spawned.
28+ */
1929 cwd ?: string ;
2030
21- /** Color to use on prefix of the command.*/
31+ /**
32+ * Color to use on prefix of the command.
33+ */
2234 prefixColor ?: string ;
2335
24- /** Output command in raw format.*/
36+ /**
37+ * Output command in raw format.
38+ */
2539 raw ?: boolean ;
2640}
2741
2842export interface CloseEvent {
2943 command : CommandInfo ;
3044
31- /** The command's index among all commands ran.*/
45+ /**
46+ * The command's index among all commands ran.
47+ */
3248 index : number ;
3349
34- /** Whether the command exited because it was killed.*/
50+ /**
51+ * Whether the command exited because it was killed.
52+ */
3553 killed : boolean ;
3654
37- /** The exit code or signal for the command.*/
55+ /**
56+ * The exit code or signal for the command.
57+ */
3858 exitCode : string | number ;
3959 timings : {
4060 startDate : Date ;
@@ -48,14 +68,20 @@ export interface TimerEvent {
4868 endDate ?: Date ;
4969}
5070
51- /** Subtype of NodeJS's child_process including only what's actually needed for a command to work. */
71+ /**
72+ * Subtype of NodeJS's child_process including only what's actually needed for a command to work.
73+ */
5274export type ChildProcess = EventEmitter &
5375 Pick < BaseChildProcess , 'pid' | 'stdin' | 'stdout' | 'stderr' > ;
5476
55- /** Interface for a function that must kill the process with `pid`, optionally sending `signal` to it. */
77+ /**
78+ * Interface for a function that must kill the process with `pid`, optionally sending `signal` to it.
79+ */
5680export type KillProcess = ( pid : number , signal ?: string ) => void ;
5781
58- /** Interface for a function that spawns a command and returns its child process instance. */
82+ /**
83+ * Interface for a function that spawns a command and returns its child process instance.
84+ */
5985export type SpawnCommand = ( command : string , options : SpawnOptions ) => ChildProcess ;
6086
6187export class Command implements CommandInfo {
@@ -113,7 +139,9 @@ export class Command implements CommandInfo {
113139 this . spawnOpts = spawnOpts ;
114140 }
115141
116- /** Starts this command, piping output, error and close events onto the corresponding observables. */
142+ /**
143+ * Starts this command, piping output, error and close events onto the corresponding observables.
144+ */
117145 start ( ) {
118146 const child = this . spawn ( this . command , this . spawnOpts ) ;
119147 this . process = child ;
@@ -162,7 +190,9 @@ export class Command implements CommandInfo {
162190 this . stdin = child . stdin || undefined ;
163191 }
164192
165- /** Kills this command, optionally specifying a signal to send to it. */
193+ /**
194+ * Kills this command, optionally specifying a signal to send to it.
195+ */
166196 kill ( code ?: string ) {
167197 if ( Command . canKill ( this ) ) {
168198 this . killed = true ;
@@ -180,7 +210,9 @@ export class Command implements CommandInfo {
180210 }
181211}
182212
183- /** Pipes all events emitted by `stream` into `subject`.s */
213+ /**
214+ * Pipes all events emitted by `stream` into `subject`.
215+ */
184216function pipeTo < T > ( stream : Rx . Observable < T > , subject : Rx . Subject < T > ) {
185217 stream . subscribe ( ( event ) => subject . next ( event ) ) ;
186218}
0 commit comments