#!/usr/bin/env bash
# TrainUs code statistics — lines of code by area, via cloc.
# Excludes generated output, dependencies, and the Hugo theme.
# Usage: ./scripts/code-stats.sh

set -euo pipefail
cd "$(dirname "$0")/.."

if ! command -v cloc >/dev/null 2>&1; then
  echo "cloc is required (e.g. 'apt install cloc' or 'brew install cloc')" >&2
  exit 1
fi

echo "=== Overall (src/, tests/, website/, docs/) ==="
cloc . \
  --exclude-dir=node_modules,dist,.git,dev-dist,tmp,.venv \
  --fullpath --not-match-d='(^|/)(public|resources|themes)(/|$)' \
  --exclude-ext=json,lock

echo
echo "=== src/ (application code) ==="
cloc src/ --exclude-ext=json

echo
echo "=== tests/ (Playwright, excluding venv) ==="
cloc tests/ --exclude-dir=.venv --exclude-ext=json

echo
echo "=== website/ (docs site, excluding generated/theme/deps) ==="
cloc website/ \
  --fullpath --not-match-d='(^|/)(public|resources|themes|node_modules)(/|$)' \
  --exclude-ext=json,lock

echo
echo "=== docs/ ==="
cloc docs/
