fuzzyworld-tools / files / server / preview.sh
preview.sh
| 1 | #!/bin/bash |
| 2 | # Preview code.fuzzyworld.net locally, built from working copies of repos: |
| 3 | # npm run dev this repo |
| 4 | # npm run dev -- ~/code/explodorama other repos (any number) |
| 5 | # PORT=9000 npm run dev -- ... |
| 6 | # Each run clones the repos afresh (committed state only, not uncommitted edits), regenerates the |
| 7 | # pages with gen.py, and serves them. The stylesheets are symlinks, so CSS edits show on reload; |
| 8 | # changes to gen.py need a restart. |
| 9 | set -euo pipefail |
| 10 | cd "$(dirname "$0")/.." |
| 11 | PORT=${PORT:-8000} |
| 12 | W=${TMPDIR:-/tmp}/fw-preview |
| 13 | rm -rf "$W" |
| 14 | mkdir -p "$W"/{git,site,apps,state,ci,queue} |
| 15 | [ $# -gt 0 ] || set -- . |
| 16 | export FW_GIT_ROOT="$W/git" FW_CODE_SITE="$W/site" FW_APPS_SITE="$W/apps" FW_STATE="$W/state" FW_CI="$W/ci" FW_QUEUE="$W/queue" |
| 17 | names=() |
| 18 | for r in "$@"; do |
| 19 | top=$(git -C "$r" rev-parse --show-toplevel) |
| 20 | name=$(basename "$top") |
| 21 | git clone -q --bare "$top" "$FW_GIT_ROOT/$name.git" |
| 22 | git -C "$FW_GIT_ROOT/$name.git" config fuzzyworld.visibility public |
| 23 | python3 server/gen.py repo "$name" |
| 24 | names+=("$name") |
| 25 | done |
| 26 | python3 server/gen.py index |
| 27 | for f in _shared.css _icons.css style.css favicon.ico; do |
| 28 | ln -sf "$PWD/server/site/$f" "$W/site/$f" |
| 29 | done |
| 30 | echo "Serving http://localhost:$PORT/ ($(IFS=,; echo "${names[*]}"))" |
| 31 | exec python3 -m http.server "$PORT" --directory "$W/site" |