fuzzyworld

fuzzyworld-tools / files / server / preview.sh

preview.sh

1.3 KB · history · blame

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.
9set -euo pipefail
10cd "$(dirname "$0")/.."
11PORT=${PORT:-8000}
12W=${TMPDIR:-/tmp}/fw-preview
13rm -rf "$W"
14mkdir -p "$W"/{git,site,apps,state,ci,queue}
15[ $# -gt 0 ] || set -- .
16export 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"
17names=()
18for 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")
25done
26python3 server/gen.py index
27for f in _shared.css _icons.css style.css favicon.ico; do
28 ln -sf "$PWD/server/site/$f" "$W/site/$f"
29done
30echo "Serving http://localhost:$PORT/ ($(IFS=,; echo "${names[*]}"))"
31exec python3 -m http.server "$PORT" --directory "$W/site"