| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | root="$(git rev-parse --show-toplevel)" |
| 5 | desktop_dir="$root/desktop" |
| 6 | |
| 7 | vite_port="${REASONIX_DESKTOP_VITE_PORT:-}" |
| 8 | if [[ $# -gt 0 && "$1" =~ ^[0-9]+$ ]]; then |
| 9 | vite_port="$1" |
| 10 | shift |
| 11 | fi |
| 12 | |
| 13 | if [[ -z "$vite_port" ]]; then |
| 14 | branch="$(git -C "$root" branch --show-current || true)" |
| 15 | if [[ -z "$branch" ]]; then |
| 16 | branch="$(git -C "$root" rev-parse --short HEAD)" |
| 17 | fi |
| 18 | key="$root:$branch" |
| 19 | hash="$(printf "%s" "$key" | cksum | awk '{print $1}')" |
| 20 | vite_port=$((5173 + (hash % 100))) |
| 21 | fi |
| 22 | |
| 23 | if (( vite_port < 1024 || vite_port > 36000 )); then |
| 24 | echo "dev: Vite port must be between 1024 and 36000, got $vite_port" >&2 |
| 25 | exit 2 |
| 26 | fi |
| 27 | |
| 28 | wails_port="${REASONIX_DESKTOP_WAILS_PORT:-$((vite_port + 29000))}" |
| 29 | |
| 30 | export REASONIX_DESKTOP_VITE_PORT="$vite_port" |
| 31 | export REASONIX_DEV=1 |
| 32 | # pnpm honors npm_config_* not PNPM_CONFIG_*; suppress headless TTY purge prompt + age gate. |
| 33 | export npm_config_confirm_modules_purge=false |
| 34 | export npm_config_minimum_release_age=0 |
| 35 | |
| 36 | echo "Reasonix desktop dev" |
| 37 | echo " worktree: $root" |
| 38 | echo " vite: http://127.0.0.1:$vite_port" |
| 39 | echo " wails: 127.0.0.1:$wails_port" |
| 40 | |
| 41 | cd "$desktop_dir" |
| 42 | exec wails dev -nosyncgomod -devserver "127.0.0.1:$wails_port" "$@" |
| 43 |