#!/usr/bin/env bash # Assemble dist/: the static site, self-contained, served from any web root. # Usage: scripts/build-dist.sh (runs scripts/build-wasm.sh first) set -euo pipefail ROOT=$(cd "$(dirname "$0")/.." && pwd) cd "$ROOT" # The licences and notices page, from the build's dependency tree; stops the build when a # family crate has no LICENSE (BSD-3 and MIT ask for their notices with the binary). python3 -I scripts/notices.py scripts/build-wasm.sh mkdir -p dist/pkg cp web/index.html web/notices.html web/style.css web/app.js web/controls.js web/audio-worklet.js web/icon.svg web/robots.txt web/manifest.json dist/ cp web/pkg/play_nes.js web/pkg/play_nes_bg.wasm dist/pkg/ if [ -d web/games ]; then mkdir -p dist/games && cp web/games/* dist/games/; fi commit=$(git rev-parse --short HEAD 2>/dev/null || echo none)$(git diff --quiet HEAD -- . ':!dist' 2>/dev/null || echo "-dirty") # The board's commit, from the pin in Cargo.toml. board=$(grep -v '^ *#' Cargo.toml | grep -o 'rev = "[0-9a-f]*"' | head -1 | cut -d'"' -f2 | cut -c1-7 || true) # Or, while the board comes by path (a prototype branch), that checkout's commit. path=$(grep -v '^ *#' Cargo.toml | grep -o 'path = "\.\./famicom-rust-fast"' | cut -d'"' -f2 || true) if [ -z "$board" ] && [ -n "$path" ]; then board="$(git -C "$path" rev-parse --short HEAD)$(git -C "$path" diff --quiet HEAD -- . || echo -dirty) (path)" fi printf '{"commit": "%s", "board": "%s", "built": "%s"}\n' "$commit" "$board" "$(date -u +%Y-%m-%dT%H:%MZ)" > dist/version.json echo "dist/ built at $commit (board $board): $(find dist -type f | wc -l) files, $(du -sh dist | cut -f1)"