#!/usr/bin/env bash
set -e
export APP_ENV=production
export WRANGLER_LOG="error"

LOG_FILE="logs/lint.log"

{
    find app -name "*.lock" -type f -delete
    echo "[lint] typegen cwd: $(pwd)"
    pnpm exec react-router typegen
    typegen_exit=$?
    generated_count=$(find .react-router/types -type f -name '*.ts' 2>/dev/null | wc -l | tr -d ' ')
    echo "[lint] typegen exit=${typegen_exit}, generated ${generated_count} file(s) under .react-router/types"
    bunx --bun linter check "$@"
} 2>&1 | tee "$LOG_FILE"

exit ${PIPESTATUS[0]}
