#!/usr/bin/env bash # Compila o Hexapipes (puzzles de tubos em grades hexagonais e outras, de Daria Vasyukova/gereleth, MIT; SvelteKit 3 + # Svelte 5) a partir do commit 09274d5 de github.com/gereleth/hexapipes, com o "npm ci" do package-lock.json do # autor (hashes de integridade do npm) e "vite build", com o Node 24.21.0 de artifacts/tools. # # O projeto sai para a Vercel (adapter-vercel, rotas por caminho). Aqui vira um site estatico dentro de uma # pasta qualquer: @sveltejs/adapter-static 4.0.1 (MIT; tarball conferido pelo sha256, instalado sem gravar no # package.json) com pagina de entrada unica e roteamento por hash (kit.router.type = 'hash'), e o # index.html gerado passa a apontar para ./_app/ (relativo) em vez de /_app/. # # Mudancas no jogo (hexapipes/hexapipes-fredygames.patch): adapter-static + roteador por hash e os links # internos viram #/... ; o puzzle diario busca o arquivo por caminho relativo e, nos dias sem arquivo (os # do autor vao ate 2026-11-30), usa o do mesmo dia e mes do ano mais recente que tenha; sem as meta tags # og:/twitter: e sem os links para GitHub, Twitter, Bluesky e outros sites (viram texto); uma CSP que # bloqueia conexoes fora da propria origem. Nao ha analytics no codigo. og_image_v1.png e robots.txt ficam de fora. # # src/FredGames.Bundler/Builds/build-hexapipes.sh # # Saida: artifacts/build/hexapipes-09274d5/{hexapipes-09274d5-dist.tar.gz,licenses.txt}; o tar.gz (pasta dist/) tem que # sair igual em dois builds seguidos. set -euo pipefail COMMIT=09274d58cfd02e4ce15b1ae97107d0584f3f6ed3 SHA256=2ab2a26308e24aeb45c367811452a3126c12e4f105496af4ff19a155bbefa8e4 NODE=24.21.0 ADAPTER=4.0.1 ADAPTER_SHA256=c15058b0434434f20fa77dd8da06a4ea8b440ec445be453b177775f1a2170295 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/hexapipes-${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/gereleth/hexapipes/archive/$COMMIT.tar.gz" "hexapipes-${COMMIT:0:7}.tar.gz" "$SHA256" fetch "https://registry.npmjs.org/@sveltejs/adapter-static/-/adapter-static-$ADAPTER.tgz" "adapter-static-$ADAPTER.tgz" "$ADAPTER_SHA256" rm -rf "$out" mkdir -p "$out/tree" tar -xzf "$cache/hexapipes-${COMMIT:0:7}.tar.gz" -C "$out/tree" --strip-components 1 patch -s -p1 -d "$out/tree" < "$here/hexapipes/hexapipes-fredygames.patch" cd "$out/tree" export npm_config_cache="$cache/npm-hexapipes" npm_config_update_notifier=false npm ci --ignore-scripts --no-audit --no-fund --loglevel=error npm install --no-save --ignore-scripts --no-audit --no-fund --loglevel=error "$cache/adapter-static-$ADAPTER.tgz" rm static/og_image_v1.png static/robots.txt npx vite build > "$out/build.log" 2>&1 || { tail -30 "$out/build.log"; exit 1; } [ -f build/index.html ] && [ -d build/_app ] # O index.html de entrada (fallback do adapter-static) traz caminhos absolutos; a pagina roda numa subpasta. python3 -I - <<'PY' p = 'build/index.html' s = open(p).read() n = s.count('"/_app/') + s.count('href="/favicon.png"') s = s.replace('"/_app/', '"./_app/').replace('href="/favicon.png"', 'href="./favicon.png"') assert n > 5 and '"/_app' not in s and 'src="/' not in s open(p, 'w').write(s) PY { for pkg in svelte @sveltejs/kit devalue esm-env normalize-wheel randomcolor transformation-matrix; do for f in node_modules/$pkg/LICEN[CS]E*; do if [ -f "$f" ]; then echo "== $pkg $(node -p "require('./node_modules/$pkg/package.json').version"): $(basename "$f")"; cat "$f"; echo; fi done done } > "$out/licenses.txt" # dist/ vira um tar.gz deterministico (datas fixas, ordem fixa, sem dono). cp -R build "$out/dist" find "$out/dist" -exec touch -t 202610250000 {} + ( 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 > "hexapipes-${COMMIT:0:7}-dist.tar.gz" && rm files.txt ) rm -rf "$out/tree" ls -l "$out/hexapipes-${COMMIT:0:7}-dist.tar.gz" shasum -a 256 "$out/hexapipes-${COMMIT:0:7}-dist.tar.gz" "$out/licenses.txt"