Files
oliver c7b653ff6a Restructure: move Vite project into app/, deploy build output to repo root
The webserver serves the repo checkout directly as static files, so
index.html at the repo root must be the production build (pointing at
hashed /assets/*.js) rather than the dev template (/src/main.tsx),
which was being served with an unrecognized application/octet-stream
MIME type and blocked by the browser.

- Move src/, public/, scripts/, server/, package.json, vite.config.ts,
  tsconfig.json, .env(.example), and the dev index.html into app/.
- Add app/scripts/deploy.mjs: copies app/dist/* into the repo root
  after every `vite build`, cleaning up stale hashed filenames.
- Wire it into `npm run build` (app/package.json).
- Update run.sh to operate from app/, and .gitignore for the new layout.
- Commit the current build output (index.html, assets/, manifest,
  sw.js, workbox-*.js, favicon.svg, icons/, LICENSE) to the repo root.
- Update README with the new project layout and deployment model.
2026-11-04 14:05:46 -03:00

89 lines
2.3 KiB
Bash
Executable File

#!/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, deployed into the repo root
# ./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")/app"
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 and deploying to repo root..."
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