#!/bin/sh
. "$(dirname -- "$0")/_/husky.sh"

changed_files=$(git diff --name-only HEAD~1)

app_changed=$(echo "$changed_files" | grep -E '^apps/app/' || true)
space_changed=$(echo "$changed_files" | grep -E '^apps/space/' || true)
echo $app_changed
echo $space_changed

if [ -n "$app_changed" ] && [ -n "$space_changed" ]; then
    echo "Changes detected in both apps/app and apps/space. Building..."
    yarn run lint
    yarn run build
elif [ -n "$app_changed" ]; then
    echo "Changes detected in apps/app. Building..."
    yarn run lint --filter=app
    yarn run build --filter=app
elif [ -n "$space_changed" ]; then
    echo "Changes detected in apps/space. Building..."
    yarn run lint --filter=space
    yarn run build --filter=space
fi
