website-htmx-rustelo-code/scripts/local-install/rustelo-htmx-server.sh

73 lines
2.6 KiB
Bash
Raw Normal View History

2026-07-10 03:44:13 +01:00
#!/bin/sh
# rustelo-htmx-server — local installation wrapper
#
# Resolves the site root, sets required env vars, and exec's the real binary.
# Installed at $HOME/.local/bin/rustelo-htmx-server by `just local-install`.
#
# Site root resolution order:
# 1. --site <path> (explicit workspace root containing site/)
# 2. $PWD has a site/ subdirectory
# 3. $HOME/.config/rustelo-htmx-server/ exists and has site/
#
# Any env var set in the caller environment is preserved (: "${VAR:=...}").
set -eu
REAL_BIN="$HOME/.local/libexec/rustelo-htmx-server"
NICKEL_BASE="$HOME/.local/share/rustelo/nickel"
TEMPLATES_BASE="$HOME/.local/share/rustelo-htmx-server/htmx-templates"
HTMX_ASSETS_BASE="$HOME/.local/share/rustelo-htmx-server/htmx"
CONFIG_HOME="$HOME/.config/rustelo-htmx-server"
# -- parse --site flag before forwarding remaining args to the server ------
SITE_ROOT=""
while [ $# -gt 0 ]; do
case "$1" in
--site|-s)
SITE_ROOT="$2"; shift 2 ;;
--site=*)
SITE_ROOT="${1#*=}"; shift ;;
*) break ;;
esac
done
# -- site root resolution --------------------------------------------------
if [ -z "$SITE_ROOT" ]; then
if [ -d "$PWD/site" ]; then
SITE_ROOT="$PWD"
elif [ -d "$CONFIG_HOME/site" ]; then
SITE_ROOT="$CONFIG_HOME"
else
printf 'rustelo-htmx-server: site root not found\n' >&2
printf ' provide one of:\n' >&2
printf ' --site <workspace> workspace root that contains site/\n' >&2
printf ' run from a dir with site/ subfolder\n' >&2
printf ' place config at %s/site/\n' "$CONFIG_HOME" >&2
exit 1
fi
fi
# -- env setup (caller values take precedence) -----------------------------
: "${SITE_CONFIG_PATH:=$SITE_ROOT/site/config/index.ncl}"
: "${NICKEL_IMPORT_PATH:=$NICKEL_BASE:$SITE_ROOT/site/config}"
# SSR content-grid index root (matches the deployed PV convention: site/r,
# sibling of the site tree). Absolute so it's independent of process cwd.
: "${SITE_SERVER_CONTENT_ROOT:=$SITE_ROOT/site/r}"
if [ -d "$SITE_ROOT/htmx-templates" ]; then
: "${HTMX_TEMPLATE_PATH:=$SITE_ROOT/htmx-templates}"
else
: "${HTMX_TEMPLATE_PATH:=$TEMPLATES_BASE}"
fi
# htmx runtime (/assets/htmx → htmx.min.js + ext/*). Prefer a site-local copy,
# else the framework runtime installed under ~/.local/share.
if [ -d "$SITE_ROOT/templates/shared/htmx" ]; then
: "${HTMX_ASSETS_PATH:=$SITE_ROOT/templates/shared/htmx}"
else
: "${HTMX_ASSETS_PATH:=$HTMX_ASSETS_BASE}"
fi
export SITE_CONFIG_PATH NICKEL_IMPORT_PATH HTMX_TEMPLATE_PATH HTMX_ASSETS_PATH SITE_SERVER_CONTENT_ROOT
exec "$REAL_BIN" "$@"