this repo has no description
at main 62 lines 2.0 kB view raw
1#!/bin/sh 2 3# Pre-commit script to generate types and API docs (robust PATH + .env sourcing) 4set -e 5echo "🔄 Running pre-commit checks..." 6 7# Ensure Homebrew and local bins are discoverable when Git spawns a minimal shell 8export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" 9 10# Load .env so scripts relying on env vars (e.g. NEXT_PUBLIC_SUPABASE_ANON_KEY) work 11if [ -f ".env" ]; then 12 set -a 13 . ./.env 14 set +a 15fi 16 17# Decide remote vs local type generation from .env content 18USE_REMOTE_DB=$(grep "NEXT_PUBLIC_USE_REMOTE_DEV_DB=true" .env 2>/dev/null || true) 19 20# Choose package runner: prefer pnpm, fallback to npm 21if command -v pnpm >/dev/null 2>&1; then 22 RUN_CMD=pnpm 23else 24 RUN_CMD="npm run -s" 25fi 26 27if [ -n "$USE_REMOTE_DB" ]; then 28 echo "📝 Generating TypeScript types from remote database..." 29 TYPE_GEN_CMD="$RUN_CMD gen-types" 30else 31 echo "📝 Generating TypeScript types from local database..." 32 TYPE_GEN_CMD="$RUN_CMD dev:gen-types" 33fi 34 35# Generate TypeScript types from Supabase 36if ! sh -c "$TYPE_GEN_CMD"; then 37 echo "❌ Failed to generate types. Commit aborted." 38 echo "💡 Tip: Make sure Supabase is configured correctly" 39 echo "💡 For remote: SUPABASE_ACCESS_TOKEN must be set" 40 echo "💡 For local: Run 'supabase start' first" 41 exit 1 42fi 43 44# Generate API documentation (non-blocking if vars are missing) 45echo "📚 Generating API docs..." 46if ! sh -c "$RUN_CMD gen-api-docs"; then 47 echo "⚠️ Warning: Failed to generate API docs. This is non-blocking." 48 echo "💡 Tip: Ensure NEXT_PUBLIC_SUPABASE_ANON_KEY is set (or present in .env)" 49fi 50 51# Auto-stage updated artifacts if changed 52if ! git diff --quiet src/database-types.ts 2>/dev/null; then 53 echo "📦 Adding updated database types to commit..." 54 git add src/database-types.ts 55fi 56 57if [ -f "public/openapi.json" ] && ! git diff --quiet public/openapi.json 2>/dev/null; then 58 echo "📦 Adding updated API docs to commit..." 59 git add public/openapi.json 60fi 61 62echo "✨ Pre-commit checks completed!"