#!/bin/sh
# This script is used by the pre-commit hook to enforce frontend code quality.
# It runs formatting, import sorting, linting, and tests on all frontend code.
# If any tool (like Prettier or ESLint) automatically fixes files, those changes
# are immediately staged. This ensures that all code style and lint fixes are
# included in the same commit, so developers do not need to make an extra commit
# for auto-fixes. This keeps the commit history clean and guarantees that all
# committed code meets project standards.

set -e

# Run all frontend checks (format, sort-imports, lint, test)
npm run check

# Stage any files that were automatically fixed by the above commands
git diff --name-only --diff-filter=M | xargs -r git add