#!/usr/bin/env bash # Compila o Juicefruit Orchard (jogo de fazenda de suco de Michael Pauley/reheated, Ludum Dare 45; codigo, arte e # musica CC0 1.0; fonte m5x7 de Daniel Linssen, CC0) a partir do commit e9d2410 de github.com/reheated/ph, onde o # jogo vive em juicefruit/. Faz o mesmo que o "ph build" do autor: o TypeScript do jogo e da biblioteca ph # (tsc 5.9.3, uma saida so, sem source map) vira game.js, os recursos viram game.dat (Builds/juicefruit-orchard/ # bundle.mjs reproduz o formato) e o template vira o index.html. Unica mudanca: uma CSP no index.html (nada sai do # site). O codigo do jogo nao e alterado. # # src/FredGames.Bundler/Builds/build-juicefruit-orchard.sh # # Saida: artifacts/build/juicefruit-orchard-e9d2410/{juicefruit-orchard-e9d2410-dist.tar.gz,licenses.txt}; o tar.gz # (pasta dist/) sai igual em dois builds seguidos. set -euo pipefail COMMIT=e9d241029a63948a2c12ad58ad1530369c24964a SHA256=3ba5798954a97158691bb5223542dc2edb25ddc541ab90fd3550eec78f791a8c NODE=24.21.0 TS=5.9.3 TS_SHA256=10e108c9cf7d5f2879053dff18515fb405abf2ccef63eaaf017d9c571687a1d3 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/juicefruit-orchard-${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" fetch() { if [ ! -f "$cache/$2" ]; then curl -fsSL --retry 4 "$1" -o "$cache/$2.partial" && mv "$cache/$2.partial" "$cache/$2" fi echo "$3 $cache/$2" | shasum -a 256 -c - } fetch "https://github.com/reheated/ph/archive/$COMMIT.tar.gz" "ph-${COMMIT:0:7}.tar.gz" "$SHA256" fetch "https://registry.npmjs.org/typescript/-/typescript-$TS.tgz" "typescript-$TS.tgz" "$TS_SHA256" rm -rf "$out" mkdir -p "$out/tree" "$out/ts" "$out/dist" tar -xzf "$cache/ph-${COMMIT:0:7}.tar.gz" -C "$out/tree" --strip-components 1 tar -xzf "$cache/typescript-$TS.tgz" -C "$out/ts" g="$out/tree/juicefruit" cat > "$g/tsconfig.fredygames.json" <<'J' { "compilerOptions": { "target": "es6", "module": "none", "strict": true, "allowJs": true, "outFile": "phaux/game.js" }, "include": ["../ph/lib/**/*", "src/**/*"] } J # O tsc 5.9 reclama de tipos do lib.dom (FontFace, VideoFrame) em codigo de 2019, mas emite o JS igual: so os erros # de tipo sao ignorados, e o game.js tem que existir. ( cd "$g" && node "$out/ts/package/bin/tsc" -p tsconfig.fredygames.json >"$out/tsc.log" || true ) [ -s "$g/phaux/game.js" ] node "$here/juicefruit-orchard/bundle.mjs" "$g" "$out/dist/game.dat" cp "$g/phaux/game.js" "$out/dist/game.js" cp "$g/static/favicon.ico" "$g/static/m5x7.bff" "$out/dist/" node -e ' const fs = require("fs"), [g, dest] = process.argv.slice(1); const ph = JSON.parse(fs.readFileSync(g + "/ph.json", "utf8")); let t = fs.readFileSync(g + "/template/index.html", "utf8"); t = t.replace(/\$\{([a-zA-Z][a-zA-Z0-9]*)\}/g, (m, k) => ph[k]); const csp = ""; t = t.replace("", "\n " + csp); fs.writeFileSync(dest, t); ' "$g" "$out/dist/index.html" { echo "== pH e Juicefruit Orchard (LICENSE do repositorio, CC0 1.0)" cat "$out/tree/LICENSE" echo echo "== README: licenca e creditos" sed -n '/^#### License and Attributions/,/^### Caveats/p' "$out/tree/README.md" | sed '$d' } > "$out/licenses.txt" find "$out/dist" -exec touch -t 202511010000 {} + ( 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 > "juicefruit-orchard-${COMMIT:0:7}-dist.tar.gz" && rm files.txt ) rm -rf "$out/tree" "$out/ts" ls -l "$out/juicefruit-orchard-${COMMIT:0:7}-dist.tar.gz" shasum -a 256 "$out/juicefruit-orchard-${COMMIT:0:7}-dist.tar.gz" "$out/licenses.txt"