import { readdir, readFile } from 'node:fs/promises' import { join } from 'node:path' import { gzipSync } from 'node:zlib' const directory = process.argv[2] || 'apps/web/dist' const files = [] async function walk(path) { for (const entry of await readdir(path, { withFileTypes: true })) { const name = join(path, entry.name) if (entry.isDirectory()) await walk(name) else if (/\.(js|css)$/.test(name)) { const content = await readFile(name) files.push({ file: name, bytes: content.length, gzipBytes: gzipSync(content, { level: 9 }).length }) } } } await walk(directory) files.sort((a, b) => b.bytes - a.bytes) console.log(JSON.stringify({ node: process.version, directory, totalBytes: files.reduce((n, f) => n + f.bytes, 0), totalGzipBytes: files.reduce((n, f) => n + f.gzipBytes, 0), files }, null, 2))