#!/usr/bin/env bash
# Quick restart of Metro so workspace changes apply.
# Usage: run-stack mobile [--build] [app]
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

flags=()
target=""
for arg in "$@"; do
  case "${arg}" in
    -*) flags+=("${arg}") ;;
    *)  target="${arg}" ;;
  esac
done

ensure_env
use_mobile_app "${target}" || exit 1

# Only the built-in app has deps/packages sidecars; an extra app is installed
# and watched by the shared frontend-deps / frontend-packages pair.
services=("${MOBILE_SERVICE}")
if [ "${MOBILE_SERVICE}" = mobile-client ]; then
  services=(mobile-deps mobile-packages mobile-client)
fi

exec bash "$(dirname "${BASH_SOURCE[0]}")/restart.sh" \
  ${flags[@]+"${flags[@]}"} "${services[@]}"
