@@ -2,11 +2,8 @@ import type { ChildProcess } from 'child_process';
2
2
import { spawn } from 'child_process' ;
3
3
4
4
import { getEnvConfig } from '../config/config' ;
5
- import { TerminalColors } from '../terminal/TerminalColors' ;
6
5
import type { Logger } from '../util/Logger' ;
7
-
8
- const NEWLINE_SEPARATOR = / \r \n | \r | \n / ;
9
- const OUTPUT_PREFIX = / ^ ( [ a - z ] + : ( [ \s ] { 4 } | [ \s ] { 3 } ) ) / ;
6
+ import { EFOutputParser } from './EFOutputParser' ;
10
7
11
8
export type ExecOpts = {
12
9
cmdArgs : string [ ] ;
@@ -29,67 +26,6 @@ export type ExecProcess = {
29
26
export class CLI {
30
27
constructor ( private readonly logger : Logger ) { }
31
28
32
- public static getDataFromStdOut ( output : string ) : string {
33
- return this . stripPrefixFromStdOut (
34
- output
35
- . split ( NEWLINE_SEPARATOR )
36
- . filter ( line => line . startsWith ( 'data:' ) )
37
- . join ( '\n' ) ,
38
- ) ;
39
- }
40
-
41
- public static getErrorsFromStdOut ( output : string ) : string {
42
- return this . stripPrefixFromStdOut (
43
- output
44
- . split ( NEWLINE_SEPARATOR )
45
- . filter ( line => line . startsWith ( 'error:' ) )
46
- . join ( '\n' ) ,
47
- ) ;
48
- }
49
-
50
- private static filter ( out : string , prefix : string ) {
51
- return out
52
- . split ( NEWLINE_SEPARATOR )
53
- . filter ( line => ! line . trim ( ) . startsWith ( prefix ) )
54
- . join ( '\n' ) ;
55
- }
56
-
57
- public static filterInfoFromOutput ( out : string ) : string {
58
- return this . filter ( out , 'info:' ) ;
59
- }
60
-
61
- public static filterDataFromOutput ( out : string ) : string {
62
- return this . filter ( out , 'data:' ) ;
63
- }
64
-
65
- public static colorizeOutput ( output : string ) : string {
66
- return output
67
- . split ( NEWLINE_SEPARATOR )
68
- . map ( line => {
69
- if ( line . startsWith ( 'warn:' ) ) {
70
- return (
71
- line . replace ( OUTPUT_PREFIX , `$1${ TerminalColors . yellow } ` ) +
72
- TerminalColors . reset
73
- ) ;
74
- }
75
- if ( line . startsWith ( 'error:' ) ) {
76
- return (
77
- line . replace ( OUTPUT_PREFIX , `$1${ TerminalColors . red } ` ) +
78
- TerminalColors . reset
79
- ) ;
80
- }
81
- return line ;
82
- } )
83
- . join ( '\n' ) ;
84
- }
85
-
86
- public static stripPrefixFromStdOut ( output : string ) : string {
87
- return output
88
- . split ( NEWLINE_SEPARATOR )
89
- . map ( line => line . replace ( OUTPUT_PREFIX , '' ) )
90
- . join ( '\n' ) ;
91
- }
92
-
93
29
private getInterpolatedArgs (
94
30
args : string [ ] ,
95
31
params : { [ key : string ] : string } ,
@@ -117,12 +53,14 @@ export class CLI {
117
53
118
54
const args = interpolatedArgs . concat ( additionalArgs ) ;
119
55
56
+ const envConfig = getEnvConfig ( ) ;
57
+
120
58
const cmd = spawn ( args [ 0 ] , args . slice ( 1 ) , {
121
59
cwd,
122
60
shell : true ,
123
61
env : {
124
62
...process . env ,
125
- ...getEnvConfig ( ) ,
63
+ ...envConfig ,
126
64
} ,
127
65
} ) ;
128
66
@@ -149,10 +87,12 @@ export class CLI {
149
87
} ) ;
150
88
151
89
cmd ?. on ( 'exit' , async code => {
152
- const error = stderr || CLI . getErrorsFromStdOut ( stdout ) ;
90
+ const error = stderr || EFOutputParser . parse ( stdout ) . errors ;
153
91
if ( error || code !== 0 ) {
154
92
handlers ?. onStdOut ?.( `Exited with code ${ code } \n` ) ;
155
- const finalError = CLI . filterInfoFromOutput ( error || stdout ) ;
93
+ const finalError = EFOutputParser . filterInfoFromOutput (
94
+ error || stdout ,
95
+ ) ;
156
96
rej ( new Error ( finalError ) ) ;
157
97
} else {
158
98
res ( stdout ) ;
0 commit comments