Skip to content

Commit 81e586b

Browse files
committed
progress bar, it's much better
1 parent 3a20ff3 commit 81e586b

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blackmad/api-diff",
3-
"version": "1.0.28",
3+
"version": "1.0.29",
44
"description": "",
55
"main": "index.js",
66
"scripts": {
@@ -28,10 +28,12 @@
2828
},
2929
"homepage": "https://github.com/radarlabs/api-diff#readme",
3030
"dependencies": {
31+
"@types/cli-progress": "^3.8.0",
3132
"axios": "^0.19.2",
3233
"axios-retry": "^3.1.8",
3334
"bluebird": "^3.7.2",
3435
"chalk": "^4.1.0",
36+
"cli-progress": "^3.8.2",
3537
"csv-parse": "^4.11.1",
3638
"csv-stringify": "^5.5.0",
3739
"dotenv": "^8.2.0",

src/api-diff/formatters/compare-formatter.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* eslint-disable no-console */
22
import * as fs from 'fs';
33
import * as stats from 'stats-lite';
4+
import CliProgress from 'cli-progress';
5+
46
import { Change } from '../change';
57
import { ApiEnv } from '../../apiEnv';
68
import { ParsedArgs } from '../argv';
@@ -12,17 +14,17 @@ export type FormatterConstructorParams = {
1214
newApiEnv: ApiEnv;
1315
argv: FormatterArgv;
1416
totalQueries: number;
15-
}
17+
};
1618

1719
export type PerHostFinishedStats = {
18-
statusCodes: Record<number, number>,
20+
statusCodes: Record<number, number>;
1921
responseTimes: number[];
20-
}
22+
};
2123

2224
export type FinishedStats = {
23-
new?: PerHostFinishedStats,
24-
old: PerHostFinishedStats
25-
}
25+
new?: PerHostFinishedStats;
26+
old: PerHostFinishedStats;
27+
};
2628

2729
/**
2830
* Convert list of response times to a dictionary of stats
@@ -59,6 +61,9 @@ export abstract class CompareFormatter {
5961

6062
numQueriesChanged = 0;
6163

64+
/** cli output */
65+
progressBar: CliProgress.SingleBar;
66+
6267
/** Called when a query has actually changed */
6368
abstract logChange(change: Change): void;
6469

@@ -72,9 +77,10 @@ export abstract class CompareFormatter {
7277
*/
7378
queryCompleted(change: Change): void {
7479
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+
});
7884

7985
if (!change.delta && !this.showUnchanged) {
8086
return;
@@ -131,6 +137,15 @@ export abstract class CompareFormatter {
131137
this.startDate = new Date();
132138
this.showUnchanged = argv.unchanged;
133139

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+
134149
const outputFilename = argv.output_file;
135150
if (outputFilename && outputFilename !== '-') {
136151
this.outputStream = fs.createWriteStream(outputFilename);

0 commit comments

Comments
 (0)