build.sh raw

   1  #!/bin/sh
   2  # build.sh — Clean build of all tinyjs targets.
   3  # Wipes compiled .mjs output before recompiling so no stale files survive.
   4  # Hand-written $runtime/*.mjs files are preserved.
   5  set -e
   6  cd "$(dirname "$0")"
   7  
   8  # Ensure tinyjs is available — build from submodule if missing.
   9  if ! command -v tinyjs >/dev/null 2>&1; then
  10    echo "tinyjs not found, building from next/tinygo..."
  11    (cd next/tinygo && go build -o "$HOME/.local/bin/tinyjs" ./cmd/tinyjs)
  12  fi
  13  
  14  DIST=app/smesh3
  15  
  16  # Generate version_gen.go in each tinyjs target — single source of truth from pkg/version/version.
  17  VER=$(cat pkg/version/version)
  18  for dir in next/sm3sh next/sw next/sw-relay; do
  19    printf 'package main\n\nconst version = "%s"\n' "$VER" > "$dir/version_gen.go"
  20  done
  21  
  22  # Wipe compiled .mjs files in each target dir (not subdirs — $runtime is safe).
  23  # Preserve hand-written files: mls-bridge.mjs
  24  for dir in "$DIST" "$DIST/\$sw" "$DIST/\$sw-relay"; do
  25    find "$dir" -maxdepth 1 -name '*.mjs' ! -name 'mls-bridge.mjs' -delete 2>/dev/null || true
  26  done
  27  
  28  # Recompile all targets.
  29  echo "compiling sm3sh..."
  30  (cd next/sm3sh && tinyjs -o ../../$DIST .)
  31  echo "compiling sw (shell)..."
  32  (cd next/sw && tinyjs -o ../../$DIST/\$sw .)
  33  echo "compiling sw-relay..."
  34  (cd next/sw-relay && tinyjs -o ../../$DIST/\$sw-relay .)
  35  
  36  echo "build complete"
  37