-
Notifications
You must be signed in to change notification settings - Fork 8
/
format-lh-for-s3.cjs
40 lines (35 loc) · 1.2 KB
/
format-lh-for-s3.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const fs = require('fs');
const path = require('path');
const manifest = require('./lhci/manifest.json');
const FINAL_DIR = './lhci/final';
// create directory for final reports if it does not exist
if (!fs.existsSync(FINAL_DIR)) {
fs.mkdirSync(FINAL_DIR);
}
manifest.forEach(report => {
fs.readFile(report.jsonPath, (readErr, data) => {
if (readErr) throw readErr;
// Get relevant data from report
const body = JSON.parse(data);
const relevantData = JSON.stringify({
url: report?.url,
fetchTime: body?.fetchTime,
performanceScore: report?.summary?.performance,
accessibilityScore: report?.summary?.accessibility,
bestPracticesScore: report?.summary?.['best-practices'],
seoScore: report?.summary?.seo,
pwaScore: report?.summary?.pwa,
runDuration: body?.timing?.total,
runIsMedianResult: report?.isRepresentativeRun,
lighthouseVersion: body?.lighthouseVersion,
userAgent: body?.userAgent,
formFactor: body?.configSettings?.formFactor,
locale: body?.configSettings?.locale,
});
// Write final file
const filename = path.basename(report.jsonPath);
fs.writeFile(`${FINAL_DIR}/${filename}`, relevantData, writeErr => {
if (writeErr) throw writeErr;
});
});
});