#!/bin/sh

echo "Running pre-commit checks..."

# Run lint-staged (handles staged .ts/.tsx files)
npm exec lint-staged

# Run TypeScript type check
echo "Running type check..."
npm run typecheck
if [ $? -ne 0 ]; then
  echo "Type check failed. Please fix TypeScript errors before committing."
  exit 1
fi

# Run linting
echo "Running lint..."
npm run lint
if [ $? -ne 0 ]; then
  echo "Lint failed. Run 'npm run lint:fix' to auto-fix issues."
  exit 1
fi

# Check for vulnerabilities
echo "Checking for vulnerabilities..."
npm audit --audit-level=high
if [ $? -ne 0 ]; then
  echo "Security vulnerabilities found. Run 'npm audit fix' to resolve."
  exit 1
fi

echo "All pre-commit checks passed!"
