#!/usr/bin/env bash # Compila o Hexa Battle (RPG tatico em grade hexagonal contra a IA, de Giacomo Tagliabue, MIT; TypeScript + React 15 + SVG) a partir # do commit fe97718 de github.com/itajaja/hb, com o yarn.lock do autor ("yarn install --frozen-lockfile", yarn 1.22.22, Node 24.21.0) # e "webpack -p" (webpack 2.5). A API do webpack 2 ainda roda no Node 24, so o md4 precisa do provedor legado do OpenSSL. # # Mudancas (hexa-battle/hexa-battle-fredygames.patch): caminhos relativos (publicPath ./) em vez de /static/, sem source map, e no # index.html uma CSP que bloqueia qualquer requisicao fora da pasta e as folhas de estilo locais no lugar dos links do cdnjs # (normalize.css 4.2.0, MIT, do pacote do npm conferido pelo sha256) e do Google Fonts (VT323, OFL, do google/fonts em commit fixo). # O jogo nao tem audio e so usa localStorage (lib "store"). Os icones SVG sao do game-icons.net (CC BY 3.0): creditos em LICENSE.txt. # # src/FredGames.Bundler/Builds/build-hexa-battle.sh # # Saida: artifacts/build/hexa-battle-fe97718/{hexa-battle-fe97718-dist.tar.gz,licenses.txt}; o tar.gz tem que sair igual em dois builds. set -euo pipefail COMMIT=fe97718def25736a4000e93efca6894530ba0c86 SHA256=9ab492bb4b5ab92e0d531aba28d140e73d7bdd51da8002e0ef8d2bb2ae0a855a NODE=24.21.0 YARN=1.22.22 YARN_SHA256=c17d3797fb9a9115bf375e31bfd30058cac6bc9c3b8807a3d8cb2094794b51ca NORMALIZE=4.2.0 NORMALIZE_SHA256=a69137c2a0a3707d59459044d584752abcfaf6d6f1f13909bed13ea142fc1548 FONTS_COMMIT=9862abc066c9b83bf84c3e8ed1fc2d8d48f9bbf0 VT323_SHA256=cf4de751ada78ceac033dbe16a687742939995b77bc2a052ae17a4957958594d OFL_SHA256=27d9af34210253e7ca1251fbace86c6f65b40031d6ce1a75493a1b2093631298 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/hexa-battle-${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/itajaja/hb/archive/$COMMIT.tar.gz" "hb-${COMMIT:0:7}.tar.gz" "$SHA256" fetch "https://registry.npmjs.org/yarn/-/yarn-$YARN.tgz" "yarn-$YARN.tgz" "$YARN_SHA256" fetch "https://registry.npmjs.org/normalize.css/-/normalize.css-$NORMALIZE.tgz" "normalize.css-$NORMALIZE.tgz" "$NORMALIZE_SHA256" fetch "https://raw.githubusercontent.com/google/fonts/$FONTS_COMMIT/ofl/vt323/VT323-Regular.ttf" "VT323-Regular-${FONTS_COMMIT:0:7}.ttf" "$VT323_SHA256" fetch "https://raw.githubusercontent.com/google/fonts/$FONTS_COMMIT/ofl/vt323/OFL.txt" "OFL-vt323-${FONTS_COMMIT:0:7}.txt" "$OFL_SHA256" rm -rf "$out" mkdir -p "$out/tree" "$out/yarn" "$out/normalize" tar -xzf "$cache/hb-${COMMIT:0:7}.tar.gz" -C "$out/tree" --strip-components 1 tar -xzf "$cache/yarn-$YARN.tgz" -C "$out/yarn" tar -xzf "$cache/normalize.css-$NORMALIZE.tgz" -C "$out/normalize" patch -s -p1 -d "$out/tree" < "$here/hexa-battle/hexa-battle-fredygames.patch" yarn() { node "$out/yarn/package/bin/yarn.js" "$@"; } cd "$out/tree" yarn install --frozen-lockfile --ignore-scripts --silent --cache-folder "$cache/yarn-hexa-battle" 2>/dev/null NODE_ENV=production NODE_OPTIONS=--openssl-legacy-provider node_modules/.bin/webpack -p > "$out/webpack.log" 2>&1 || { tail -30 "$out/webpack.log"; exit 1; } [ -s build/bundle.js ] && [ -s build/index.html ] # Folhas de estilo locais (as que o index.html pede) e a fonte. cp "$out/normalize/package/normalize.css" build/normalize.css cp "$cache/VT323-Regular-${FONTS_COMMIT:0:7}.ttf" build/VT323-Regular.ttf printf '@font-face{font-family:"VT323";font-style:normal;font-weight:400;src:url(./VT323-Regular.ttf) format("truetype")}\n' > build/vt323.css if grep -q 'https\?://' build/index.html; then echo "index.html ainda tem URL externa" >&2; exit 1; fi { echo "== Hexa Battle (LICENSE do repositorio, MIT)" cat LICENSE echo echo "== normalize.css $NORMALIZE (LICENSE.md, MIT)" cat "$out/normalize/package/LICENSE.md" echo echo "== VT323 (OFL.txt do google/fonts, commit $FONTS_COMMIT)" cat "$cache/OFL-vt323-${FONTS_COMMIT:0:7}.txt" echo # Pacotes que entram no bundle (lista do webpack --json). Sem arquivo de licenca no pacote: o campo "license" do package.json # (aphrodite: tambem a secao License do README, que traz o copyright). for pkg in react react-dom fbjs prop-types object-assign aphrodite css-in-js-utils hyphenate-style-name inline-style-prefixer asap string-hash animejs color color-convert color-name color-string is-arrayish simple-swizzle store process lodash; do d=node_modules/$pkg echo "== $pkg $(node -p "require('./$d/package.json').version") (entra no bundle; package.json: $(node -p "require('./$d/package.json').license"))" found=0 while IFS= read -r f; do cat "$f"; echo; found=1; done < <(find "$d" -maxdepth 1 -type f -iname 'licen[cs]e*' | LC_ALL=C sort) if [ "$found" = 0 ] && [ "$pkg" = aphrodite ]; then sed -n '/^# License/,/^\[webcomponents\]/p' "$d/README.md" | sed '$d'; fi if [ "$found" = 0 ] && [ "$pkg" != aphrodite ]; then echo "(o pacote nao traz arquivo de licenca)"; fi echo done } > "$out/licenses.txt" cp -R build "$out/dist" find "$out/dist" -exec touch -t 202611020000 {} + ( 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 > "hexa-battle-${COMMIT:0:7}-dist.tar.gz" && rm files.txt ) cd "$out" && rm -rf tree yarn normalize ls -l "$out/hexa-battle-${COMMIT:0:7}-dist.tar.gz" shasum -a 256 "$out/hexa-battle-${COMMIT:0:7}-dist.tar.gz" "$out/licenses.txt"