#!/usr/bin/env bash # Compila o CannonSmash Web (jgbrwn, GPL-2.0-or-later; reescrita em TypeScript + three.js do Cannon Smash de Kanna # Yoshihiro, feita pelo Claude da Anthropic segundo o NOTICE do repositorio) a partir do commit 7e9055f de # github.com/jgbrwn/cannonsmash-web, com o "npm ci" do package-lock.json do autor (hashes de integridade do npm) e # "vite build --base ./" (a pagina roda numa subpasta; o index.html do autor usa caminhos absolutos), com o Node # 24.21.0 de artifacts/tools. O projeto nao muda; o jogo nao tem arquivos de imagem nem de audio (tudo e three.js e # WebAudio em codigo) e nao faz nenhuma requisicao externa. # # src/FredGames.Bundler/Builds/build-cannonsmash-web.sh # # Saida: artifacts/build/cannonsmash-web-7e9055f/{cannonsmash-web-7e9055f-dist.tar.gz,licenses.txt}; o tar.gz (pasta # dist/) tem que sair igual em dois builds seguidos. licenses.txt traz a licenca do three.js (MIT), embutido no bundle. set -euo pipefail COMMIT=7e9055fd1f22d0ae1e4753acbe0310cb6a833f6d SHA256=c5dd5c4ec070ad3445c9f6887c6838131f2cab218240d714e0c9e9741ff6d338 NODE=24.21.0 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/cannonsmash-web-${COMMIT:0:7}" cache="$root/artifacts/build/cache" nodebin="$root/artifacts/tools/node-v$NODE/bin" [ -x "$nodebin/node" ] && [ "$("$nodebin/node" -v)" = "v$NODE" ] || { echo "Precisa do Node $NODE em $nodebin." >&2; exit 1; } export PATH="$nodebin:$PATH" mkdir -p "$cache" tarball="$cache/cannonsmash-web-${COMMIT:0:7}.tar.gz" if [ ! -f "$tarball" ]; then curl -fsSL --retry 4 "https://github.com/jgbrwn/cannonsmash-web/archive/$COMMIT.tar.gz" -o "$tarball.partial" && mv "$tarball.partial" "$tarball" fi echo "$SHA256 $tarball" | shasum -a 256 -c - rm -rf "$out" mkdir -p "$out/tree" tar -xzf "$tarball" -C "$out/tree" --strip-components 1 cd "$out/tree" export npm_config_cache="$cache/npm-cannonsmash-web" npm_config_update_notifier=false npm ci --ignore-scripts --no-audit --no-fund --loglevel=error npx vite build --base ./ > "$out/build.log" 2>&1 || { tail -30 "$out/build.log"; exit 1; } [ -f dist/index.html ] if grep -rIl "https\?://" dist | grep -v '\.map$' | head -3 | grep .; then echo "(aviso) ha URLs no dist; conferir se sao so namespaces/comentarios" >&2 fi { echo "== three $(node -p "require('./node_modules/three/package.json').version"): LICENSE" cat node_modules/three/LICENSE } > "$out/licenses.txt" # dist/ vira um tar.gz deterministico (datas fixas, ordem fixa, sem dono). cp -R dist "$out/dist" find "$out/dist" -exec touch -t 202607180000 {} + ( cd "$out" && find dist -type f | LC_ALL=C sort > files.txt \ && COPYFILE_DISABLE=1 tar --format=ustar --uid 0 --gid 0 --uname root --gname root -n -cf - -T files.txt \ | gzip -n -9 > "cannonsmash-web-${COMMIT:0:7}-dist.tar.gz" && rm files.txt ) rm -rf "$out/tree" ls -l "$out/cannonsmash-web-${COMMIT:0:7}-dist.tar.gz" shasum -a 256 "$out/cannonsmash-web-${COMMIT:0:7}-dist.tar.gz" "$out/licenses.txt" find "$out/dist" -type f | sed "s|$out/||"