@@ -28,43 +28,41 @@ const bigIntStringify = <T>(value: T): string => {
2828 ) ;
2929} ;
3030
31+ let IS_PREV_JSON_LOG = false ;
32+
3133export const createConsole = (
3234 headMessage : HeadMessage ,
3335 type : 'info' | 'error' | 'table' | 'bold' = 'info' ,
3436) => {
3537 return < T , U > ( ...args : T [ ] | U [ ] ) => {
38+ // print comma if previous log is JSON to separate logs
39+ if ( IS_PREV_JSON_LOG ) {
40+ console . info ( ',' ) ;
41+ }
42+ // set flag so that next log can check if previous log is JSON and print comma
43+ if ( program . opts ( ) . json ) {
44+ IS_PREV_JSON_LOG = true ;
45+ }
46+
3647 switch ( type ) {
3748 case 'table' :
3849 if ( program . opts ( ) . json ) {
39- console . info ( `\n${ getColoredLog ( headMessage , headMessage + ':' ) } ` ) ;
40- console . info ( '<JSON>' ) ;
41- console . info ( bigIntStringify ( args ) ) ;
42- console . info ( '</JSON>' ) ;
43- return ;
50+ return console . info ( bigIntStringify ( args ) ) ;
4451 }
4552 console . info ( `\n${ getColoredLog ( headMessage , headMessage + ':' ) } ` ) ;
46- console . table ( ...args ) ;
47- break ;
53+ return console . table ( ...args ) ;
54+
4855 case 'bold' :
4956 if ( program . opts ( ) . json ) {
50- console . info ( `\n${ getColoredLog ( headMessage , headMessage + ':' ) } ` ) ;
51- console . info ( '<JSON>' ) ;
52- console . info ( bigIntStringify ( { Result : args } ) ) ;
53- console . info ( '</JSON>' ) ;
54- return ;
57+ return console . info ( bigIntStringify ( { result : args } ) ) ;
5558 }
56- console . info ( getColoredLog ( headMessage , args ) ) ;
57- break ;
59+ return console . info ( getColoredLog ( headMessage , args ) ) ;
5860 default :
5961 if ( program . opts ( ) . json ) {
60- console . info ( `\n${ getColoredLog ( headMessage , headMessage + ':' ) } ` ) ;
61- console . info ( '<JSON>' ) ;
62- console . info ( bigIntStringify ( { Result : args } ) ) ;
63- console . info ( '</JSON>' ) ;
64- return ;
62+ return console . info ( bigIntStringify ( { result : args } ) ) ;
6563 }
6664 // eslint-disable-next-line no-console
67- console [ type ] (
65+ return console [ type ] (
6866 `\n${ getColoredLog ( headMessage , headMessage + ':' ) } ` ,
6967 ...args ,
7068 ) ;
@@ -80,10 +78,14 @@ const createTable = (headMessage?: HeadMessage) => (args: CreateTableArgs) => {
8078 if ( ! data ) return ;
8179
8280 if ( program . opts ( ) . json ) {
83- console . info ( '<JSON>' ) ;
84- console . info ( bigIntStringify ( { Result : data } ) ) ;
85- console . info ( '</JSON>' ) ;
86- return ;
81+ // print comma if previous log is JSON to separate logs
82+ if ( IS_PREV_JSON_LOG ) {
83+ console . info ( ',' ) ;
84+ }
85+
86+ IS_PREV_JSON_LOG = true ;
87+
88+ return console . info ( bigIntStringify ( { result : data } ) ) ;
8789 } else {
8890 const table = new Table ( { ...TABLE_PARAMS , ...params } ) ;
8991 table . push ( ...data ) ;
0 commit comments