#!/usr/bin/env bash # Compila o Kart Royale (corrida de karts em 3D de Ryan Campbell, MIT; TypeScript + three.js + Vite, escrito pelo Claude da Anthropic # em varias rodadas de agentes, como diz o README) a partir do commit 036c0ef de github.com/ryancampbell/kart-royale, com o "npm ci" # do package-lock.json do autor (hashes de integridade do npm) e "vite build --base ./" (a pagina roda numa subpasta), com o Node # 24.21.0 de artifacts/tools. O jogo nao tem imagem, modelo, fonte nem audio: tudo (malhas, texturas, sons e musica) e gerado por # codigo ao carregar. Sem o "tsc --noEmit" do script "build" do autor (so verifica tipos) e sem source maps. # # Mudancas (kart-royale/kart-royale-fredygames.patch): uma CSP que bloqueia qualquer requisicao fora da pagina e o do manifest # (caminho absoluto, e o manifest so serve para instalar como app) sai; o build tambem nao publica public/. # # src/FredGames.Bundler/Builds/build-kart-royale.sh # # Saida: artifacts/build/kart-royale-036c0ef/{kart-royale-036c0ef-dist.tar.gz,licenses.txt}; o tar.gz (pasta dist/) tem que sair igual # em dois builds seguidos. licenses.txt traz as licencas das bibliotecas embutidas (three.js, postprocessing, n8ao, simplex-noise). set -euo pipefail COMMIT=036c0efb025f5ecf8fc31c405e9d818c61e03e21 SHA256=879929df0127282d3b9267a1d2adf865cd45803d3aefa559613fd3b3b18b8069 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/kart-royale-${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/kart-royale-${COMMIT:0:7}.tar.gz" if [ ! -f "$tarball" ]; then curl -fsSL --retry 4 "https://github.com/ryancampbell/kart-royale/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" patch -s -p1 < "$here/kart-royale/kart-royale-fredygames.patch" rm -rf public export npm_config_cache="$cache/npm-kart-royale" npm_config_update_notifier=false PUPPETEER_SKIP_DOWNLOAD=1 npm ci --ignore-scripts --no-audit --no-fund --loglevel=error sed -i.bak 's/sourcemap: true/sourcemap: false/' vite.config.ts 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 | head -3 | grep .; then echo "(aviso) ha URLs no dist; conferir se sao so namespaces/comentarios" >&2 fi { for pkg in three postprocessing n8ao simplex-noise; do echo "== $pkg $(node -p "require('./node_modules/$pkg/package.json').version"): LICENSE" cat node_modules/$pkg/LICENSE* echo done } > "$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 202611060000 {} + ( 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 > "kart-royale-${COMMIT:0:7}-dist.tar.gz" && rm files.txt ) rm -rf "$out/tree" ls -l "$out/kart-royale-${COMMIT:0:7}-dist.tar.gz" shasum -a 256 "$out/kart-royale-${COMMIT:0:7}-dist.tar.gz" "$out/licenses.txt" find "$out/dist" -type f | sed "s|$out/||"