|
1 | 1 | import axios from 'axios';
|
2 | 2 | import { readJson } from 'fs-extra';
|
3 |
| -import { Metrics } from './shared/types'; |
4 | 3 | import { DefaultBenchCase, getCommitLink, getMetricsPath } from './shared';
|
5 | 4 |
|
6 | 5 | const productName = process.argv[2] || 'MODERNJS_FRAMEWORK';
|
@@ -77,13 +76,20 @@ export async function compare(productName: string) {
|
77 | 76 | process.argv[3] ||
|
78 | 77 | DefaultBenchCase[productName as keyof typeof DefaultBenchCase];
|
79 | 78 | const { jsonPath, remoteURL } = await getMetricsPath(productName, caseName);
|
80 |
| - const allMetrics: Metrics[] = |
| 79 | + |
| 80 | + const allMetrics = |
81 | 81 | process.env.MONITOR === '1'
|
82 | 82 | ? (await axios.get(remoteURL)).data
|
83 | 83 | : await readJson(jsonPath);
|
84 |
| - const keys = Object.keys(allMetrics); |
85 |
| - const currentKey = keys[keys.length - 1]; |
86 |
| - const baseKey = keys[keys.length - 2]; |
| 84 | + |
| 85 | + let arr = Object.keys(allMetrics).map(key => { |
| 86 | + return { key: key, value: allMetrics[key] }; |
| 87 | + }); |
| 88 | + |
| 89 | + arr.sort((a, b) => a.value.time - b.value.time); |
| 90 | + |
| 91 | + const currentKey = arr[arr.length - 1].key; |
| 92 | + const baseKey = arr[arr.length - 2].key; |
87 | 93 | const current = allMetrics[currentKey as any];
|
88 | 94 | const base = allMetrics[baseKey as any];
|
89 | 95 | const baseCommitLink = getCommitLink(productName, baseKey);
|
|
0 commit comments