@@ -11,33 +11,29 @@ export default class Process extends EventEmitter {
11
11
start ( args ) {
12
12
logger . log ( 'Starting process:' , this . command , ( args || [ ] ) . join ( ' ' ) ) ;
13
13
14
- // Spawn process
15
- const { process, stop, push } = api . spawnProcess ( this . command , args ) ;
16
-
17
- // Connect handlers
18
- process . stdout . on ( 'data' , data => {
19
- this . emit ( 'stdout' , data ) ;
20
- } ) ;
21
-
22
- process . stderr . on ( 'data' , data => {
23
- this . emit ( 'stderr' , data ) ;
24
- } ) ;
25
-
26
- process . on ( 'close' , ( code , signal ) => {
27
- logger . log ( 'Process ended with code' , code , 'and signal' , signal ) ;
14
+ const handlers = {
15
+ onStdOut : data => {
16
+ this . emit ( 'data' , data ) ;
17
+ } ,
18
+ onStdErr : data => {
19
+ this . emit ( 'data' , data ) ;
20
+ } ,
21
+ onClose : ( code , signal ) => {
22
+ logger . log ( 'Process ended with code' , code , 'and signal' , signal ) ;
23
+
24
+ this . emit ( 'close' , code , signal ) ;
25
+ } ,
26
+ onExit : ( code , signal ) => {
27
+ this . emit ( 'exit' , code , signal ) ;
28
+ } ,
29
+ onError : err => {
30
+ this . emit ( 'error' , err ) ;
31
+ } ,
32
+ } ;
28
33
29
- this . emit ( 'close' , code , signal ) ;
30
- } ) ;
31
-
32
- process . on ( 'exit' , ( code , signal ) => {
33
- this . emit ( 'exit' , code , signal ) ;
34
- } ) ;
35
-
36
- process . on ( 'error' , err => {
37
- this . emit ( 'error' , err ) ;
38
- } ) ;
34
+ // Spawn process
35
+ const { stop, push } = api . spawnProcess ( this . command , args , handlers ) ;
39
36
40
- this . process = process ;
41
37
this . stop = stop ;
42
38
this . push = push ;
43
39
0 commit comments