AtlatestRepositorysigil-site
sigil-site / treebuild.sh
1
#!/usr/bin/env bash2
#3
# Build the Sigil website for local development.4
# For full builds with all API docs, use ./publish.sh instead.5
#6
# Usage:7
# ./build.sh build Build the site8
# ./build.sh serve Dev server with live reload10
set -e12
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"13
cd "$SCRIPT_DIR"15
SIGIL="${SIGIL:-$HOME/.sigil/bin/sigil}"17
# Check peer repos18
if [ ! -d "../sigil" ]; then19
echo "ERROR: ../sigil not found. Clone the sigil repo as a peer directory."20
exit 121
fi23
if [ ! -d "../press" ]; then24
echo "ERROR: ../press not found. Clone the press repo as a peer directory."25
exit 126
fi28
# Check for API docs (combined lib from publish.sh, or monorepo dev build)29
if [ -d "build/combined-lib" ]; then30
echo "Using combined API docs from publish.sh"31
elif [ -d "../sigil/build/dev/lib" ]; then32
echo "Using monorepo API docs (run ./publish.sh --local for full docs)"33
else34
echo "WARNING: No API docs available."35
echo " Run './publish.sh --local' for full API docs,"36
echo " or 'sigil build' in ../sigil for monorepo-only docs."37
echo ""38
fi40
# Web REPL WASM assets (built with zig, wasm32-wasi target)41
REPL_DIR="${REPL_DIR:-../sigil-web-repl/build/web}"42
if [ "$1" = "--with-repl" ]; then43
shift44
if [ ! -f "$REPL_DIR/sigil-web-repl.wasm" ]; then45
echo "ERROR: --with-repl specified but WASM artifacts not found in $REPL_DIR"46
echo " Build sigil-web-repl first (sigil build --config web),"47
echo " or set REPL_DIR to the correct path."48
exit 149
fi50
fi52
if [ -f "$REPL_DIR/sigil-web-repl.wasm" ]; then53
echo "Copying REPL WASM artifacts from $REPL_DIR..."54
cp "$REPL_DIR/sigil-web-repl.wasm" assets/repl/56
# Build a combined lib.bundle with the web-repl modules plus extras57
# for REPL examples (sigil-sxml, sigil-match from peer repos)58
BUNDLE_DIRS="\"$REPL_DIR/lib\""59
for peer_lib in ../sigil-sxml ../sigil-match; do60
if [ -d "$peer_lib/build/dev/lib" ]; then61
echo " Adding modules from $(basename $peer_lib)..."62
BUNDLE_DIRS="$BUNDLE_DIRS \"$peer_lib/build/dev/lib\""63
fi64
done66
echo " Generating lib.bundle..."67
$SIGIL eval "(import (sigil build))68
(let ((n (generate-web-bundle69
output: \"assets/repl/lib.bundle\"70
dirs: (list $BUNDLE_DIRS))))71
(display n)72
(display \" files bundled\n\"))"73
else74
echo "WARNING: REPL WASM artifacts not found in $REPL_DIR"75
echo " The /repl/ page will not be functional without them."76
echo " Build sigil-web-repl first: sigil build --config web"77
echo ""78
fi80
# Ensure deps are installed81
if [ ! -d ".sigil/deps" ]; then82
echo "Installing dependencies..."83
$SIGIL deps install84
fi86
# Build and run the site87
exec $SIGIL run -- "$@"