@@ -24,6 +24,9 @@ class CustomSpinnerBar {
2424 this . lastProgressValue = - 1 ;
2525 this . renderCount = 0 ;
2626
27+ this . startTime = null ;
28+ this . showTimestamps = options . showTimestamps !== false ;
29+
2730 // Only render every 10th frame to reduce I/O operations
2831 this . renderThrottle = 10 ;
2932
@@ -42,6 +45,7 @@ class CustomSpinnerBar {
4245 this . isSpinning = true ;
4346 this . frameIndex = 0 ;
4447 this . renderCount = 0 ;
48+ this . startTime = Date . now ( ) ;
4549 this . resetProgressBar ( ) ;
4650 this . progressBar . start ( ) ;
4751
@@ -73,12 +77,38 @@ class CustomSpinnerBar {
7377 return this ;
7478 }
7579
80+ getElapsedTime ( ) {
81+ if ( ! this . startTime ) return 0 ;
82+ return this . formatTime ( Date . now ( ) - this . startTime ) ;
83+ }
84+
85+ formatTime ( milliseconds ) {
86+ const seconds = Math . floor ( milliseconds / 1000 ) ;
87+ const ms = milliseconds % 1000 ;
88+
89+ if ( seconds < 60 ) {
90+ return `${ seconds } .${ Math . floor ( ms / 100 ) } s` ;
91+ }
92+
93+ const minutes = Math . floor ( seconds / 60 ) ;
94+ const remainingSeconds = seconds % 60 ;
95+ return `${ minutes } m ${ remainingSeconds } s` ;
96+ }
97+
98+ getTimestamp ( ) {
99+ const now = new Date ( ) ;
100+ return now . toTimeString ( ) . split ( ' ' ) [ 0 ] ;
101+ }
102+
76103 succeed ( text ) {
77104 if ( global ?. verbose ) return this ;
78105 this . stop ( ) ;
79106
80107 this . progressBar . setProgress ( this . progressBar . total ) ;
81- const output = `${ chalk . green ( "✔" ) } ${ text || this . text } ${ this . progressBar . render ( ) } ` ;
108+ const finalText = text || this . text ;
109+ const timeInfo = this . showTimestamps ?
110+ chalk . gray ( ` [${ this . getTimestamp ( ) } ] (${ this . getElapsedTime ( ) } )` ) : '' ;
111+ const output = `${ chalk . green ( "✔" ) } ${ finalText } ${ this . progressBar . render ( ) } ${ timeInfo } ` ;
82112 this . clearLine ( ) ;
83113 this . writeLine ( output ) ;
84114 return this ;
@@ -91,24 +121,31 @@ class CustomSpinnerBar {
91121 if ( global . logDirectory ) {
92122 finalText += chalk . gray ( " Check logs at: " ) + chalk . cyan ( global . logDirectory ) ;
93123 }
124+
125+ const timeInfo = this . showTimestamps ?
126+ chalk . gray ( ` [${ this . getTimestamp ( ) } ] (${ this . getElapsedTime ( ) } )` ) : '' ;
94127 this . clearLine ( ) ;
95- this . writeLine ( `${ chalk . red ( '✖' ) } ${ chalk . bold . red ( finalText ) } ` ) ;
128+ this . writeLine ( `${ chalk . red ( '✖' ) } ${ chalk . bold . red ( finalText ) } ${ timeInfo } ` ) ;
96129 process . exit ( 1 ) ;
97130 }
98131
99132 info ( text ) {
100133 if ( global . verbose ) return this ;
101134 this . stop ( ) ;
135+ const timeInfo = this . showTimestamps ?
136+ chalk . gray ( ` [${ this . getTimestamp ( ) } ]` ) : '' ;
102137 this . clearLine ( ) ;
103- this . writeLine ( `${ chalk . blue ( "ℹ" ) } ${ text || this . text } ` ) ;
138+ this . writeLine ( `${ chalk . blue ( "ℹ" ) } ${ text || this . text } ${ timeInfo } ` ) ;
104139 return this ;
105140 }
106141
107142 warn ( text ) {
108143 if ( global . verbose ) return this ;
109144 this . stop ( ) ;
145+ const timeInfo = this . showTimestamps ?
146+ chalk . gray ( ` [${ this . getTimestamp ( ) } ]` ) : '' ;
110147 this . clearLine ( ) ;
111- this . writeLine ( `${ chalk . yellow ( "⚠" ) } ${ text || this . text } ` ) ;
148+ this . writeLine ( `${ chalk . yellow ( "⚠" ) } ${ text || this . text } ${ timeInfo } ` ) ;
112149 return this ;
113150 }
114151
@@ -195,6 +232,11 @@ class CustomSpinnerBar {
195232 this . progressBar . disable ( ) ;
196233 return this ;
197234 }
235+
236+ setShowTimestamps ( show ) {
237+ this . showTimestamps = show ;
238+ return this ;
239+ }
198240}
199241
200242// Exporting singleton instance and function for new instance
0 commit comments