1import { readdirSync, statSync } from 'fs'2import path from 'path'4export const getDirSize = (dirPath: string): number => {5 let total = 06 try {7 const entries = readdirSync(dirPath, { withFileTypes: true })8 for (const entry of entries) {9 const fullPath = path.join(dirPath, entry.name)10 if (entry.isDirectory()) total += getDirSize(fullPath)11 else if (entry.isFile()) total += statSync(fullPath).size12 }13 } catch {}14 return total15}17export const fmtSizeMb = (bytes: number) => `${Math.round(bytes / 1024 / 1024)}MB`