From a57e729c1005af3d376a2202016b6350090e2d15 Mon Sep 17 00:00:00 2001 From: Justin Visser Date: Wed, 10 Jun 2026 13:57:35 +0200 Subject: [PATCH] dev: one-command local stack via dev.sh Starts the Go API and the Vite dev server as background jobs; 'wait -n' returns when the first one exits and the EXIT trap kills the rest, so one Ctrl-C (or either server crashing) stops everything. Installs web/node_modules on first run. Verified: both ports respond, SIGINT leaves no orphan processes. --- README.md | 8 +++++++- dev.sh | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 dev.sh diff --git a/README.md b/README.md index 5774223..0661357 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,13 @@ Status: milestone 2, thin API + parity page done. ## Development -Two terminals: +One command (installs frontend deps on first run, Ctrl-C stops everything): + +```sh +./dev.sh +``` + +Or manually, in two terminals: ```sh go run ./cmd/spreadlab # API on localhost:8080 diff --git a/dev.sh b/dev.sh new file mode 100755 index 0000000..131c26f --- /dev/null +++ b/dev.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Local dev stack in one command: +# - Go API on localhost:8080 +# - Vite dev server on localhost:5173 (proxies /api to the Go server) +# One Ctrl-C stops everything; if either server dies, the other is stopped. +set -euo pipefail + +cd "$(dirname "$0")" + +if [ ! -d web/node_modules ]; then + echo "dev.sh: first run, installing frontend dependencies..." + (cd web && npm install) +fi + +# On exit (Ctrl-C included), stop whichever background job is still running. +trap 'kill $(jobs -p) 2>/dev/null' EXIT + +go run ./cmd/spreadlab & +(cd web && npm run dev) & + +# wait -n returns when the FIRST job exits; the trap then cleans up the rest. +wait -n