1
1
/* eslint-disable no-console */
2
2
import * as fs from 'fs' ;
3
3
import * as stats from 'stats-lite' ;
4
+ import CliProgress from 'cli-progress' ;
5
+
4
6
import { Change } from '../change' ;
5
7
import { ApiEnv } from '../../apiEnv' ;
6
8
import { ParsedArgs } from '../argv' ;
@@ -12,17 +14,17 @@ export type FormatterConstructorParams = {
12
14
newApiEnv : ApiEnv ;
13
15
argv : FormatterArgv ;
14
16
totalQueries : number ;
15
- }
17
+ } ;
16
18
17
19
export type PerHostFinishedStats = {
18
- statusCodes : Record < number , number > ,
20
+ statusCodes : Record < number , number > ;
19
21
responseTimes : number [ ] ;
20
- }
22
+ } ;
21
23
22
24
export type FinishedStats = {
23
- new ?: PerHostFinishedStats ,
24
- old : PerHostFinishedStats
25
- }
25
+ new ?: PerHostFinishedStats ;
26
+ old : PerHostFinishedStats ;
27
+ } ;
26
28
27
29
/**
28
30
* Convert list of response times to a dictionary of stats
@@ -59,6 +61,9 @@ export abstract class CompareFormatter {
59
61
60
62
numQueriesChanged = 0 ;
61
63
64
+ /** cli output */
65
+ progressBar : CliProgress . SingleBar ;
66
+
62
67
/** Called when a query has actually changed */
63
68
abstract logChange ( change : Change ) : void ;
64
69
@@ -72,9 +77,10 @@ export abstract class CompareFormatter {
72
77
*/
73
78
queryCompleted ( change : Change ) : void {
74
79
this . numQueriesRun += 1 ;
75
- if ( this . numQueriesRun % 10 === 0 ) {
76
- console . error ( `IN PROGRESS. ${ this . numQueriesRun } /${ this . totalQueries } run` ) ;
77
- }
80
+
81
+ this . progressBar . update ( this . numQueriesRun , {
82
+ numChanged : this . numQueriesChanged ,
83
+ } ) ;
78
84
79
85
if ( ! change . delta && ! this . showUnchanged ) {
80
86
return ;
@@ -131,6 +137,15 @@ export abstract class CompareFormatter {
131
137
this . startDate = new Date ( ) ;
132
138
this . showUnchanged = argv . unchanged ;
133
139
140
+ this . progressBar = new CliProgress . SingleBar ( {
141
+ etaBuffer : 250 ,
142
+ format :
143
+ 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | {numChanged} changed' ,
144
+ } ) ;
145
+ this . progressBar . start ( totalQueries , 0 , {
146
+ numChanged : 0 ,
147
+ } ) ;
148
+
134
149
const outputFilename = argv . output_file ;
135
150
if ( outputFilename && outputFilename !== '-' ) {
136
151
this . outputStream = fs . createWriteStream ( outputFilename ) ;
0 commit comments