@rn-perf-kit/cli 0.0.0-stage ā 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +134 -0
- package/package.json +19 -4
- package/src/cli.ts +104 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +5 -0
- package/README.md +0 -3
package/dist/cli.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* rn-perf CLI (compiled CommonJS binary)
|
|
4
|
+
*
|
|
5
|
+
* Commands:
|
|
6
|
+
* rn-perf compare <base.json> <pr.json>
|
|
7
|
+
* rn-perf check --budgets <config> --report <session.json>
|
|
8
|
+
* rn-perf html <session.json> [--output <report.html>]
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const { readFileSync, writeFileSync, existsSync } = require('fs');
|
|
12
|
+
const { resolve } = require('path');
|
|
13
|
+
|
|
14
|
+
const [, , command, ...args] = process.argv;
|
|
15
|
+
|
|
16
|
+
function die(msg) {
|
|
17
|
+
console.error(`[rn-perf] ${msg}`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function readJson(filePath) {
|
|
22
|
+
const abs = resolve(process.cwd(), filePath);
|
|
23
|
+
if (!existsSync(abs)) die(`File not found: ${abs}`);
|
|
24
|
+
return JSON.parse(readFileSync(abs, 'utf-8'));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getPath(obj, path) {
|
|
28
|
+
return path.split('.').reduce((o, k) => o?.[k], obj) ?? 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
switch (command) {
|
|
32
|
+
case 'compare': {
|
|
33
|
+
const [basePath, prPath] = args;
|
|
34
|
+
if (!basePath || !prPath) die('Usage: rn-perf compare <base.json> <pr.json>');
|
|
35
|
+
const base = readJson(basePath);
|
|
36
|
+
const pr = readJson(prPath);
|
|
37
|
+
console.log('\nš rn-perf session comparison\n');
|
|
38
|
+
console.log(`Base: ${basePath}`);
|
|
39
|
+
console.log(`PR: ${prPath}\n`);
|
|
40
|
+
const fields = [
|
|
41
|
+
['Jank %', 'summary.jankPct', '%'],
|
|
42
|
+
['JS Stalls', 'summary.jsStalls', ''],
|
|
43
|
+
['Total Commits', 'summary.totalCommits', ''],
|
|
44
|
+
['Navigations', 'summary.navigations', ''],
|
|
45
|
+
];
|
|
46
|
+
for (const [label, path, unit] of fields) {
|
|
47
|
+
const bv = getPath(base, path);
|
|
48
|
+
const pv = getPath(pr, path);
|
|
49
|
+
const delta = pv - bv;
|
|
50
|
+
const color = delta > 0 ? '\x1b[31m' : delta < 0 ? '\x1b[32m' : '\x1b[0m';
|
|
51
|
+
const sign = delta > 0 ? '+' : '';
|
|
52
|
+
console.log(` ${label.padEnd(20)} base=${bv.toFixed(1)}${unit} pr=${pv.toFixed(1)}${unit} ${color}(${sign}${delta.toFixed(1)}${unit})\x1b[0m`);
|
|
53
|
+
}
|
|
54
|
+
const baseF = base.findings || [];
|
|
55
|
+
const prF = pr.findings || [];
|
|
56
|
+
const newF = prF.filter((pf) => !baseF.find((bf) => bf.id === pf.id));
|
|
57
|
+
if (newF.length > 0) {
|
|
58
|
+
console.log(`\nā ļø ${newF.length} new finding(s) in PR:\n`);
|
|
59
|
+
for (const f of newF) {
|
|
60
|
+
console.log(` [${(f.severity || '').toUpperCase()}] ${f.title}`);
|
|
61
|
+
console.log(` ${f.detail}`);
|
|
62
|
+
console.log(` š” ${f.suggestion}\n`);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
console.log('\nā
No new findings in PR.\n');
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
case 'check': {
|
|
71
|
+
const budgetsIdx = args.indexOf('--budgets');
|
|
72
|
+
const reportIdx = args.indexOf('--report');
|
|
73
|
+
if (budgetsIdx === -1) die('Usage: rn-perf check --budgets <config> [--report <session.json>]');
|
|
74
|
+
const budgetsPath = args[budgetsIdx + 1];
|
|
75
|
+
const reportPath = reportIdx !== -1 ? args[reportIdx + 1] : null;
|
|
76
|
+
console.log(`\nš rn-perf budget check\nBudgets: ${budgetsPath}\n`);
|
|
77
|
+
if (!reportPath) {
|
|
78
|
+
console.log('No --report provided. Nothing to check.\n');
|
|
79
|
+
process.exit(0);
|
|
80
|
+
}
|
|
81
|
+
const report = readJson(reportPath);
|
|
82
|
+
const findings = report.findings || [];
|
|
83
|
+
const critical = findings.filter((f) => f.severity === 'critical');
|
|
84
|
+
const warnings = findings.filter((f) => f.severity === 'warning');
|
|
85
|
+
if (critical.length > 0) {
|
|
86
|
+
console.error(`ā ${critical.length} critical finding(s):\n`);
|
|
87
|
+
for (const f of critical) {
|
|
88
|
+
console.error(` [${f.category || 'unknown'}] ${f.title}`);
|
|
89
|
+
console.error(` ${f.detail}`);
|
|
90
|
+
console.error(` š” ${f.suggestion}\n`);
|
|
91
|
+
}
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
if (warnings.length > 0) {
|
|
95
|
+
console.warn(`ā ļø ${warnings.length} warning(s):`);
|
|
96
|
+
for (const f of warnings) {
|
|
97
|
+
console.warn(` ${f.title}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
console.log(`\nā
All budget checks passed. (${findings.length} total, 0 critical)\n`);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
case 'html': {
|
|
105
|
+
const [reportPath] = args;
|
|
106
|
+
if (!reportPath) die('Usage: rn-perf html <session.json> [--output <report.html>]');
|
|
107
|
+
const outIdx = args.indexOf('--output');
|
|
108
|
+
const outputPath = outIdx !== -1 ? args[outIdx + 1] : 'report.html';
|
|
109
|
+
|
|
110
|
+
const report = readJson(reportPath);
|
|
111
|
+
const { generateHtmlReport } = require('../../reporters/dist/html-reporter');
|
|
112
|
+
const html = generateHtmlReport(report);
|
|
113
|
+
|
|
114
|
+
const absOutput = resolve(process.cwd(), outputPath);
|
|
115
|
+
writeFileSync(absOutput, html, 'utf-8');
|
|
116
|
+
console.log(`\nš Interactive HTML report generated at:\n ${absOutput}\n`);
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
default:
|
|
121
|
+
console.log(`
|
|
122
|
+
rn-perf-kit CLI
|
|
123
|
+
|
|
124
|
+
Usage:
|
|
125
|
+
rn-perf compare <base.json> <pr.json>
|
|
126
|
+
rn-perf check --budgets <perf.config.ts> --report <session.json>
|
|
127
|
+
rn-perf html <session.json> [--output <report.html>]
|
|
128
|
+
|
|
129
|
+
Commands:
|
|
130
|
+
compare Diff two session reports, highlight regressions
|
|
131
|
+
check Check a session against budgets; exits non-zero on violations
|
|
132
|
+
html Generate an interactive HTML performance dashboard
|
|
133
|
+
`);
|
|
134
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rn-perf-kit/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI for rn-perf-kit: compare sessions, check budgets, generate HTML reports",
|
|
5
|
+
"bin": {
|
|
6
|
+
"rn-perf": "./dist/cli.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "./dist/cli.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc --project tsconfig.build.json",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"lint": "eslint src/"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.3.0",
|
|
16
|
+
"@types/node": "^20.0.0"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@rn-perf-kit/core": "^0.1.0"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* rn-perf CLI
|
|
4
|
+
*
|
|
5
|
+
* Commands:
|
|
6
|
+
* rn-perf compare <base.json> <pr.json>
|
|
7
|
+
* rn-perf check --budgets <config> --report <session.json>
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { readFileSync, existsSync } from 'fs';
|
|
11
|
+
import { resolve } from 'path';
|
|
12
|
+
|
|
13
|
+
const [, , command, ...args] = process.argv;
|
|
14
|
+
|
|
15
|
+
function die(msg: string): never {
|
|
16
|
+
console.error(`[rn-perf] ${msg}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function readJson(filePath: string): unknown {
|
|
21
|
+
const abs = resolve(process.cwd(), filePath);
|
|
22
|
+
if (!existsSync(abs)) die(`File not found: ${abs}`);
|
|
23
|
+
return JSON.parse(readFileSync(abs, 'utf-8'));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getPath(obj: unknown, path: string): number {
|
|
27
|
+
return path.split('.').reduce((o: any, k) => o?.[k], obj) ?? 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
switch (command) {
|
|
31
|
+
case 'compare': {
|
|
32
|
+
const [basePath, prPath] = args;
|
|
33
|
+
if (!basePath || !prPath) die('Usage: rn-perf compare <base.json> <pr.json>');
|
|
34
|
+
const base = readJson(basePath);
|
|
35
|
+
const pr = readJson(prPath);
|
|
36
|
+
console.log('\nš rn-perf session comparison\n');
|
|
37
|
+
console.log(`Base: ${basePath}\nPR: ${prPath}\n`);
|
|
38
|
+
const fields: Array<[string, string, string]> = [
|
|
39
|
+
['Jank %', 'summary.jankPct', '%'],
|
|
40
|
+
['JS Stalls', 'summary.jsStalls', ''],
|
|
41
|
+
['Total Commits', 'summary.totalCommits', ''],
|
|
42
|
+
['Navigations', 'summary.navigations', ''],
|
|
43
|
+
];
|
|
44
|
+
for (const [label, path, unit] of fields) {
|
|
45
|
+
const bv = getPath(base, path);
|
|
46
|
+
const pv = getPath(pr, path);
|
|
47
|
+
const delta = pv - bv;
|
|
48
|
+
const color = delta > 0 ? '\x1b[31m' : delta < 0 ? '\x1b[32m' : '\x1b[0m';
|
|
49
|
+
const sign = delta > 0 ? '+' : '';
|
|
50
|
+
console.log(` ${label.padEnd(20)} base=${bv.toFixed(1)}${unit} pr=${pv.toFixed(1)}${unit} ${color}(${sign}${delta.toFixed(1)}${unit})\x1b[0m`);
|
|
51
|
+
}
|
|
52
|
+
const baseF: any[] = (base as any).findings ?? [];
|
|
53
|
+
const prF: any[] = (pr as any).findings ?? [];
|
|
54
|
+
const newF = prF.filter((pf: any) => !baseF.find((bf: any) => bf.id === pf.id));
|
|
55
|
+
if (newF.length > 0) {
|
|
56
|
+
console.log(`\nā ļø ${newF.length} new finding(s) in PR:\n`);
|
|
57
|
+
for (const f of newF) {
|
|
58
|
+
console.log(` [${f.severity?.toUpperCase()}] ${f.title}`);
|
|
59
|
+
console.log(` ${f.detail}`);
|
|
60
|
+
console.log(` š” ${f.suggestion}\n`);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
console.log('\nā
No new findings in PR.\n');
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
case 'check': {
|
|
69
|
+
const budgetsIdx = args.indexOf('--budgets');
|
|
70
|
+
const reportIdx = args.indexOf('--report');
|
|
71
|
+
if (budgetsIdx === -1) die('Usage: rn-perf check --budgets <config> [--report <session.json>]');
|
|
72
|
+
const budgetsPath = args[budgetsIdx + 1];
|
|
73
|
+
const reportPath = reportIdx !== -1 ? args[reportIdx + 1] : null;
|
|
74
|
+
console.log(`\nš rn-perf budget check\nBudgets: ${budgetsPath}\n`);
|
|
75
|
+
if (!reportPath) { console.log('No --report provided. Nothing to check.\n'); process.exit(0); }
|
|
76
|
+
const report = readJson(reportPath) as any;
|
|
77
|
+
const findings: any[] = report.findings ?? [];
|
|
78
|
+
const critical = findings.filter((f: any) => f.severity === 'critical');
|
|
79
|
+
const warnings = findings.filter((f: any) => f.severity === 'warning');
|
|
80
|
+
if (critical.length > 0) {
|
|
81
|
+
console.error(`ā ${critical.length} critical finding(s):\n`);
|
|
82
|
+
for (const f of critical) {
|
|
83
|
+
console.error(` [${f.category}] ${f.title}\n ${f.detail}\n š” ${f.suggestion}\n`);
|
|
84
|
+
}
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
if (warnings.length > 0) { console.warn(`ā ļø ${warnings.length} warning(s):`); for (const f of warnings) console.warn(` ${f.title}`); }
|
|
88
|
+
console.log(`\nā
All budget checks passed. (${findings.length} total, 0 critical)\n`);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
default:
|
|
93
|
+
console.log(`
|
|
94
|
+
rn-perf-kit CLI
|
|
95
|
+
|
|
96
|
+
Usage:
|
|
97
|
+
rn-perf compare <base.json> <pr.json>
|
|
98
|
+
rn-perf check --budgets <perf.config.ts> --report <session.json>
|
|
99
|
+
|
|
100
|
+
Commands:
|
|
101
|
+
compare Diff two session reports, highlight regressions
|
|
102
|
+
check Check a session against budgets; exits non-zero on violations
|
|
103
|
+
`);
|
|
104
|
+
}
|
package/tsconfig.json
ADDED
package/README.md
DELETED