@@ -2,11 +2,8 @@ import type { ChildProcess } from 'child_process';
22import { spawn } from 'child_process' ;
33
44import { getEnvConfig } from '../config/config' ;
5- import { TerminalColors } from '../terminal/TerminalColors' ;
65import 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' ;
107
118export type ExecOpts = {
129 cmdArgs : string [ ] ;
@@ -29,67 +26,6 @@ export type ExecProcess = {
2926export class CLI {
3027 constructor ( private readonly logger : Logger ) { }
3128
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-
9329 private getInterpolatedArgs (
9430 args : string [ ] ,
9531 params : { [ key : string ] : string } ,
@@ -117,12 +53,14 @@ export class CLI {
11753
11854 const args = interpolatedArgs . concat ( additionalArgs ) ;
11955
56+ const envConfig = getEnvConfig ( ) ;
57+
12058 const cmd = spawn ( args [ 0 ] , args . slice ( 1 ) , {
12159 cwd,
12260 shell : true ,
12361 env : {
12462 ...process . env ,
125- ...getEnvConfig ( ) ,
63+ ...envConfig ,
12664 } ,
12765 } ) ;
12866
@@ -149,10 +87,12 @@ export class CLI {
14987 } ) ;
15088
15189 cmd ?. on ( 'exit' , async code => {
152- const error = stderr || CLI . getErrorsFromStdOut ( stdout ) ;
90+ const error = stderr || EFOutputParser . parse ( stdout ) . errors ;
15391 if ( error || code !== 0 ) {
15492 handlers ?. onStdOut ?.( `Exited with code ${ code } \n` ) ;
155- const finalError = CLI . filterInfoFromOutput ( error || stdout ) ;
93+ const finalError = EFOutputParser . filterInfoFromOutput (
94+ error || stdout ,
95+ ) ;
15696 rej ( new Error ( finalError ) ) ;
15797 } else {
15898 res ( stdout ) ;
0 commit comments