#!/usr/bin/env bash # Compila o Yet Another Idle RPG (RPG ocioso de texto e CSS, de Miktaew, MIT; JavaScript puro em modulos ES) a partir do commit e335643 # (v0.5.5.30) de github.com/miktaew/yet-another-idle-rpg. O projeto nao tem package.json: o autor roda o esbuild na mao (build.js). # Aqui o esbuild 0.28.1 vem de yet-another-idle-rpg/package-lock.json ("npm ci", com hashes de integridade) e roda com as mesmas # opcoes do build.js (bundle, minify, es2022, esm), sem source map; o dist/bundle.js do repositorio nao entra. # # Mudancas (yet-another-idle-rpg/yet-another-idle-rpg-fredygames.patch): CSP em cada pagina (nada fora da pasta); o Material Icons # do Google Fonts vira o pacote npm "material-icons" 1.13.14 (Apache-2.0, woff2/woff conferidos pelo sha256 do tarball); a Ink Free # (fonte proprietaria da Microsoft) vira a Patrick Hand (OFL, do google/fonts em commit fixo); sem meta tags og:/JSON-LD/verificacao # do Google, sem os botoes do GitHub e do Ko-fi nem as imagens deles (github-mark-white.png, ko-fi_icon.png), favicon local, e a # ajuda (help.html) sem links para fora e sem a secao de doacao. O HackTimer (MIT) do repositorio segue como esta. # # src/FredGames.Bundler/Builds/build-yet-another-idle-rpg.sh # # Saida: artifacts/build/yet-another-idle-rpg-e335643/{yet-another-idle-rpg-e335643-dist.tar.gz,licenses.txt}; o tar.gz tem que # sair igual em dois builds. set -euo pipefail COMMIT=e3356432ad5112f30842cfe6a6b5c3a4ced77de9 SHA256=faa142f39791c4a473a234e2ce5cfefc4ffda01cc84a4fe5326cf6ba8d1e0610 NODE=24.21.0 MI_VERSION=1.13.14 MI_SHA256=31196d01fc9f0615eb35bd0c51a40a2248351268432c5939fe8a2ebee21aa599 FONTS_COMMIT=9862abc066c9b83bf84c3e8ed1fc2d8d48f9bbf0 PH_SHA256=0f173b3e6cb6d1af25babf7f0057c5ac4ee11f9992b0469bb817e967ef4ad0fc PH_OFL_SHA256=377f4f9c19e935228552478eb68cc2ed82910988a60ba60e2ac73b09f32d02d1 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/yet-another-idle-rpg-${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/miktaew/yet-another-idle-rpg/archive/$COMMIT.tar.gz" "yet-another-idle-rpg-${COMMIT:0:7}.tar.gz" "$SHA256" fetch "https://registry.npmjs.org/material-icons/-/material-icons-$MI_VERSION.tgz" "material-icons-$MI_VERSION.tgz" "$MI_SHA256" fetch "https://raw.githubusercontent.com/google/fonts/$FONTS_COMMIT/ofl/patrickhand/PatrickHand-Regular.ttf" "ofl-patrickhand-PatrickHand-Regular.ttf" "$PH_SHA256" fetch "https://raw.githubusercontent.com/google/fonts/$FONTS_COMMIT/ofl/patrickhand/OFL.txt" "ofl-patrickhand-OFL.txt" "$PH_OFL_SHA256" rm -rf "$out" mkdir -p "$out/tree" "$out/tools" "$out/mi" "$out/site/dist" "$out/site/src" "$out/site/resources/js/HackTimer" "$out/site/resources/fonts" tar -xzf "$cache/yet-another-idle-rpg-${COMMIT:0:7}.tar.gz" -C "$out/tree" --strip-components 1 tar -xzf "$cache/material-icons-$MI_VERSION.tgz" -C "$out/mi" patch -s -p1 -d "$out/tree" < "$here/yet-another-idle-rpg/yet-another-idle-rpg-fredygames.patch" # esbuild da versao fixa pelo package-lock.json. cp "$here/yet-another-idle-rpg/package.json" "$here/yet-another-idle-rpg/package-lock.json" "$out/tools/" ( cd "$out/tools" && npm_config_cache="$cache/npm-yair" npm_config_update_notifier=false npm ci --ignore-scripts --no-audit --no-fund --loglevel=error ) ( cd "$out/tree" && "$out/tools/node_modules/.bin/esbuild" src/main.js --bundle --minify --platform=browser --target=es2022 --format=esm \ --outfile="$out/site/dist/bundle.js" --log-level=warning ) [ -s "$out/site/dist/bundle.js" ] # Site: so o que o jogo usa. cd "$out/tree" cp index.html style.css help.html changelog.html favicon.ico "$out/site/" cp src/game_version.js "$out/site/src/" cp resources/js/HackTimer/HackTimer.min.js resources/js/HackTimer/LICENSE "$out/site/resources/js/HackTimer/" cp "$cache/ofl-patrickhand-PatrickHand-Regular.ttf" "$out/site/resources/fonts/PatrickHand-Regular.ttf" cp "$cache/ofl-patrickhand-OFL.txt" "$out/site/resources/fonts/OFL-PatrickHand.txt" cp "$out/mi/package/iconfont/material-icons.woff2" "$out/mi/package/iconfont/material-icons.woff" "$out/site/resources/fonts/" cp "$out/mi/package/LICENSE" "$out/site/resources/fonts/LICENSE-material-icons.txt" # Folha de estilo do Material Icons: so a variante cheia ("material-icons"), como a do Google Fonts. python3 -I - "$out/mi/package/iconfont/material-icons.css" "$out/site/resources/fonts/material-icons.css" <<'PY' import sys src, dst = sys.argv[1:3] text = open(src).read() i = text.index('.material-icons {') j = text.index('}\n', i) + 2 open(dst, 'w').write(text[:j]) PY if grep -rlE 'https?://' "$out/site/index.html" "$out/site/help.html" "$out/site/style.css" "$out/site/dist/bundle.js" 2>/dev/null; then echo "(URL externa acima: conferir se e so texto)" >&2 fi if grep -rqE '(href|src)="https?://' "$out/site/index.html" "$out/site/help.html" "$out/site/changelog.html"; then echo "link externo no HTML" >&2; exit 1; fi { echo "== Yet Another Idle RPG (LICENSE do repositorio, MIT)" cat LICENSE echo echo "== HackTimer (resources/js/HackTimer/LICENSE, MIT)" cat resources/js/HackTimer/LICENSE echo echo "== Patrick Hand (OFL.txt do google/fonts, commit $FONTS_COMMIT)" cat "$cache/ofl-patrickhand-OFL.txt" echo echo "== material-icons $MI_VERSION (npm; fonte Material Icons do Google; LICENSE, Apache-2.0)" cat "$out/mi/package/LICENSE" echo } > "$out/licenses.txt" mv "$out/site" "$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 > "yet-another-idle-rpg-${COMMIT:0:7}-dist.tar.gz" && rm files.txt ) du -sh "$out/dist" cd "$out" && rm -rf tree tools mi ls -l "$out/yet-another-idle-rpg-${COMMIT:0:7}-dist.tar.gz" shasum -a 256 "$out/yet-another-idle-rpg-${COMMIT:0:7}-dist.tar.gz" "$out/licenses.txt"