#!/usr/bin/env bash # SPDX-License-Identifier: MPL-2.0 # # Lance SEQUA Studio en développement (Angular, ng serve) et ouvre le navigateur. # # ./scripts/studio.sh # Core simulé # ./scripts/studio.sh ws://127.0.0.1:8787 # Core réel (WebSocket) # MOCK_CORE=error ./scripts/studio.sh # faux Core de développement (SIMULÉ) # PORT=5200 NO_OPEN=1 ./scripts/studio.sh set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" core="${1:-}" port="${PORT:-5173}" mock_scenario="${MOCK_CORE:-}" mock_pid="" if [[ -n "$core" && ! "$core" =~ ^wss?:// ]]; then echo "L'URL du Core doit commencer par ws:// ou wss:// (reçu : $core)." >&2 exit 1 fi if [[ -n "$core" && -n "$mock_scenario" ]]; then echo "Une URL de Core et MOCK_CORE sont exclusifs." >&2 exit 1 fi stop_mock_core() { if [[ -n "$mock_pid" ]]; then kill "$mock_pid" 2>/dev/null || true fi } trap stop_mock_core EXIT cd "$root/studio/ui" if [[ ! -f node_modules/.package-lock.json || package-lock.json -nt node_modules/.package-lock.json ]]; then echo "==> npm ci" npm ci --no-audit --no-fund fi if [[ -n "$mock_scenario" ]]; then echo "==> FAUX CORE DE DÉVELOPPEMENT (SIMULÉ), scénario $mock_scenario : ws://127.0.0.1:9101" npm run mock-core:build --silent # faux Core en TypeScript (contrat généré), construit par Vite node tools/.mock-core/mock-core.js --scenario "$mock_scenario" --port 9101 --host 127.0.0.1 & mock_pid=$! sleep 0.3 if ! kill -0 "$mock_pid" 2>/dev/null; then echo "Le faux Core s'est arrêté immédiatement (scénario inconnu ?)." >&2 exit 1 fi # Attend que le port 9101 accepte les connexions (5 s max). for _ in $(seq 1 50); do if (echo > /dev/tcp/127.0.0.1/9101) 2>/dev/null; then break fi sleep 0.1 done core="ws://127.0.0.1:9101" fi # Sans Core ni faux Core : Core simulé, demandé explicitement (Studio ne simule jamais sans ?core=simulated). path="/?core=simulated" if [[ -n "$core" ]]; then path="/?core=$(node -e 'process.stdout.write(encodeURIComponent(process.argv[1]))' "$core")" fi echo "==> SEQUA Studio : http://localhost:$port$path (Ctrl+C pour arrêter)" args=(run dev -- --port "$port") # ng serve n'ouvre que la racine : le navigateur est ouvert ici sur l'URL complète (?core=), # dès que le port répond. if [[ "${NO_OPEN:-0}" != "1" ]]; then ( for _ in $(seq 1 240); do if (echo > "/dev/tcp/127.0.0.1/$port") 2>/dev/null; then url="http://localhost:$port$path" if command -v xdg-open > /dev/null; then xdg-open "$url"; elif command -v open > /dev/null; then open "$url"; fi break fi sleep 0.5 done ) > /dev/null 2>&1 & fi if [[ -n "$mock_pid" ]]; then # Sans exec : le trap EXIT arrête le faux Core quand Studio s'arrête. npm "${args[@]}" else exec npm "${args[@]}" fi