#!/usr/bin/env bash # Monta o XiangQi Wizard Light (GPL-2.0-or-later, Morning Yellow / xqbase.com; xadrez chines em JavaScript) a partir # da pasta JavaScript/ do commit 6221733 de github.com/xqbase/xqwlight. O motor (position.js, search.js, book.js, # cchess.js) vai sem mudanca; so o board.js muda (Builds/xqwlight/): # - os textos em chines (mensagens de fim de partida, em GBK) passam para o ingles e saem por window.xqStatus; # - as imagens e os sons do repositorio nao tem origem declarada: o tabuleiro e as pecas sao desenhos nossos (SVG # gerados por Builds/xqwlight/gen-images.py, pecas com as letras K A E H R C P) e nao ha som; # - as medidas de style.left/top/width/height ganham "px" (a pagina original roda em quirks mode, a nossa nao). # A pagina (index.html, app.js, app.css) e nossa, com a interface em ingles; app.js e a logica do index.htm do projeto. # # src/FredGames.Bundler/Builds/build-xqwlight.sh # # Saida: artifacts/build/xqwlight-6221733/xqwlight-6221733-site.tar.gz (pasta site/); dois builds seguidos dao os # mesmos bytes. set -euo pipefail COMMIT=6221733f1f79b3acb44cce6f83dc6100443cb2c9 SHA256=e5211e8ed1df6462f88529949ca836de4a7540434175d60856b138f20dad97a8 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" slug=xqwlight out="$root/artifacts/build/$slug-${COMMIT:0:7}" cache="$root/artifacts/build/cache" export PATH="/usr/bin:/bin" mkdir -p "$cache" tarball="$cache/$slug-${COMMIT:0:7}.tar.gz" [ -f "$tarball" ] || curl -fsSL --retry 4 "https://github.com/xqbase/xqwlight/archive/$COMMIT.tar.gz" -o "$tarball" echo "$SHA256 $tarball" | shasum -a 256 -c - rm -rf "$out" mkdir -p "$out/tree" "$out/site/images" tar -xzf "$tarball" -C "$out/tree" --strip-components 1 for f in position.js search.js book.js cchess.js; do cp "$out/tree/JavaScript/$f" "$out/site/$f"; done cp "$here/xqwlight/web/index.html" "$here/xqwlight/web/app.js" "$here/xqwlight/web/app.css" "$out/site/" python3 -I "$here/xqwlight/gen-images.py" "$out/site/images" python3 -I - "$out/tree/JavaScript/board.js" "$out/site/board.js" <<'PY' import sys src, dst = sys.argv[1:3] s = open(src, "rb").read().decode("gbk") def sub(old, new, count=1): global s assert s.count(old) == count, (old, s.count(old)) s = s.replace(old, new) # imagens nossas (SVG), sem sons sub("board.jpg)", "board.svg)") sub(".gif", ".svg", 4) sub("Board.prototype.playSound = function(soundFile) {\r\n", "Board.prototype.playSound = function(soundFile) {\r\n return; // FredyGames: sem sons (nenhum arquivo de som e publicado)\r\n") # medidas com unidade sub("style.left = SQ_X(sq);", 'style.left = SQ_X(sq) + "px";') sub("style.top = SQ_Y(sq);", 'style.top = SQ_Y(sq) + "px";') sub("style.width = SQUARE_SIZE;", 'style.width = SQUARE_SIZE + "px";') sub("style.height = SQUARE_SIZE;", 'style.height = SQUARE_SIZE + "px";') # mensagens: ingles, na propria pagina sub(" alert(message);", " (window.xqStatus || alert)(message);") for zh, en in ( ("双方不变作和,辛苦了!", "Draw: neither side varies the position."), ("长打作负,请不要气馁!", "You lose by perpetual attack. Do not be discouraged!"), ("长打作负,祝贺你取得胜利!", "The computer loses by perpetual attack. Congratulations, you win!"), ("双方都没有进攻棋子了,辛苦了!", "Draw: neither side has attacking pieces left."), ("超过自然限着作和,辛苦了!", "Draw: too many moves without a capture."), ("请再接再厉!", "Checkmate. Better luck next time!"), ("祝贺你取得胜利!", "Checkmate. Congratulations, you win!"), ): sub('"%s"' % zh, '"%s"' % en) assert not any(ord(c) > 127 for c in s), "sobrou texto fora do ASCII" open(dst, "w", encoding="utf-8", newline="").write(s) PY for f in position.js search.js book.js cchess.js; do if LC_ALL=C grep -q '[^[:print:][:space:]]' "$out/site/$f"; then echo "$f tem bytes fora do ASCII" >&2; exit 1; fi done if grep -rIlE "https?://" "$out/site" --include=index.html --include=app.js --include=app.css --include=board.js | grep . ; then echo "endereco externo nos arquivos da pagina" >&2; exit 1 fi cd "$out" find site -exec touch -t 202611010000 {} + find site -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-${COMMIT:0:7}-site.tar.gz" cat files.txt rm -rf files.txt tree site shasum -a 256 "$slug-${COMMIT:0:7}-site.tar.gz"