Files
Ange-Marie MAURIN - A2M Systèmes e231e643cd refactor(studio): l'interface passe dans studio/ui, studio/ devient l'ensemble host + ui
Studio regroupe l'exécutable hôte (C++, à venir dans studio/host) et l'interface web (TypeScript, studio/ui). Chemins mis à jour dans les scripts, .gitignore et la documentation ; paquet renommé @sequa/studio-ui.
2026-11-06 22:24:27 +01:00

77 lines
2.2 KiB
Bash

#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
#
# Lance SEQUA Studio en développement (Vite) 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"
node tools/mock-core.mjs --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
path="/"
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" --strictPort)
if [[ "${NO_OPEN:-0}" != "1" ]]; then
args+=(--open "$path")
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