35 lines
801 B
Bash
Executable File
35 lines
801 B
Bash
Executable File
#!/bin/sh
|
|
# Lance le serveur de previsualisation locale et ouvre l'editeur + l'apercu
|
|
# dans le navigateur. Ctrl+C arrete tout.
|
|
|
|
set -eu
|
|
|
|
PORT="${1:-8000}"
|
|
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
python3 preview.py "$PORT" &
|
|
SERVER_PID=$!
|
|
trap 'kill "$SERVER_PID" 2>/dev/null || true' EXIT INT TERM
|
|
|
|
# Laisse le temps au serveur de demarrer avant d'ouvrir le navigateur.
|
|
sleep 1
|
|
|
|
EDITOR_URL="http://localhost:${PORT}/editor.html"
|
|
PREVIEW_URL="http://localhost:${PORT}/"
|
|
|
|
open_url() {
|
|
if command -v xdg-open > /dev/null 2>&1; then
|
|
xdg-open "$1" > /dev/null 2>&1 &
|
|
elif command -v open > /dev/null 2>&1; then
|
|
open "$1" > /dev/null 2>&1 &
|
|
else
|
|
echo "Ouvre manuellement : $1"
|
|
fi
|
|
}
|
|
|
|
open_url "$EDITOR_URL"
|
|
open_url "$PREVIEW_URL"
|
|
|
|
wait "$SERVER_PID"
|