repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

scripts/typecheck.sh

Raw
#!/usr/bin/env bash
# Typecheck gate: fails if new errors appear beyond baseline
# Usage: bun run typecheck (or npm run typecheck)
set -eo pipefail

BASELINE_FILE=".tsc-baseline.txt"
BASELINE_COUNT=$(grep -c 'error TS' "$BASELINE_FILE" 2>/dev/null || echo 0)

CURRENT_OUTPUT=$(tsc --noEmit 2>&1 || true)
CURRENT_COUNT=$(echo "$CURRENT_OUTPUT" | grep -c 'error TS' || true)

if [ "$CURRENT_COUNT" -eq 0 ]; then
	echo "✅ tsc --noEmit: 0 errors (clean!)"
	exit 0
fi

echo "⚠️  tsc --noEmit: $CURRENT_COUNT errors (baseline: $BASELINE_COUNT)"

if [ "$CURRENT_COUNT" -gt "$BASELINE_COUNT" ]; then
	echo ""
	echo "❌ Error count increased ($CURRENT_COUNT > $BASELINE_COUNT). New errors:"
	echo "$CURRENT_OUTPUT" | grep 'error TS' > /tmp/tsc-current.txt
	diff --old-line-format='' --new-line-format='%L' --unchanged-line-format='' "$BASELINE_FILE" /tmp/tsc-current.txt || true
	exit 1
fi

echo "No new errors (baseline maintained)."
exit 0