add size reporter GH action (#4745)

This commit is contained in:
RobertJoonas 2024-10-28 10:59:16 +01:00 committed by GitHub
parent 8bd32b68c9
commit b49fc82c2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 0 deletions

View File

@ -32,3 +32,4 @@ jobs:
- run: npm run check-format --prefix ./assets - run: npm run check-format --prefix ./assets
- run: npm run test --prefix ./assets - run: npm run test --prefix ./assets
- run: npm run deploy --prefix ./tracker - run: npm run deploy --prefix ./tracker
- run: npm run report-sizes --prefix ./tracker

View File

@ -2,6 +2,7 @@
"scripts": { "scripts": {
"deploy": "node compile.js", "deploy": "node compile.js",
"test": "npm run deploy && npx playwright test --config=./test/support/playwright.config.js", "test": "npm run deploy && npx playwright test --config=./test/support/playwright.config.js",
"report-sizes": "node report-sizes.js",
"start": "node test/support/server.js" "start": "node test/support/server.js"
}, },
"license": "MIT", "license": "MIT",

28
tracker/report-sizes.js Normal file
View File

@ -0,0 +1,28 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const PrivTrackerDir = '../priv/tracker/js/';
const toReport = [
'plausible.js',
'plausible.pageleave.js',
'plausible.manual.pageleave.js',
'plausible.hash.pageleave.js'
];
const results = [];
toReport.forEach((filename) => {
const filePath = path.join(PrivTrackerDir, filename);
if (fs.statSync(filePath).isFile()) {
results.push({
'Filename': filename,
'Real Size (Bytes)': fs.statSync(filePath).size,
'Gzipped Size (Bytes)': execSync(`gzip -c -9 "${filePath}"`).length,
'Brotli Size (Bytes)': execSync(`brotli -c -q 11 "${filePath}"`).length
});
}
});
console.table(results)