AtlatestRepositorysigil-site

sigil-site / treebuild.sh

1#!/usr/bin/env bash
2#
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 site
8# ./build.sh serve Dev server with live reload
9
10set -e
12SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
13cd "$SCRIPT_DIR"
15SIGIL="${SIGIL:-$HOME/.sigil/bin/sigil}"
17# Check peer repos
18if [ ! -d "../sigil" ]; then
19 echo "ERROR: ../sigil not found. Clone the sigil repo as a peer directory."
20 exit 1
21fi
23if [ ! -d "../press" ]; then
24 echo "ERROR: ../press not found. Clone the press repo as a peer directory."
25 exit 1
26fi
28# Check for API docs (combined lib from publish.sh, or monorepo dev build)
29if [ -d "build/combined-lib" ]; then
30 echo "Using combined API docs from publish.sh"
31elif [ -d "../sigil/build/dev/lib" ]; then
32 echo "Using monorepo API docs (run ./publish.sh --local for full docs)"
33else
34 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 ""
38fi
40# Web REPL WASM assets (built with zig, wasm32-wasi target)
41REPL_DIR="${REPL_DIR:-../sigil-web-repl/build/web}"
42if [ "$1" = "--with-repl" ]; then
43 shift
44 if [ ! -f "$REPL_DIR/sigil-web-repl.wasm" ]; then
45 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 1
49 fi
50fi
52if [ -f "$REPL_DIR/sigil-web-repl.wasm" ]; then
53 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 extras
57 # 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; do
60 if [ -d "$peer_lib/build/dev/lib" ]; then
61 echo " Adding modules from $(basename $peer_lib)..."
62 BUNDLE_DIRS="$BUNDLE_DIRS \"$peer_lib/build/dev/lib\""
63 fi
64 done
66 echo " Generating lib.bundle..."
67 $SIGIL eval "(import (sigil build))
68 (let ((n (generate-web-bundle
69 output: \"assets/repl/lib.bundle\"
70 dirs: (list $BUNDLE_DIRS))))
71 (display n)
72 (display \" files bundled\n\"))"
73else
74 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 ""
78fi
80# Ensure deps are installed
81if [ ! -d ".sigil/deps" ]; then
82 echo "Installing dependencies..."
83 $SIGIL deps install
84fi
86# Build and run the site
87exec $SIGIL run -- "$@"