forked from
anil.recoil.org/monopam-myspace
My aggregated monorepo of OCaml code, automaintained
1#!/bin/bash
2# Build and optionally serve the full jon.recoil.org site.
3#
4# Dune outputs go into _build/ (which dune controls and may wipe).
5# We assemble the final site into _site/ so that expensive artifacts
6# like universes persist across rebuilds.
7#
8# Usage:
9# ./deploy-site.sh # build everything and serve on port 8080
10# ./deploy-site.sh --no-serve # build only
11# ./deploy-site.sh --fresh # rebuild universes from scratch
12
13set -euo pipefail
14
15MONO=$(cd "$(dirname "$0")" && pwd)
16SITE="$MONO/_site"
17DUNE_SITE="$MONO/_build/default/site/_html"
18DUNE_DOC="$MONO/_build/default/_doc/_html"
19SERVE=true
20FRESH=false
21
22for arg in "$@"; do
23 case "$arg" in
24 --no-serve) SERVE=false ;;
25 --fresh) FRESH=true ;;
26 esac
27done
28
29if $FRESH; then
30 echo "=== --fresh: removing _site ==="
31 rm -rf "$SITE"
32fi
33
34mkdir -p "$SITE"
35
36# Ensure we're on the right switch.
37export OPAMSWITCH=5.2.0+ox
38eval "$(opam env)"
39
40echo "=== Step 1: Build and register plugins ==="
41cd "$MONO"
42dune build @install
43dune install 2>/dev/null
44echo " plugins registered"
45
46echo ""
47echo "=== Step 2: Build site content ==="
48dune build @site 2>&1 | grep -v '^Warning\|^File\|^$' | tail -5 || true
49echo " dune @site done"
50
51echo ""
52echo "=== Step 3: Build reference docs ==="
53dune build @doc 2>&1 | tail -5 || true
54echo " dune @doc done"
55
56echo ""
57echo "=== Step 4: Assemble site ==="
58# Copy site HTML from dune output into _site.
59# rsync would be ideal but cp -rf works fine.
60cp -rf "$DUNE_SITE/"* "$SITE/"
61# Merge reference docs on top (site has reference/index.html, @doc adds packages).
62cp -rf "$DUNE_DOC/reference/"* "$SITE/reference/"
63mkdir -p "$SITE/odoc.support/"
64cp -rf "$DUNE_DOC/odoc.support/"* "$SITE/odoc.support/"
65echo " assembled into $SITE/"
66
67echo ""
68echo "=== Step 5: Build site universe (notebooks) ==="
69if [ -f "$SITE/_opam/worker.js" ]; then
70 echo " universe already exists, skipping (use --fresh to rebuild)"
71else
72 jtw opam astring base brr note mime_printer fpath rresult \
73 opam-format bos odoc.model tyxml yojson uri jsonm \
74 js_top_worker-widget-leaflet \
75 tessera-geotessera-jsoo tessera-viz-jsoo \
76 onnxrt -o "$SITE/_opam"
77 echo " universe built → $SITE/_opam/"
78fi
79
80echo ""
81echo "=== Step 6: Deploy onnxrt example assets ==="
82SENTIMENT_SRC="$MONO/onnxrt/example/sentiment"
83if [ ! -f "$SENTIMENT_SRC/model_quantized.onnx" ]; then
84 echo " downloading DistilBERT model..."
85 bash "$SENTIMENT_SRC/download_model.sh"
86fi
87cp "$SENTIMENT_SRC/vocab.txt" "$SITE/_opam/vocab.txt"
88cp "$SENTIMENT_SRC/model_quantized.onnx" "$SITE/_opam/model_quantized.onnx"
89cp "$MONO/onnxrt/example/add.onnx" "$SITE/_opam/add.onnx"
90echo " deployed vocab.txt + model_quantized.onnx + add.onnx → $SITE/_opam/"
91
92echo ""
93echo "=== Step 7: Build demo universes ==="
94DEMO_DIR="$SITE/reference/odoc-interactive-extension"
95
96if [ -f "$DEMO_DIR/universe/worker.js" ]; then
97 echo " demo universes already exist, skipping (use --fresh to rebuild)"
98else
99 UNIVERSES=$(mktemp -d)
100 trap 'rm -rf "$UNIVERSES"' EXIT
101
102 echo " building default universe (cmdliner, 5.2.0+ox switch)..."
103 jtw opam --switch=5.2.0+ox -o "$UNIVERSES/default" cmdliner
104
105 echo " building v3 universe (cmdliner, 5.2.0+ox switch)..."
106 jtw opam --switch=5.2.0+ox -o "$UNIVERSES/v3" cmdliner
107
108 echo " building oxcaml universe (5.2.0+ox switch)..."
109 jtw opam --switch=5.2.0+ox -o "$UNIVERSES/oxcaml"
110
111 for d in universe universe-v2 universe-v3 universe-oxcaml; do
112 rm -rf "$DEMO_DIR/$d"
113 done
114
115 cp -r "$UNIVERSES/default" "$DEMO_DIR/universe"
116 echo " deployed universe/"
117
118 cp -r "$UNIVERSES/default" "$DEMO_DIR/universe-v2"
119 echo " deployed universe-v2/"
120
121 cp -r "$UNIVERSES/v3" "$DEMO_DIR/universe-v3"
122 echo " deployed universe-v3/"
123
124 cp -r "$UNIVERSES/oxcaml" "$DEMO_DIR/universe-oxcaml"
125 echo " deployed universe-oxcaml/"
126
127 for d in universe universe-v2 universe-v3 universe-oxcaml; do
128 cp "$SITE/_x-ocaml/x-ocaml.js" "$DEMO_DIR/$d/x-ocaml.js"
129 done
130fi
131
132echo ""
133echo "=== Done ==="
134echo ""
135echo "Site root: $SITE/"
136echo ""
137echo "Key pages:"
138echo " /index.html — site home"
139echo " /blog/index.html — blog index"
140echo " /notebooks/index.html — notebooks index"
141echo " /notebooks/foundations/index.html — foundations of CS"
142echo " /projects/index.html — projects"
143echo " /reference/ — API reference docs"
144echo " /reference/odoc-interactive-extension/ — interactive demos"
145
146if $SERVE; then
147 echo ""
148 echo "Starting HTTP server on http://localhost:8080"
149 cd "$SITE"
150 exec python3 -m http.server 8080
151fi