From f971e773d993f16fca92f584481b8e581c6ad3e8 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 06:50:31 +0000 Subject: [PATCH 1/2] Start dev and demo with bun run --parallel instead of the fish script `bun run dev` and `bun run demo` are now plain package.json scripts: they set SNAPRAID_BASE_PATH (absolute, from $PWD) and, for the demo, run scripts/dev/setup.sh first and set SNAPRAID_BIN, SNAPRAID_EXTRA_ARGS and SNAPRAID_DEMO, then start `dev:server` and `dev:web` with Bun's built-in `bun run --parallel`, which stops the other script when one fails. No process supervision of our own: the terminal sends Ctrl+C, Ctrl+Z and hangup to the whole foreground process group, so Ctrl+C stops both servers, Ctrl+Z suspends both and fg resumes them. scripts/start.sh and the fish requirement are gone; README, docs and comments updated. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Y3rdfbWb1xDUdPRng7TX9Z --- .gitignore | 2 +- README.md | 3 +- apps/server/src/system/demo.ts | 2 +- docs/development.md | 18 +++++----- e2e/harness/demo-setup.ts | 2 +- package.json | 6 ++-- scripts/dev/setup.sh | 2 +- scripts/start.sh | 62 ---------------------------------- 8 files changed, 19 insertions(+), 78 deletions(-) delete mode 100755 scripts/start.sh diff --git a/.gitignore b/.gitignore index f149d61..ec3541b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ scripts/dev/bin/ scripts/dev/.cache/ scripts/dev/sandbox/ -# Local data of scripts/start.sh (configs, schedules, logs) +# Local data of bun run dev (configs, schedules, logs) /snapraid/ !apps/server/src/parsers/__tests__/fixtures/*.log diff --git a/README.md b/README.md index 51ef7f7..efe6075 100644 --- a/README.md +++ b/README.md @@ -244,8 +244,7 @@ December 23. ## 🛠️ Development -Requires Bun (the version in `package.json`) and the fish shell for `scripts/start.sh`; -the end-to-end tests run on Bun too. +Requires Bun (the version in `package.json`); the end-to-end tests run on Bun too. ```bash git clone https://github.com/firsttris/snapraid-ui && cd snapraid-ui diff --git a/apps/server/src/system/demo.ts b/apps/server/src/system/demo.ts index 51477b9..f3b6c83 100644 --- a/apps/server/src/system/demo.ts +++ b/apps/server/src/system/demo.ts @@ -1,4 +1,4 @@ -// Stand-ins for `snapraid smart` and `probe` in the demo sandbox (scripts/start.sh --demo). +// Stand-ins for `snapraid smart` and `probe` in the demo sandbox (bun run demo). // Its disks are directories, so SnapRAID finds no device to query. The output below has // the structured log format of the real commands and goes through the same parsers. // The sandbox disks also hold only a few KiB on the host's filesystem: `status` and the diff --git a/docs/development.md b/docs/development.md index 5a463dc..a185e54 100644 --- a/docs/development.md +++ b/docs/development.md @@ -7,7 +7,6 @@ This page gets you from a fresh clone to a running development setup, and covers | Tool | Version | Needed for | |---|---|---| | [Bun](https://bun.com/) | the version in `packageManager` of the root `package.json` (1.4.4) | Everything JavaScript: runs the backend and its tests, installs the packages, runs Vite and Vitest and Playwright's test runner (`bun --bun playwright test`), compiles the standalone binary (CI and the image use the same version) | -| [fish](https://fishshell.com/) | | `scripts/start.sh` is a fish script | | `curl`, `tar`, `gcc`, `make` | | Building SnapRAID for the demo sandbox (`scripts/dev/setup.sh`) | | SnapRAID | 14.0 or newer | Only for running against a real array without `--demo`; it has to be on your `PATH` or set via `SNAPRAID_BIN` | | Docker or Podman | | Only for building the image | @@ -18,19 +17,23 @@ This page gets you from a fresh clone to a running development setup, and covers git clone https://github.com/firsttris/snapraid-ui cd snapraid-ui bun install # all packages of the workspace, from the one bun.lock -bun run demo # scripts/start.sh --demo: sandbox with fake disks, no real array needed +bun run demo # sandbox with fake disks, no real array needed ``` -Open **http://localhost:3000**. The frontend dev server runs on port 3000, the backend API and WebSocket on port 8080. `Ctrl+C` stops both. +Open **http://localhost:3000**. The frontend dev server runs on port 3000, the backend API and WebSocket on port 8080. -`scripts/start.sh` (`bun run dev`, `bun run demo`) has two modes: +There are two ways to start, both scripts in the root `package.json`: | Command | Data directory | SnapRAID binary | Extra | |---|---|---|---| -| `bun run dev` (`scripts/start.sh`) | `./snapraid/` (created on first start, ignored by git) | `snapraid` from your `PATH` | Works against your real configs | -| `bun run demo` (`scripts/start.sh --demo`) | `scripts/dev/sandbox/` | `scripts/dev/bin/snapraid` | Sets `SNAPRAID_EXTRA_ARGS=--test-skip-device` and `SNAPRAID_DEMO=1` | +| `bun run dev` | `./snapraid/` (created on first start, ignored by git) | `snapraid` from your `PATH` | Works against your real configs | +| `bun run demo` | `scripts/dev/sandbox/` | `scripts/dev/bin/snapraid` | Runs `scripts/dev/setup.sh` first (stops if it fails), sets `SNAPRAID_EXTRA_ARGS=--test-skip-device` and `SNAPRAID_DEMO=1` | -Under the hood it starts `bun run dev` in `apps/server/` (`bun --watch`, so the backend restarts on changes) and `bun run dev` in `apps/web/` (Vite with hot reload). You can run these two commands yourself in separate terminals; set `SNAPRAID_BASE_PATH` and friends first (see [Configuration](configuration.md)), otherwise the backend uses `snapraid/` in the repository's root (`../../snapraid` relative to `apps/server/`). +Both set the environment and then start the scripts `dev:server` (`bun run dev` in `apps/server/`: `bun --watch`, so the backend restarts on changes) and `dev:web` (`bun run dev` in `apps/web/`: Vite with hot reload) side by side with `bun run --parallel`, which prefixes each line with the script's name and stops the other script when one fails. + +There is no start script of its own: the terminal sends `Ctrl+C` to the whole foreground process group, so it stops both servers; `Ctrl+Z` suspends both and gives you the shell back, `fg` resumes them. + +You can also run `bun run dev:server` and `bun run dev:web` yourself in separate terminals; set `SNAPRAID_BASE_PATH` and friends first (see [Configuration](configuration.md)), otherwise the backend uses `snapraid/` in the repository's root (`../../snapraid` relative to `apps/server/`). > [!NOTE] > In development the frontend calls the backend directly at `http://localhost:8080` (`apps/web/src/lib/api/constants.ts`), and the backend only accepts credentials from the same hostname. Open the dev frontend as `http://localhost:3000`, not via a LAN IP. @@ -121,7 +124,6 @@ packages/shared/ @snapraid-ui/shared: types and logic used by backend and docker/ Dockerfile, Compose file, Quadlet units scripts/build-binary.sh the standalone binary (bun build --compile) scripts/install.sh installer of the binary with a systemd service, attached to each release -scripts/start.sh local start (bun run dev, bun run demo) scripts/dev/setup.sh demo sandbox scripts/social-preview/ the social preview image e2e/ end-to-end tests (Playwright) against real SnapRAID and snapraid-daemon diff --git a/e2e/harness/demo-setup.ts b/e2e/harness/demo-setup.ts index fea3aa1..8401b1c 100644 --- a/e2e/harness/demo-setup.ts +++ b/e2e/harness/demo-setup.ts @@ -24,7 +24,7 @@ export default async function demoSetup() { for (const server of servers.reverse()) await server.stop() } try { - // As scripts/start.sh --demo + // As bun run demo servers.push( await startBackend({ SNAPRAID_BASE_PATH: SANDBOX, diff --git a/package.json b/package.json index 834707a..389b7d6 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "e2e" ], "scripts": { - "dev": "fish scripts/start.sh", - "demo": "fish scripts/start.sh --demo" + "dev": "mkdir -p snapraid && SNAPRAID_BASE_PATH=$PWD/snapraid bun run --parallel dev:server dev:web", + "demo": "bash scripts/dev/setup.sh && SNAPRAID_BASE_PATH=$PWD/scripts/dev/sandbox SNAPRAID_BIN=$PWD/scripts/dev/bin/snapraid SNAPRAID_EXTRA_ARGS=--test-skip-device SNAPRAID_DEMO=1 bun run --parallel dev:server dev:web", + "dev:server": "bun run --cwd apps/server dev", + "dev:web": "bun run --cwd apps/web dev" } } diff --git a/scripts/dev/setup.sh b/scripts/dev/setup.sh index 07e7869..0965ffc 100755 --- a/scripts/dev/setup.sh +++ b/scripts/dev/setup.sh @@ -188,4 +188,4 @@ snapraid_logged status (cd "$BACKEND_DIR" && bun scripts/seed-demo.ts "$SANDBOX") echo -echo "Sandbox ready. Start the app with: bun run demo (scripts/start.sh --demo)" +echo "Sandbox ready. Start the app with: bun run demo" diff --git a/scripts/start.sh b/scripts/start.sh deleted file mode 100755 index c7404cf..0000000 --- a/scripts/start.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env fish - -# Usage: scripts/start.sh -> uses ./snapraid and the system snapraid binary -# scripts/start.sh --demo -> uses the dev sandbox (see scripts/dev/setup.sh) - -# The repository's root, one level above scripts/ -set root (dirname (dirname (realpath (status filename)))) - -if test "$argv[1]" = "--demo" - # Build binary and sandbox on first run, no-op afterwards - bash $root/scripts/dev/setup.sh; or exit 1 - set -x SNAPRAID_BASE_PATH $root/scripts/dev/sandbox - set -x SNAPRAID_BIN $root/scripts/dev/bin/snapraid - # All sandbox "disks" live on one filesystem, which snapraid rejects without this - set -x SNAPRAID_EXTRA_ARGS --test-skip-device - # Sandbox disks are directories without SMART, the backend fakes smart and probe - set -x SNAPRAID_DEMO 1 -else - set -x SNAPRAID_BASE_PATH $root/snapraid - # Local data directory, the backend fills it on first start - mkdir -p $SNAPRAID_BASE_PATH -end - -if not command -q bun - echo "Bun not found. Install it: https://bun.sh" >&2 - exit 1 -end - -# Stop a process and everything it started -function kill_tree - for child in (pgrep -P $argv[1]) - kill_tree $child - end - kill $argv[1] 2>/dev/null -end - -# Stop both servers with SIGTERM, also on Ctrl+C -function stop_servers --on-event fish_exit - for pid in $backend_pid $frontend_pid - kill_tree $pid - end -end - -function on_interrupt --on-signal INT --on-signal TERM - exit 130 -end - -# Starte Backend im Hintergrund -cd $root/apps/server -bun run dev & -set -g backend_pid $last_pid - -# Starte Frontend im Hintergrund -cd $root/apps/web -bun run dev & -set -g frontend_pid $last_pid - -# Warte auf beide Prozesse. Polling statt wait, weil fish wait nur bei SIGINT unterbricht; -# endet einer, stoppt fish_exit den anderen -while kill -0 $backend_pid 2>/dev/null; and kill -0 $frontend_pid 2>/dev/null - sleep 1 -end From cbc98aeb9079d18198019b87aeacadef019a24b2 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 07:02:23 +0000 Subject: [PATCH 2/2] Keep the colours of bun run dev and demo in a terminal bun run --parallel pipes the scripts' output for its name prefix, so Vite and the backend no longer see a TTY and Vite printed no colours, unlike scripts/start.sh, which left them on the terminal. Both scripts now set FORCE_COLOR=1 when their own stdout is a terminal; piped or redirected output stays free of escape codes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Y3rdfbWb1xDUdPRng7TX9Z --- docs/development.md | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/development.md b/docs/development.md index a185e54..edddc7b 100644 --- a/docs/development.md +++ b/docs/development.md @@ -29,7 +29,7 @@ There are two ways to start, both scripts in the root `package.json`: | `bun run dev` | `./snapraid/` (created on first start, ignored by git) | `snapraid` from your `PATH` | Works against your real configs | | `bun run demo` | `scripts/dev/sandbox/` | `scripts/dev/bin/snapraid` | Runs `scripts/dev/setup.sh` first (stops if it fails), sets `SNAPRAID_EXTRA_ARGS=--test-skip-device` and `SNAPRAID_DEMO=1` | -Both set the environment and then start the scripts `dev:server` (`bun run dev` in `apps/server/`: `bun --watch`, so the backend restarts on changes) and `dev:web` (`bun run dev` in `apps/web/`: Vite with hot reload) side by side with `bun run --parallel`, which prefixes each line with the script's name and stops the other script when one fails. +Both set the environment and then start the scripts `dev:server` (`bun run dev` in `apps/server/`: `bun --watch`, so the backend restarts on changes) and `dev:web` (`bun run dev` in `apps/web/`: Vite with hot reload) side by side with `bun run --parallel`, which prefixes each line with the script's name and stops the other script when one fails. `--parallel` passes the output through a pipe, so both scripts set `FORCE_COLOR=1` when you start them in a terminal to keep the colours (not when the output goes into a file or a pipe). There is no start script of its own: the terminal sends `Ctrl+C` to the whole foreground process group, so it stops both servers; `Ctrl+Z` suspends both and gives you the shell back, `fg` resumes them. diff --git a/package.json b/package.json index 389b7d6..440608d 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "e2e" ], "scripts": { - "dev": "mkdir -p snapraid && SNAPRAID_BASE_PATH=$PWD/snapraid bun run --parallel dev:server dev:web", - "demo": "bash scripts/dev/setup.sh && SNAPRAID_BASE_PATH=$PWD/scripts/dev/sandbox SNAPRAID_BIN=$PWD/scripts/dev/bin/snapraid SNAPRAID_EXTRA_ARGS=--test-skip-device SNAPRAID_DEMO=1 bun run --parallel dev:server dev:web", + "dev": "mkdir -p snapraid && if [ -t 1 ]; then export FORCE_COLOR=1; fi && SNAPRAID_BASE_PATH=$PWD/snapraid bun run --parallel dev:server dev:web", + "demo": "bash scripts/dev/setup.sh && if [ -t 1 ]; then export FORCE_COLOR=1; fi && SNAPRAID_BASE_PATH=$PWD/scripts/dev/sandbox SNAPRAID_BIN=$PWD/scripts/dev/bin/snapraid SNAPRAID_EXTRA_ARGS=--test-skip-device SNAPRAID_DEMO=1 bun run --parallel dev:server dev:web", "dev:server": "bun run --cwd apps/server dev", "dev:web": "bun run --cwd apps/web dev" }