@@ -21,8 +21,14 @@ export interface SignaleRendererOptions {
2121 scope ?: Array < string > ;
2222}
2323
24+ export const SignaleRendererOutputType = {
25+ DEBUG : 'DEBUG' ,
26+ LISTR_TASK_START : 'LISTR_TASK_START' ,
27+ LISTR_TASK_COMPLETE : 'LISTR_TASK_COMPLETE' ,
28+ } as const ;
29+
2430export interface SignaleRendererOutput {
25- type : 'debug' | 'ts' | 'td' ;
31+ type : keyof typeof SignaleRendererOutputType ;
2632 scope ?: Array < string > ;
2733 messages : Array < unknown > ;
2834}
@@ -104,21 +110,21 @@ export class SignaleRenderer implements ListrRenderer {
104110 if ( ! output . type || ! output . messages ) return ;
105111
106112 switch ( output . type ) {
107- case 'ts' : {
113+ case SignaleRendererOutputType . LISTR_TASK_START : {
108114 this . getScopedLogger ( {
109115 ...rendererOptions ,
110116 scope : output . scope ?? rendererOptions . scope ,
111117 } ) . start ( output . messages . join ( '' ) ) ;
112118 break ;
113119 }
114- case 'td' : {
120+ case SignaleRendererOutputType . LISTR_TASK_COMPLETE : {
115121 this . getScopedLogger ( {
116122 ...rendererOptions ,
117123 scope : output . scope ?? rendererOptions . scope ,
118124 } ) . success ( output . messages . join ( '' ) ) ;
119125 break ;
120126 }
121- case 'debug' : {
127+ case SignaleRendererOutputType . DEBUG : {
122128 if ( output ?. messages && rendererOptions ?. verbose === 2 ) {
123129 this . getScopedLogger ( {
124130 ...rendererOptions ,
@@ -154,7 +160,7 @@ export class ListrOutputLogger implements Logger {
154160 if ( opts ?. showLogEntry && ! opts ?. showLogEntry ( { message, ...kvs } ) ) return ;
155161
156162 this . task . output = JSON . stringify ( {
157- type : 'debug' ,
163+ type : SignaleRendererOutputType . DEBUG ,
158164 messages : [
159165 `${ message } \n` ,
160166 Object . entries ( kvs )
@@ -163,37 +169,4 @@ export class ListrOutputLogger implements Logger {
163169 ] ,
164170 } satisfies SignaleRendererOutput ) ;
165171 }
166-
167- axiosDebug ( resp : AxiosResponse , desc ?: string ) : void {
168- const config = resp . config ;
169-
170- const capitalizeFirstLetter = ( str : string ) =>
171- str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
172-
173- // NodeJS will not keep the response header in Xxx-Xxx format, correct it
174- const normalizeHeaderKey = ( key : string ) =>
175- key . split ( '-' ) . map ( capitalizeFirstLetter ) . join ( '-' ) ;
176-
177- // Transforms HTTP headers to a single line of text formatting
178- const transformHeaders = ( headers : object , normalizeKey = false ) =>
179- Object . entries ( headers ) . map (
180- ( [ key , value ] ) =>
181- `${ normalizeKey ? normalizeHeaderKey ( key ) : key } : ${ key !== 'X-API-KEY' ? value : '*****' } \n` ,
182- ) ;
183- this . task . output = JSON . stringify ( {
184- type : 'debug' ,
185- messages : [
186- `${ desc ?? '' } \n` , //TODO time consumption
187- // request
188- `${ config . method . toUpperCase ( ) } ${ axios . getUri ( config ) } \n` ,
189- ...transformHeaders ( config . headers ) ,
190- config ?. data ? `\n${ config . data } \n` : '' ,
191- '\n' ,
192- // response
193- `${ resp . status } ${ resp . statusText } \n` ,
194- ...transformHeaders ( resp . headers , true ) ,
195- `${ resp ?. data ? `\n${ JSON . stringify ( resp . data ) } ` : '' } \n` ,
196- ] ,
197- } satisfies SignaleRendererOutput ) ;
198- }
199172}
0 commit comments