Open History to see the last commit
1import { readFile, readdir, stat } from 'node:fs/promises'
2import path from 'node:path'
3import { gzipSync } from 'node:zlib'
4import { fileURLToPath } from 'node:url'
5β
6const scriptDir = path.dirname(fileURLToPath(import.meta.url))
7const repoRoot = path.resolve(scriptDir, '..')
8const distDir = path.join(repoRoot, 'dist')
9const entryFile = path.join(distDir, 'index.js')
10β
11async function getDirSizeBytes(dirPath) {
12 let total = 0
13 const entries = await readdir(dirPath, { withFileTypes: true })
14 for (const entry of entries) {
15 const fullPath = path.join(dirPath, entry.name)
16 if (entry.isDirectory()) {
17 total += await getDirSizeBytes(fullPath)
18 } else if (entry.isFile()) {
19 total += (await stat(fullPath)).size
20 }
21 }
22 return total
23}
24β
25async function run() {
26 const entry = await readFile(entryFile)
27 const entryGzip = gzipSync(entry)
28 const distBytes = await getDirSizeBytes(distDir)
29β
30 const output = {
31 measuredAt: new Date().toISOString(),
32 entryJsBytes: entry.length,
33 entryJsGzipBytes: entryGzip.length,
34 distTotalBytes: distBytes,
35 }
36β
37 console.log(JSON.stringify(output, null, 2))
38}
39β
40run().catch((error) => {
41 console.error(error)
42 process.exit(1)
43})