#!/usr/bin/env bash # Monta os mini-jogos do Santa Tracker do Google (google/santa-tracker-web, commit 7b7b0d1: codigo Apache-2.0, # imagens e audio CC BY 4.0) como jogos independentes. O projeto original so roda dentro do shell dele (Firebase, # analytics, roteador, fontes e decodificador Draco do Google); aqui o shell e trocado por um host nosso # (santa-tracker/host/: pagina com barra de pontos/pausa/reiniciar, protocolo MessageChannel igual ao do original, # som pelo kplay.js do proprio projeto), e a cena de cada jogo vai como o projeto a publica (api.js e kplay.js sem # mudanca), com as poucas edicoes listadas em santa-tracker/games.json. # # src/FredGames.Bundler/Builds/build-santa-tracker.sh [slug ...] # # Saida: artifacts/build/santa-tracker-7b7b0d1//{-dist.tar.gz} (a pasta dist/ tem que sair igual em # dois builds seguidos) e licenses.txt (jQuery MIT, Roboto e Lobster OFL). # Ferramentas (fora do git): Node 24.21.0, dart-sass 1.107.1 e Closure Compiler 20240317 em artifacts/tools. set -euo pipefail COMMIT=7b7b0d17c7549b58e8c9a3945feaf1fae525ee21 SHA256=1d4ae467a6934fdb14d48ef40376e1d6aa0167ce89654da323bf65105b6139d8 FONTS_COMMIT=5bb28733cec313b63fbd415b574b5ae35c8aa8b8 JQUERY_SHA256=02012f60b95dfbd7bdcf3585f36d80c7a35e78705b3d97f70d27ea2d7a467865 THREE_SHA256=ce122e3fffc1d00aa6305021bae200e8d83e35502863c2ad22c0f0de76e90d04 LOTTIE_SHA256=2577a7466942b33487800520ec92af6bb63485aca85b606c713592d794767448 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/santa-tracker-${COMMIT:0:7}" cache="$root/artifacts/build/cache" nodebin="$root/artifacts/tools/node-v$NODE/bin" export SASS_BIN="$root/artifacts/tools/dart-sass-1.107.1/dart-sass/sass" export CLOSURE_BIN="$root/artifacts/tools/closure-compiler-20240317.0.0/compiler" [ -x "$nodebin/node" ] && [ "$("$nodebin/node" -v)" = "v$NODE" ] || { echo "Precisa do Node $NODE em $nodebin." >&2; exit 1; } [ -x "$SASS_BIN" ] || { echo "Precisa do dart-sass em $SASS_BIN." >&2; exit 1; } [ -x "$CLOSURE_BIN" ] || { echo "Precisa do Closure Compiler em $CLOSURE_BIN." >&2; exit 1; } export PATH="$nodebin:$PATH" fetch() { # url sha256 destino if [ ! -f "$3" ]; then mkdir -p "$(dirname "$3")" curl -fsSL --retry 4 "$1" -o "$3.partial" && mv "$3.partial" "$3" fi echo "$2 $3" | shasum -a 256 -c - >/dev/null } mkdir -p "$cache" tarball="$cache/santa-tracker-web-${COMMIT:0:7}.tar.gz" fetch "https://github.com/google/santa-tracker-web/archive/$COMMIT.tar.gz" "$SHA256" "$tarball" tree="$out/tree" if [ ! -f "$tree/.ok" ]; then rm -rf "$tree"; mkdir -p "$tree" tar -xzf "$tarball" -C "$tree" --strip-components 1 touch "$tree/.ok" fi # jQuery 3.5.0 (MIT), o mesmo do package-lock.json do projeto fetch "https://registry.npmjs.org/jquery/-/jquery-3.5.0.tgz" "$JQUERY_SHA256" "$cache/santa-jquery-3.5.0.tgz" if [ ! -f "$cache/santa-jquery/package/dist/jquery.min.js" ]; then rm -rf "$cache/santa-jquery"; mkdir -p "$cache/santa-jquery"; tar -xzf "$cache/santa-jquery-3.5.0.tgz" -C "$cache/santa-jquery" fi # three.js 0.158.0 (MIT) do npm, o mesmo do package-lock.json do projeto (so o Railroad importa "three" pelo nome) fetch "https://registry.npmjs.org/three/-/three-0.158.0.tgz" "$THREE_SHA256" "$cache/santa-three-0.158.0.tgz" if [ ! -f "$cache/santa-three/package/build/three.module.js" ]; then rm -rf "$cache/santa-three"; mkdir -p "$cache/santa-three"; tar -xzf "$cache/santa-three-0.158.0.tgz" -C "$cache/santa-three" fi # lottie-web 5.5.10 (MIT), o mesmo do package-lock.json do projeto (animacoes do Build & Bolt e do Snow Dodgeball) fetch "https://registry.npmjs.org/lottie-web/-/lottie-web-5.5.10.tgz" "$LOTTIE_SHA256" "$cache/santa-lottie-web-5.5.10.tgz" if [ ! -f "$cache/santa-lottie/package/build/player/lottie_canvas.min.js" ]; then rm -rf "$cache/santa-lottie"; mkdir -p "$cache/santa-lottie"; tar -xzf "$cache/santa-lottie-web-5.5.10.tgz" -C "$cache/santa-lottie" fi # Roboto e Lobster (SIL OFL 1.1), do google/fonts num commit fixo, no lugar do fonts.googleapis.com fb="https://raw.githubusercontent.com/google/fonts/$FONTS_COMMIT" fetch "$fb/ofl/roboto/Roboto%5Bwdth,wght%5D.ttf" d7598e12c5dbef095ff8272cfc55da0250bd07fbdecbac8a530b9b277872a134 "$cache/santa-fonts-src/Roboto.ttf" fetch "$fb/ofl/roboto/OFL.txt" 061402327a96aadb0bfb694a960ed289ecd38d383e396243831ab81feb109c41 "$cache/santa-fonts-src/Roboto-OFL.txt" fetch "$fb/ofl/lobster/Lobster-Regular.ttf" d6568e697fd50cedc0be04d8aae4127fe95add607e7bff954ca88604be80c205 "$cache/santa-fonts-src/Lobster-Regular.ttf" fetch "$fb/ofl/lobster/OFL.txt" 88aece7d90f2bb7049719f11619a560af22af3451af141f12aa4f46bb157a99b "$cache/santa-fonts-src/Lobster-OFL.txt" if [ ! -f "$cache/santa-fonts/fonts.css" ]; then ftmp="$cache/santa-fonts.$$"; rm -rf "$ftmp"; mkdir -p "$ftmp" cp "$cache"/santa-fonts-src/* "$ftmp/" cat > "$ftmp/fonts.css" <<'CSS' /* Roboto (SIL OFL 1.1, The Roboto Project Authors) and Lobster (SIL OFL 1.1, The Lobster Project Authors), both unmodified. */ @font-face { font-family: 'Roboto'; font-style: normal; font-weight: 100 900; font-stretch: 75% 100%; src: url(Roboto.ttf) format('truetype'); } @font-face { font-family: 'Lobster'; font-style: normal; font-weight: 400; src: url(Lobster-Regular.ttf) format('truetype'); } CSS rm -rf "$cache/santa-fonts"; mv "$ftmp" "$cache/santa-fonts" fi node "$here/santa-tracker/build.mjs" --tree "$tree" --out "$out" --cache "$cache" --games "$here/santa-tracker/games.json" "$@" { echo "== jQuery 3.5.0 (MIT)"; cat "$cache/santa-jquery/package/LICENSE.txt"; echo echo "== lottie-web 5.5.10 (MIT)"; cat "$cache/santa-lottie/package/LICENSE.md"; echo echo "== Roboto (SIL OFL 1.1)"; cat "$cache/santa-fonts-src/Roboto-OFL.txt"; echo echo "== Lobster (SIL OFL 1.1)"; cat "$cache/santa-fonts-src/Lobster-OFL.txt" } > "$out/licenses.txt" for d in "$out"/*/dist; do [ -d "$d" ] || continue slug="$(basename "$(dirname "$d")")" if [ "$#" -gt 0 ] && ! printf '%s\n' "$@" | grep -qx "$slug"; then continue; fi find "$d" -exec touch -t 202607180000 {} + ( cd "$out/$slug" && 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-dist.tar.gz" && rm files.txt ) ls -l "$out/$slug/$slug-dist.tar.gz" shasum -a 256 "$out/$slug/$slug-dist.tar.gz" done shasum -a 256 "$out/licenses.txt"