#!/usr/bin/env bash
# Stop the dev orchestrator started by ./dev-start.sh.
set -uo pipefail
cd "$(dirname "$0")"

PIDDIR=.dev

stop() {
  local name="$1" f="$PIDDIR/$1.pid" pid
  [ -f "$f" ] || return 0
  pid=$(cat "$f" 2>/dev/null || true)
  if [ -n "${pid:-}" ]; then
    kill -TERM -- "-$pid" 2>/dev/null || kill -TERM "$pid" 2>/dev/null || true
  fi
  rm -f "$f"
}

stop watch
stop server
stop frontend
