import fs from 'node:fs'; import path from 'node:path'; const root = process.cwd(); const pagesDir = path.join(root, 'src/pages'); const limit = Number(process.argv[2] || 700); const files = fs.readdirSync(pagesDir) .filter((file) => file.endsWith('.tsx')) .map((file) => { const fullPath = path.join(pagesDir, file); const lines = fs.readFileSync(fullPath, 'utf8').split('\n').length; return { file, lines }; }) .sort((a, b) => b.lines - a.lines); const overLimit = files.filter((item) => item.lines > limit); console.log(`Page size budget: ${limit} lines\n`); for (const item of files) { const mark = item.lines > limit ? '!' : ' '; console.log(`${mark} ${String(item.lines).padStart(4, ' ')} ${item.file}`); } if (overLimit.length > 0) { console.log(`\n${overLimit.length} page(s) exceed the ${limit}-line budget.`); process.exitCode = 1; }