forgejo/tools/watch.sh
2025-12-23 09:59:00 +01:00

36 lines
881 B
Bash

#!/bin/bash
set -euo pipefail
# Flag to ensure watch-backend is started only once
BACKEND_STARTED=false
# Function to start watch-backend
start_backend() {
if [ "$BACKEND_STARTED" = false ]; then
make --no-print-directory watch-backend &
BACKEND_PID=$!
BACKEND_STARTED=true
echo "Started watch-backend (PID: $BACKEND_PID)"
fi
}
# Trap to kill all background processes on exit
cleanup() {
if [ "$BACKEND_STARTED" = true ] && [ -n "${BACKEND_PID:-}" ]; then
kill "$BACKEND_PID" 2>/dev/null || true
fi
# Kill any remaining background jobs
jobs -p | xargs -r kill 2>/dev/null || true
}
trap cleanup EXIT
# Start watch-frontend and monitor output
make --no-print-directory watch-frontend | while IFS= read -r line; do
echo "$line"
if [[ "$line" == *"assets by path"* ]]; then
start_backend
fi
done &
# Wait for the background process
wait