#!/bin/sh

# Check if Node.js is installed
node --version > /dev/null 2>&1
if [[ $? != 0 ]]; then
    echo "Node.js could not be found. Please install Node.js."
    exit 1
fi

# Check if Biome is installed
npx biome --version  > /dev/null 2>&1
if [[ $? != 0 ]]; then
    echo "Biome could not be found. Installing Biome..."
    npm install --save-dev --save-exact @biomejs/biome
fi

# Run Biome linter
npx biome lint

# Capture the exit code of the linter
LINT_EXIT_CODE=$?

# Exit with the linter's exit code
if [ $LINT_EXIT_CODE -ne 0 ]; then
    echo "Biome linter failed. Please fix the issues before committing."
    exit 1
fi

exit 0
