From 60f56367dfc1e3c5095d034bed4fb4f572e32b55 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Wed, 27 May 2026 23:17:18 +0900 Subject: refactor(packaging): split into dispatch/dispatch-systemd/dispatch-s6, separate dispatch-electron, add bun-based frontend serve PKGBUILD is now a split package producing three .pkg.tar.zst files in one makepkg run: - dispatch base application files (/opt/dispatch), CLI wrappers (dispatch-api, dispatch-frontend), env configs (/etc/dispatch/dispatch-api.conf, /etc/dispatch/dispatch-frontend.conf) - dispatch-systemd systemd user units for dispatch-api + dispatch-frontend (conflicts with dispatch-s6) - dispatch-s6 s6-rc service pipelines (-srv + -log) for both services (conflicts with dispatch-systemd) The Electron desktop wrapper moved to its own self-contained PKGBUILD at packaging/electron/, producing dispatch-electron. It bundles its own copy of the frontend dist + electron entry points under /opt/dispatch-electron and does not depend on the base dispatch package, so users can install it standalone and point VITE_API_URL at any backend at build time. Files under packaging/ are now read directly from ${_projectdir}/packaging/ rather than via source=(); the two s6 service dirs share basenames (run, type) which would collide inside ${srcdir}. New frontend static server: packages/frontend/serve.ts uses Bun's built-in HTTP server (no extra runtime deps) with SPA fallback to index.html and path-traversal protection. PORT/HOST/DIST_DIR overridable via env. Exposed as 'bun run --cwd packages/frontend serve' and via /usr/bin/dispatch-frontend. Build scripts: - bin/build-pkg now prints the freshest built packages - bin/install-pkg installs dispatch + dispatch-systemd by default; accepts package names or --all; searches both packaging/ and packaging/electron/ - bin/build-pkg-electron new, builds the electron split - bin/build-pkg-windows replaces bin/windows-pkg; drops the hard-coded WSL copy step, just prints the win-unpacked path .gitignore extended to cover packaging/*.tar.zst and packaging/electron/{src,pkg,*.pkg.tar.zst,*.tar.zst}. --- bin/build-pkg | 17 ++++++++++++- bin/build-pkg-electron | 20 ++++++++++++++++ bin/build-pkg-windows | 38 +++++++++++++++++++++++++++++ bin/install-pkg | 65 +++++++++++++++++++++++++++++++++++++++++++++----- bin/windows-pkg | 31 ------------------------ 5 files changed, 133 insertions(+), 38 deletions(-) create mode 100755 bin/build-pkg-electron create mode 100755 bin/build-pkg-windows delete mode 100755 bin/windows-pkg (limited to 'bin') diff --git a/bin/build-pkg b/bin/build-pkg index 904a0bb..d257efc 100755 --- a/bin/build-pkg +++ b/bin/build-pkg @@ -1,8 +1,23 @@ #!/usr/bin/env bash +# Build the dispatch Arch split package: dispatch + dispatch-systemd + dispatch-s6. +# One makepkg run produces three .pkg.tar.zst files in packaging/. +# +# Usage: +# bin/build-pkg # build +# bin/build-pkg --noconfirm # forward extra args to makepkg +# +# Override frontend build target with VITE_API_URL, e.g.: +# VITE_API_URL="https://api.example.com" bin/build-pkg + set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -PACKAGING_DIR="$(dirname "$SCRIPT_DIR")/packaging" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" +PACKAGING_DIR="$PROJECT_DIR/packaging" cd "$PACKAGING_DIR" makepkg -fd "$@" + +echo "" +echo "Built packages (newest first):" +ls -1t "$PACKAGING_DIR"/*.pkg.tar.zst 2>/dev/null | head -5 diff --git a/bin/build-pkg-electron b/bin/build-pkg-electron new file mode 100755 index 0000000..ceec321 --- /dev/null +++ b/bin/build-pkg-electron @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Build the dispatch-electron Arch package (Linux desktop wrapper). +# Depends on the `dispatch` package being built/installed at the matching version. +# +# Usage: +# bin/build-pkg-electron # build +# bin/build-pkg-electron --noconfirm + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" +PACKAGING_DIR="$PROJECT_DIR/packaging/electron" + +cd "$PACKAGING_DIR" +makepkg -fd "$@" + +echo "" +echo "Built package:" +ls -1t "$PACKAGING_DIR"/*.pkg.tar.zst 2>/dev/null | head -1 diff --git a/bin/build-pkg-windows b/bin/build-pkg-windows new file mode 100755 index 0000000..c5760e0 --- /dev/null +++ b/bin/build-pkg-windows @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Build the Windows Electron output via electron-builder. +# Produces an unpacked directory at packages/frontend/release/win-unpacked. +# +# Usage: +# bin/build-pkg-windows +# +# Override the API URL the frontend bundle points to: +# VITE_API_URL="http://your-host:18390" bin/build-pkg-windows + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" +FRONTEND_DIR="$PROJECT_DIR/packages/frontend" +VITE_API_URL="${VITE_API_URL:-http://localhost:18390}" + +cd "$PROJECT_DIR" + +# Install deps (electron + electron-builder live as frontend devDependencies) +bun install + +# Build the SPA bundle, then package it for Windows (unpacked dir) +cd "$FRONTEND_DIR" +VITE_API_URL="$VITE_API_URL" bun run dist:win + +WIN_BUILD="$FRONTEND_DIR/release/win-unpacked" + +if [ ! -d "$WIN_BUILD" ]; then + echo "Build failed: no win-unpacked directory found at $WIN_BUILD" >&2 + exit 1 +fi + +echo "" +echo "Windows Electron build ready at:" +echo " $WIN_BUILD" +echo "" +echo "Copy that folder to a Windows machine and run Dispatch.exe." diff --git a/bin/install-pkg b/bin/install-pkg index 89e55b2..72e218b 100755 --- a/bin/install-pkg +++ b/bin/install-pkg @@ -1,15 +1,68 @@ #!/usr/bin/env bash +# Install one or more built dispatch packages with yay -U. +# +# Default: installs the freshest dispatch + dispatch-systemd from packaging/. +# Pass package names (without version) to install a custom set. +# +# Usage: +# bin/install-pkg # dispatch + dispatch-systemd +# bin/install-pkg dispatch dispatch-s6 # dispatch + dispatch-s6 +# bin/install-pkg dispatch dispatch-electron # dispatch + electron wrapper +# bin/install-pkg --all # every freshest pkg found + set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -PACKAGING_DIR="$(dirname "$SCRIPT_DIR")/packaging" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" +PACKAGING_DIR="$PROJECT_DIR/packaging" +ELECTRON_DIR="$PROJECT_DIR/packaging/electron" + +# Find the most recent .pkg.tar.zst matching a package name in a given dir. +find_pkg() { + local name="$1" dir="$2" + ls -t "$dir"/"$name"-[0-9]*-x86_64.pkg.tar.zst 2>/dev/null | head -1 +} + +# Resolve a package name to its freshest tarball, searching both dirs. +resolve_pkg() { + local name="$1" path + path=$(find_pkg "$name" "$PACKAGING_DIR") + [ -n "$path" ] || path=$(find_pkg "$name" "$ELECTRON_DIR") + echo "$path" +} + +declare -a names +declare -a paths + +if [ $# -eq 0 ]; then + names=(dispatch dispatch-systemd) +elif [ "${1:-}" = "--all" ]; then + names=(dispatch dispatch-systemd dispatch-s6 dispatch-electron) +else + names=("$@") +fi -PKG=$(ls -t "$PACKAGING_DIR"/dispatch-[0-9]*-x86_64.pkg.tar.zst 2>/dev/null | head -1) +for name in "${names[@]}"; do + path=$(resolve_pkg "$name") + if [ -z "$path" ]; then + # --all is lenient: skip missing packages + if [ "${1:-}" = "--all" ]; then + echo "warn: no built package found for '$name', skipping" >&2 + continue + fi + echo "error: no built package found for '$name'" >&2 + echo " run bin/build-pkg (or bin/build-pkg-electron) first." >&2 + exit 1 + fi + paths+=("$path") +done -if [ -z "$PKG" ]; then - echo "No package found. Run bin/build-pkg first." >&2 +if [ ${#paths[@]} -eq 0 ]; then + echo "error: nothing to install." >&2 exit 1 fi -echo "Installing $PKG" -yay -U "$PKG" "$@" +echo "Installing:" +printf ' %s\n' "${paths[@]}" +echo "" +yay -U "${paths[@]}" diff --git a/bin/windows-pkg b/bin/windows-pkg deleted file mode 100755 index 693168c..0000000 --- a/bin/windows-pkg +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -PROJECT_DIR="$(dirname "$SCRIPT_DIR")" -FRONTEND_DIR="$PROJECT_DIR/packages/frontend" -DEST="/mnt/c/Users/micro/OneDrive/Documents/Dispatch" - -# Install deps (includes electron + electron-builder as devDependencies) -cd "$PROJECT_DIR" -bun install - -# Build frontend and package for Windows (use production port) -cd "$FRONTEND_DIR" -VITE_API_URL="http://localhost:18390" bun run dist:win - -# Find the output directory -WIN_BUILD=$(ls -d "$FRONTEND_DIR/release/win-unpacked" 2>/dev/null || true) - -if [ -z "$WIN_BUILD" ]; then - echo "Build failed: no win-unpacked directory found in release/" >&2 - exit 1 -fi - -# Copy to Windows Documents -rm -rf "$DEST" -mkdir -p "$DEST" -cp -r "$WIN_BUILD"/. "$DEST"/ - -echo "Windows build copied to: C:\\Users\\micro\\OneDrive\\Documents\\Dispatch" -echo "Run Dispatch.exe from that folder." -- cgit v1.2.3