Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/ci/check_lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ async function generateStats(root = 'src') {
return files
}

// biome-ignore lint/suspicious/noExplicitAny: it's okay for printing any data
function printMarkdownTable(data: any[]) {
if (!data.length) return 'No changes'
const keys = Object.keys(data[0])
const alignments = keys.map((key) => (typeof data[0][key] === 'number' ? '---:' : ':---'))
console.log(`| ${keys.join(' | ')} |\n| ${alignments.join(' | ')} |`)
console.log(data.map((row) => `| ${keys.map((key) => (key === 'diff' ? formatDiff(row[key]) : row[key])).join(' | ')} |`).join('\n'))
}

const formatDiff = (count: number) => (count > 0 ? `+${count}` : count.toString())

function generateDiff(statsOld: FileStats[], statsNew: FileStats[]) {
const results: FileStatsDiff[] = []
const filesOld = new Set(statsOld.map((file) => file.path))
Expand All @@ -48,22 +59,24 @@ function generateDiff(statsOld: FileStats[], statsNew: FileStats[]) {

if (import.meta.main) {
if (Bun.argv.length === 4) {
// CI mode - compare two directories
const [, , base, pr] = Bun.argv
const baseStats = await generateStats(base)
const prStats = await generateStats(pr)
const diff = generateDiff(baseStats, prStats)
diff.sort((a, b) => b.diff - a.diff)

console.log('## Changes:')
console.log('```')
console.table(diff)
printMarkdownTable(diff)

const totalDiff = diff.reduce((sum, file) => sum + file.diff, 0)
const total = prStats.reduce((sum, file) => sum + file.lines, 0)
console.log(`\nTotal lines: ${total} (${totalDiff > 0 ? '+' : ''}${totalDiff})`)
console.log('```')
console.log(`\n**Total lines: ${total} (${formatDiff(totalDiff)})**` + (totalDiff < -100 ? ' 🔥' : ''))
} else {
// Regular mode - analyze a single directory
const files = await generateStats(Bun.argv[2])

const top10 = files.slice(0, 10)

console.log('Top 10 files by lines:')
console.table(top10)

Expand Down
Loading