#!/usr/bin/env bash # Compila o Crypt of Grimwin (roguelike de possessao, 7DRL 2018, do Team Kalamakkara; MIT; TypeScript + PixiJS 4 + # rot.js) para a web a partir do fonte, num commit fixo, com o Node 24.21.0 (artifacts/tools) e o package-lock do autor: # npm ci + webpack 3 (o do projeto). Unica diferenca para o "npm run build" dele: a configuracao do webpack # (Builds/crypt-of-grimwin/webpack.fredygames.config.js) sem o HappyPack e o ForkTsChecker, que nao rodam no Node # atual, e sem o source map embutido; o ts-loader compila so (transpileOnly), como o do autor em modo happypack. # O index.html gerado carrega ../dist/index.js (a estrutura do repositorio); aqui o script fica ao lado do HTML. # # src/FredGames.Bundler/Builds/build-crypt-of-grimwin.sh # # Saida: artifacts/build/crypt-of-grimwin-328cc44/{site.tar.gz,crypt-of-grimwin-328cc44.tar.gz,licenses/}; # site.tar.gz (a pasta do jogo) tem que sair igual em dois builds seguidos. set -euo pipefail SLUG=crypt-of-grimwin COMMIT=328cc44977b60dfd74ae59ac470b10c062822b82 SHA256=3f319cc35d9112ab3f642788dd6062c96d66dc7c38febc8e52392a846edd53a1 URL="https://github.com/maqqr/7drl2018/archive/$COMMIT.tar.gz" MTIME=201803102259 # data do commit here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/$SLUG-${COMMIT:0:7}" cache="$root/artifacts/build/cache" mkdir -p "$cache" fetch() { [ -f "$cache/$3" ] || curl -fsSL --retry 4 "$1" -o "$cache/$3" echo "$2 $cache/$3" | shasum -a 256 -c - >/dev/null } fetch "$URL" "$SHA256" "$SLUG-${COMMIT:0:7}.tar.gz" export PATH="$root/artifacts/tools/node-v24.21.0/bin:$PATH" export NODE_OPTIONS=--openssl-legacy-provider # o webpack 3 usa md4, que o OpenSSL 3 do Node atual so da no modo legado export npm_config_cache="$cache/npm-$SLUG" rm -rf "$out" mkdir -p "$out/tree" tar -xzf "$cache/$SLUG-${COMMIT:0:7}.tar.gz" -C "$out/tree" --strip-components 1 # Fonte publicado (sem alteracoes): o tarball do commit, regravado em tar deterministico. ( cd "$out/tree" && find . -type f | sed 's|^\./||' | LC_ALL=C sort > "$out/files.txt" ) ( cd "$out/tree" && COPYFILE_DISABLE=1 tar --format=ustar --uid 0 --gid 0 --uname root --gname root -n \ -cf - -T "$out/files.txt" ) | gzip -n -9 > "$out/$SLUG-${COMMIT:0:7}.tar.gz" cd "$out/tree" cp "$here/crypt-of-grimwin/webpack.fredygames.config.js" ./webpack.fredygames.config.js npm ci --no-audit --no-fund --ignore-scripts >/dev/null 2>&1 npx webpack --config webpack.fredygames.config.js --json > "$out/webpack-stats.json" mv "$out/tree/dist" "$out/site" site="$out/site" sed -i.bak 's#src="../dist/index.js"#src="index.js"#' "$site/index.html" && rm "$site/index.html.bak" grep -q 'src="index.js"' "$site/index.html" find "$site" -exec touch -t "$MTIME" {} + ( cd "$out" && find site -type f | LC_ALL=C sort > "$out/site-files.txt" ) ( cd "$out" && COPYFILE_DISABLE=1 tar --format=ustar --uid 0 --gid 0 --uname root --gname root -n \ -cf - -T "$out/site-files.txt" ) | gzip -n -9 > "$out/site.tar.gz" # Licencas dos pacotes npm que entram no bundle (a lista vem das estatisticas do proprio webpack). mkdir -p "$out/licenses" python3 -I - "$out/webpack-stats.json" > "$out/pkgs.txt" <<'PY' import json, re, sys ms = set() def walk(mods): for m in mods: r = re.match(r"\./node_modules/((?:@[^/]+/)?[^/]+)/", m.get("name", "")) if r: ms.add(r.group(1)) walk(m.get("modules", [])) walk(json.load(open(sys.argv[1]))["modules"]) print("\n".join(sorted(ms))) PY while read -r pkg; do d="node_modules/$pkg" echo "== npm $(node -p "const p=require('./$d/package.json'); p.name+' '+p.version+' ('+(typeof p.license==='string'?p.license:JSON.stringify(p.license||p.licenses))+')'")" for f in "$d"/LICEN[CS]E* "$d"/license* "$d"/COPYING*; do [ -f "$f" ] && { echo "-- $(basename "$f")"; cat "$f"; echo; }; done done < "$out/pkgs.txt" > "$out/licenses/npm.txt" ls -l "$out/site.tar.gz" shasum -a 256 "$out/site.tar.gz" "$out/$SLUG-${COMMIT:0:7}.tar.gz"