35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const { brotliCompressSync, gzipSync } = require("node:zlib");
|
|
|
|
const distDirectory = path.resolve(process.cwd(), "dist");
|
|
|
|
function getFiles(directory) {
|
|
return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
const entryPath = path.join(directory, entry.name);
|
|
return entry.isDirectory() ? getFiles(entryPath) : [entryPath];
|
|
});
|
|
}
|
|
|
|
function toKilobytes(bytes) {
|
|
return `${(bytes / 1000).toFixed(2)} kB`;
|
|
}
|
|
|
|
if (!fs.existsSync(distDirectory)) {
|
|
console.error("dist/ nicht gefunden. Bitte zuerst npm run build ausführen.");
|
|
process.exit(1);
|
|
}
|
|
|
|
const rows = getFiles(distDirectory)
|
|
.sort()
|
|
.map((filePath) => {
|
|
const contents = fs.readFileSync(filePath);
|
|
return {
|
|
Datei: path.relative(distDirectory, filePath),
|
|
Unkomprimiert: toKilobytes(contents.length),
|
|
GZip: toKilobytes(gzipSync(contents).length),
|
|
Brotli: toKilobytes(brotliCompressSync(contents).length),
|
|
};
|
|
});
|
|
|
|
console.table(rows); |