@@ -21,8 +21,14 @@ export interface SignaleRendererOptions {
21
21
scope ?: Array < string > ;
22
22
}
23
23
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
+
24
30
export interface SignaleRendererOutput {
25
- type : 'debug' | 'ts' | 'td' ;
31
+ type : keyof typeof SignaleRendererOutputType ;
26
32
scope ?: Array < string > ;
27
33
messages : Array < unknown > ;
28
34
}
@@ -104,21 +110,21 @@ export class SignaleRenderer implements ListrRenderer {
104
110
if ( ! output . type || ! output . messages ) return ;
105
111
106
112
switch ( output . type ) {
107
- case 'ts' : {
113
+ case SignaleRendererOutputType . LISTR_TASK_START : {
108
114
this . getScopedLogger ( {
109
115
...rendererOptions ,
110
116
scope : output . scope ?? rendererOptions . scope ,
111
117
} ) . start ( output . messages . join ( '' ) ) ;
112
118
break ;
113
119
}
114
- case 'td' : {
120
+ case SignaleRendererOutputType . LISTR_TASK_COMPLETE : {
115
121
this . getScopedLogger ( {
116
122
...rendererOptions ,
117
123
scope : output . scope ?? rendererOptions . scope ,
118
124
} ) . success ( output . messages . join ( '' ) ) ;
119
125
break ;
120
126
}
121
- case 'debug' : {
127
+ case SignaleRendererOutputType . DEBUG : {
122
128
if ( output ?. messages && rendererOptions ?. verbose === 2 ) {
123
129
this . getScopedLogger ( {
124
130
...rendererOptions ,
@@ -154,7 +160,7 @@ export class ListrOutputLogger implements Logger {
154
160
if ( opts ?. showLogEntry && ! opts ?. showLogEntry ( { message, ...kvs } ) ) return ;
155
161
156
162
this . task . output = JSON . stringify ( {
157
- type : 'debug' ,
163
+ type : SignaleRendererOutputType . DEBUG ,
158
164
messages : [
159
165
`${ message } \n` ,
160
166
Object . entries ( kvs )
@@ -163,37 +169,4 @@ export class ListrOutputLogger implements Logger {
163
169
] ,
164
170
} satisfies SignaleRendererOutput ) ;
165
171
}
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
- }
199
172
}
0 commit comments