INIT
This commit is contained in:
commit
5245c0a856
42 files changed
+11202
No files matched your search
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env sh
|
||||
#
|
||||
# Convenience runner for the Hermes PWA.
|
||||
#
|
||||
# ./run.sh # dev server -> http://localhost:5173
|
||||
# ./run.sh dev # same as above
|
||||
# ./run.sh build # production build into dist/
|
||||
# ./run.sh serve # build if needed, then host + proxy /api/* (needs HERMES_TARGET)
|
||||
# ./run.sh preview # build, then serve the build with vite preview
|
||||
# ./run.sh icons # regenerate the PWA icon set
|
||||
# ./run.sh typecheck # type-check without emitting
|
||||
#
|
||||
# Environment:
|
||||
# HERMES_TARGET Hermes base URL for `serve`, e.g. https://hermes.example.com
|
||||
# PORT Port for `serve` (default 8787)
|
||||
# HERMES_DEV_TARGET Hermes base URL to proxy /api/* during `dev` (avoids CORS)
|
||||
#
|
||||
set -eu
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
MODE="${1:-dev}"
|
||||
|
||||
log() { printf '\033[1;34m>\033[0m %s\n' "$*"; }
|
||||
die() { printf '\033[1;31mx\033[0m %s\n' "$*" >&2; exit 1; }
|
||||
|
||||
command -v node >/dev/null 2>&1 || die "Node.js is required (>=18). Install it and retry."
|
||||
command -v npm >/dev/null 2>&1 || die "npm is required. Install it and retry."
|
||||
|
||||
ensure_deps() {
|
||||
if [ ! -d node_modules ]; then
|
||||
log "Installing dependencies..."
|
||||
npm install --no-audit --no-fund
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_icons() {
|
||||
if [ ! -f public/icons/icon-512.png ]; then
|
||||
log "Generating PWA icons..."
|
||||
npm run icons
|
||||
fi
|
||||
}
|
||||
|
||||
case "$MODE" in
|
||||
dev)
|
||||
ensure_deps
|
||||
ensure_icons
|
||||
if [ -n "${HERMES_DEV_TARGET:-}" ]; then
|
||||
log "Proxying /api/* to $HERMES_DEV_TARGET"
|
||||
fi
|
||||
log "Starting dev server..."
|
||||
exec npm run dev
|
||||
;;
|
||||
build)
|
||||
ensure_deps
|
||||
ensure_icons
|
||||
log "Building..."
|
||||
exec npm run build
|
||||
;;
|
||||
serve)
|
||||
[ -n "${HERMES_TARGET:-}" ] || die "Set HERMES_TARGET, e.g. HERMES_TARGET=https://hermes.example.com ./run.sh serve"
|
||||
ensure_deps
|
||||
ensure_icons
|
||||
if [ ! -d dist ]; then
|
||||
log "No build found - building first..."
|
||||
npm run build
|
||||
fi
|
||||
log "Serving on http://localhost:${PORT:-8787} (proxying /api/* to $HERMES_TARGET)"
|
||||
exec npm run serve
|
||||
;;
|
||||
preview)
|
||||
ensure_deps
|
||||
ensure_icons
|
||||
npm run build
|
||||
exec npm run preview
|
||||
;;
|
||||
icons)
|
||||
ensure_deps
|
||||
exec npm run icons
|
||||
;;
|
||||
typecheck)
|
||||
ensure_deps
|
||||
exec npm run typecheck
|
||||
;;
|
||||
*)
|
||||
die "Unknown mode '$MODE'. Use: dev | build | serve | preview | icons | typecheck"
|
||||
;;
|
||||
esac
|
||||
Reference in new issue
Block a user