#!/bin/sh

GENERATED_API_FILES="packages/backend/src/generated/routes.ts packages/backend/src/generated/swagger.json"
if git diff --cached --name-only -- $GENERATED_API_FILES | grep -q .; then
  git restore --staged -- $GENERATED_API_FILES
  echo "Unstaged generated API artifacts; they are committed by the release workflow."
fi

if git diff --cached --name-only -- .env | grep -qx '.env' && \
  git show :.env 2>/dev/null | grep -Eq '^LIGHTDASH_LICENSE_KEY=[[:space:]]*[^[:space:]]'; then
  echo "ERROR: LIGHTDASH_LICENSE_KEY must not be committed to .env."
  echo "Use .env.development.local for local secrets."
  exit 1
fi

bash "$(dirname "$0")/runGitSecrets.sh"

# Check if profiles.yml has been modified
if git diff --cached --name-only | grep -q "examples/full-jaffle-shop-demo/profiles/profiles.yml"; then
  echo "\033[1;31m"
  echo "╔════════════════════════════════════════════════════════════════╗"
  echo "║                           ERROR                                ║"
  echo "║ Modifications to profiles.yml are not allowed!                 ║"
  echo "║ Please revert changes to:                                      ║"
  echo "║ examples/full-jaffle-shop-demo/profiles/profiles.yml           ║"
  echo "╚════════════════════════════════════════════════════════════════╝"
  echo "\033[0m"
  exit 1
fi

pnpm exec lint-staged
pnpm -F frontend unused-exports
