#!/usr/bin/env bash # Compila jogos de Ludum Dare de Shawn M. Moore (sartak; MIT; arte, sons e musica dele: Aseprite, ChipTone, Abundant) # a partir do fonte, num commit fixo, como o package.json deles: "npm ci" (package-lock.json do autor) e # "node scripts/build.js" (Create React App ejetado, webpack 4, Phaser 3), com o Node 24.21.0 de artifacts/tools e o # provedor "legacy" do OpenSSL (o webpack 4 usa md4). # # Mudancas nos jogos (sartak/-fredygames.patch): "homepage" relativo (o jogo roda em /bundles///), # uma CSP que barra qualquer requisicao fora do site, a pagina sem o aviso do Safari e sem o Google Analytics, e o # componente Production sem os links para o autor, o evento e o Twitch/Twitter. O codigo do jogo nao e alterado. # Do build entram so a pagina e os arquivos que ela carrega (sem source maps, service worker nem manifestos de cache). # # src/FredGames.Bundler/Builds/build-sartak-games.sh [slug ...] (sem argumento: todos) # # Saida de cada jogo: artifacts/build//{-dist.tar.gz,-licenses.txt}; o .tar.gz (pasta dist/) tem que # sair igual em dois builds seguidos. set -euo pipefail NODE=24.21.0 GPL3_SHA256=3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" 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() { # url arquivo sha256 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 - >/dev/null } load() { case "$1" in nighty-night-nosferatu) REPO=nighty-night-nosferatu PATCH=nnn COMMIT=7898531bafc71e2ac806c87585736f031aa68dd6 SHA256=f752ae4e074d8d51280db2756091d10c56d0d7f72c7635f75acea42590450c92 ;; jumpcoins) REPO=jumpcoins PATCH=jc COMMIT=04a157ee1352a4d653bba0381067361ca836e933 SHA256=642f59e6ea86981430fa298d039ac1eb07eff3e69e5e424a708b34e93e92a01a ;; jet-janitor) REPO=jet-janitor PATCH=jj COMMIT=7a6d25f27579990eceac261169781bc880e124b5 SHA256=2f5d0174002ffa0050d065bf748df5e3a54f7a0b92092f443372ad0e983fc45b ;; *) echo "jogo desconhecido: $1" >&2; exit 1 ;; esac } build() { local slug="$1" load "$slug" local out="$root/artifacts/build/$slug" tree="$root/artifacts/build/$slug/tree" fetch "https://github.com/sartak/$REPO/archive/$COMMIT.tar.gz" "$slug-${COMMIT:0:7}.tar.gz" "$SHA256" rm -rf "$out"; mkdir -p "$tree" "$out/dist" tar -xzf "$cache/$slug-${COMMIT:0:7}.tar.gz" -C "$tree" --strip-components 1 patch -s -p1 -d "$tree" < "$here/sartak/$PATCH-fredygames.patch" ( cd "$tree" export npm_config_cache="$cache/npm-sartak" npm_config_update_notifier=false npm ci --ignore-scripts --no-audit --no-fund --loglevel=error NODE_OPTIONS=--openssl-legacy-provider CI=false node scripts/build.js >"$out/build.log" 2>&1 \ || { tail -30 "$out/build.log"; exit 1; } grep -q "^Compiled" "$out/build.log" python3 -I "$here/sartak/licenses.py" build node_modules "$out/npm-licenses.txt" ) # So o que a pagina carrega: nada de source maps, service worker nem manifestos de cache. ( cd "$tree/build" && find . -type f ! -name '*.map' ! -name 'service-worker.js' ! -name 'precache-manifest.*' \ ! -name 'asset-manifest.json' -print0 | while IFS= read -r -d '' f; do mkdir -p "$out/dist/$(dirname "$f")"; cp "$f" "$out/dist/$f"; done ) { echo "$slug - licences" echo "==================" echo echo "== The game (LICENSE.md of the repository, MIT)" cat "$tree/LICENSE.md" echo if [ -f "$tree/public/illuminated.js" ]; then fetch "https://www.gnu.org/licenses/gpl-3.0.txt" "gpl-3.0.txt" "$GPL3_SHA256" echo "== illuminated.js (public/illuminated.js, served as is; GNU GPL v3 or later: its header and the licence text)" sed -n '/^Copyright (C) 2012/,/^\*\//p' "$tree/public/illuminated.js" cat "$cache/gpl-3.0.txt" echo fi cat "$out/npm-licenses.txt" } > "$out/$slug-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 > "$slug-${COMMIT:0:7}-dist.tar.gz" && rm files.txt ) rm -rf "$tree" ls -l "$out/$slug-${COMMIT:0:7}-dist.tar.gz" shasum -a 256 "$out/$slug-${COMMIT:0:7}-dist.tar.gz" "$out/$slug-licenses.txt" } for g in "${@:-nighty-night-nosferatu jumpcoins jet-janitor}"; do for s in $g; do build "$s"; done; done