Fix map wrap, touch and keyboard input; harden build and release workflow; docs
This commit is contained in:
parent
f51c68a8ac
commit
494d71793e
6 changed files with 91 additions and 40 deletions
28
.github/workflows/release.yml
vendored
28
.github/workflows/release.yml
vendored
|
|
@ -6,17 +6,21 @@ name: Release to GitHub Pages
|
|||
# tagged v<version>.
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
# "released" also fires when a pre-release is promoted to a full release.
|
||||
types: [released]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: Existing release tag to redeploy (e.g. v1.0.0)
|
||||
required: true
|
||||
allow_older:
|
||||
description: Allow deploying a version older than what is live (rollback)
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
# Least privilege: only the deploy job can write to Pages.
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
concurrency:
|
||||
group: pages
|
||||
|
|
@ -29,6 +33,8 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
env:
|
||||
TAG: ${{ github.event.release.tag_name || inputs.tag }}
|
||||
ALLOW_OLDER: ${{ inputs.allow_older || false }}
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
|
|
@ -45,10 +51,21 @@ jobs:
|
|||
echo "::error::Release tag $TAG does not match package.json version ($want)"
|
||||
exit 1
|
||||
fi
|
||||
- name: Never deploy pre-releases or roll the live site back by accident
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ "$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json isPrerelease -q .isPrerelease)" = "true" ]; then
|
||||
echo "::error::$TAG is a pre-release; pre-releases never deploy"; exit 1
|
||||
fi
|
||||
live=$(curl -sSf https://seriesoftub.es/version.json 2>/dev/null | jq -r .version || echo "0.0.0")
|
||||
new="${TAG#v}"
|
||||
if [ "$ALLOW_OLDER" != "true" ] && [ "$(printf '%s\n%s\n' "$live" "$new" | sort -V | tail -n1)" != "$new" ]; then
|
||||
echo "::error::$new is older than the live $live. Re-run with allow_older to roll back on purpose."; exit 1
|
||||
fi
|
||||
- run: npm ci
|
||||
- run: npm test
|
||||
- name: Build site
|
||||
run: VERSION="${TAG#v}" npm run build
|
||||
run: VERSION="${TAG#v}" REQUIRE_NOTES=1 npm run build
|
||||
- uses: actions/upload-pages-artifact@v5
|
||||
with:
|
||||
path: ./_site
|
||||
|
|
@ -56,6 +73,9 @@ jobs:
|
|||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pages: write
|
||||
id-token: write
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
|
|
|
|||
11
README.md
11
README.md
|
|
@ -50,7 +50,7 @@ site/ everything that is deployed
|
|||
robots.txt, sitemap.xml, llms.txt, 404.html, CNAME
|
||||
scripts/build.sh copies site/ to _site/ and stamps __VERSION__ / __BUILD_DATE__
|
||||
tests/ node:test + jsdom
|
||||
.github/workflows/ ci.yml (every push) and release.yml (Pages deploy)
|
||||
.github/workflows/ ci.yml (pushes to main and PRs) and release.yml (Pages deploy)
|
||||
```
|
||||
|
||||
## Releasing
|
||||
|
|
@ -65,13 +65,18 @@ Only published releases reach [seriesoftub.es](https://seriesoftub.es). Pushes t
|
|||
3. Publish a GitHub release tagged `v<version>`, e.g. `gh release create v1.1.0 --generate-notes`.
|
||||
|
||||
The release workflow checks that the tag matches `package.json`, runs the tests,
|
||||
builds, deploys to GitHub Pages and pings IndexNow. Pre-releases never deploy.
|
||||
builds, deploys to GitHub Pages and pings IndexNow. It refuses to build when the
|
||||
CHANGELOG has no `## [<version>]` section (rename `[Unreleased]` first).
|
||||
Pre-releases never deploy, also not when run by hand, and a version older than
|
||||
the live one is refused unless you tick `allow_older` (a deliberate rollback).
|
||||
To redeploy an existing release, run the workflow manually with its tag.
|
||||
|
||||
## Hosting setup
|
||||
|
||||
GitHub Pages serves the site with **Source: GitHub Actions** and the custom domain
|
||||
`seriesoftub.es`. DNS for the apex domain:
|
||||
`seriesoftub.es`. Releases deploy from tags, so in **Settings → Environments →
|
||||
github-pages → Deployment branches and tags**, add a tag rule for `v*` (by default
|
||||
only the default branch may deploy). DNS for the apex domain:
|
||||
|
||||
```
|
||||
seriesoftub.es. A 185.199.108.153
|
||||
|
|
|
|||
|
|
@ -1,15 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
# Builds the deployable site into _site/: copies site/ and stamps the version
|
||||
# (from package.json) and the build date into the pages that carry them.
|
||||
# Builds the deployable site into _site/ (or $OUT): copies site/ and stamps the
|
||||
# version (from package.json) and the build date into the pages that carry them.
|
||||
# Set REQUIRE_NOTES=1 to fail when CHANGELOG.md has no bullets for this version.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
VERSION="${VERSION:-$(node -p "require('./package.json').version")}"
|
||||
BUILD_DATE="${BUILD_DATE:-$(date -u +%Y-%m-%d)}"
|
||||
OUT="${OUT:-_site}"
|
||||
|
||||
rm -rf _site
|
||||
cp -R site _site
|
||||
for f in _site/index.html _site/sitemap.xml _site/llms.txt; do
|
||||
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.+][0-9A-Za-z.-]+)?$ ]]; then
|
||||
echo "error: VERSION '$VERSION' is not a semantic version" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf "$OUT"
|
||||
cp -R site "$OUT"
|
||||
for f in "$OUT/index.html" "$OUT/sitemap.xml" "$OUT/llms.txt"; do
|
||||
sed -i.bak -e "s/__VERSION__/${VERSION}/g" -e "s/__BUILD_DATE__/${BUILD_DATE}/g" "$f"
|
||||
rm -f "$f.bak"
|
||||
done
|
||||
|
|
@ -17,15 +24,21 @@ done
|
|||
# Release notes for this version, baked into the page ("What's new") and
|
||||
# published as version.json so open games can spot a newer release.
|
||||
NOTES="$(node scripts/release-notes.js "$VERSION")"
|
||||
node -e '
|
||||
const fs=require("fs"),[,v,d,notes]=process.argv;
|
||||
const f="_site/index.html";
|
||||
fs.writeFileSync(f,fs.readFileSync(f,"utf8").replace("/*__RELEASE_NOTES__*/[]",notes));
|
||||
fs.writeFileSync("_site/version.json",JSON.stringify({version:v,date:d,notes:JSON.parse(notes)},null,2)+"\n");
|
||||
' "$VERSION" "$BUILD_DATE" "$NOTES"
|
||||
|
||||
if grep -rl "__VERSION__\|__BUILD_DATE__" _site >/dev/null; then
|
||||
echo "error: unreplaced placeholders left in _site" >&2
|
||||
if [ "${REQUIRE_NOTES:-}" = "1" ] && [ "$NOTES" = "[]" ]; then
|
||||
echo "error: CHANGELOG.md has no '## [$VERSION]' section with bullets (still under [Unreleased]?)" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Built Series of Tubes ${VERSION} (${BUILD_DATE}) into _site/"
|
||||
node -e '
|
||||
const fs=require("fs"),[,out,v,d,notes]=process.argv;
|
||||
const f=out+"/index.html",ph="/*__RELEASE_NOTES__*/[]",html=fs.readFileSync(f,"utf8");
|
||||
if(!html.includes(ph)){console.error("error: release-notes placeholder missing from index.html");process.exit(1);}
|
||||
// Function replacer: no $& / $$ expansion. Escape "<" so a note can never close the <script>.
|
||||
fs.writeFileSync(f,html.replace(ph,()=>notes.replace(/</g,"\\u003c")));
|
||||
fs.writeFileSync(out+"/version.json",JSON.stringify({version:v,date:d,notes:JSON.parse(notes)},null,2)+"\n");
|
||||
' "$OUT" "$VERSION" "$BUILD_DATE" "$NOTES"
|
||||
|
||||
if grep -rl "__VERSION__\|__BUILD_DATE__" "$OUT" >/dev/null; then
|
||||
echo "error: unreplaced placeholders left in $OUT" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Built Series of Tubes ${VERSION} (${BUILD_DATE}) into ${OUT}/"
|
||||
|
|
|
|||
|
|
@ -2424,7 +2424,8 @@ function applyAnim(){const r=document.documentElement;r.classList.toggle('no-ani
|
|||
const toS=(wx,wy,k=0)=>[(wx+k*W-cam.x)*cam.z+CW/2,(wy-cam.y)*cam.z+CH/2];
|
||||
const iconScale=()=>clamp(Math.sqrt(cam.z),0.7,1.35);
|
||||
function rr(x,y,w,h,r){ctx.beginPath();ctx.moveTo(x+r,y);ctx.arcTo(x+w,y,x+w,y+h,r);ctx.arcTo(x+w,y+h,x,y+h,r);ctx.arcTo(x,y+h,x,y,r);ctx.arcTo(x,y,x+w,y,r);ctx.closePath();}
|
||||
function visibleKs(){const ks=[];for(const k of [-1,0,1]){const a=toS(0,0,k)[0],b=toS(W,0,k)[0];if(b>-200&&a<CW+200)ks.push(k);}return ks;}
|
||||
// Enough world copies to cover any screen width at any zoom (the map wraps horizontally).
|
||||
function visibleKs(){const ks=[];for(let k=-5;k<=5;k++){const a=toS(0,0,k)[0],b=toS(W,0,k)[0];if(b>-200&&a<CW+200)ks.push(k);}return ks;}
|
||||
const GEO=new Map();
|
||||
function linkGeom(l){const i=pairLinks(l.a,l.b).indexOf(l);const key=l.id+'|'+i+'|'+(l.cable||'');const h=GEO.get(key);if(h)return h;
|
||||
let pts=null;if(l.cable){const cp=cablePair(l.cable,l.a,l.b);if(cp){pts=cp.pts.map(p=>p.slice());const same=pairLinks(l.a,l.b).filter(x=>x.cable===l.cable).indexOf(l);if(same>0)for(let j=1;j<pts.length-1;j++){pts[j][1]+=same*5;}}}
|
||||
|
|
@ -2467,7 +2468,7 @@ function draw(now){
|
|||
// waves: one path, one stroke
|
||||
ctx.strokeStyle='rgba(255,255,255,.45)';ctx.lineWidth=2/z;ctx.lineCap='round';ctx.beginPath();
|
||||
const ph0=now/900;for(const [x,y,ph] of WAVES){const o=Math.sin(ph0+ph*6)*3;ctx.moveTo(x-9+o,y);ctx.quadraticCurveTo(x-4.5+o,y-4,x+o,y);ctx.quadraticCurveTo(x+4.5+o,y+4,x+9+o,y);}ctx.stroke();
|
||||
if(wl){ctx.setTransform(1,0,0,1,0,0);ctx.drawImage(wl.cv,Math.round(DPR*((k*W-cam.x)*z+CW/2)),Math.round(DPR*((-cam.y)*z+CH/2)));ctx.setTransform(DPR*z,0,0,DPR*z,DPR*((k*W-cam.x)*z+CW/2),DPR*((-cam.y)*z+CH/2));}else paintWorld(ctx,z,true);
|
||||
if(wl){ctx.setTransform(1,0,0,1,0,0);ctx.drawImage(wl.cv,Math.round(DPR*((k*W-cam.x)*z+CW/2)),Math.round(DPR*((-cam.y)*z+CH/2)));ctx.setTransform(DPR*z,0,0,DPR*z,DPR*((k*W-cam.x)*z+CW/2),DPR*((-cam.y)*z+CH/2));}else paintWorld(ctx,z,false);
|
||||
// clouds
|
||||
ctx.fillStyle='rgba(255,255,255,.55)';ctx.beginPath();
|
||||
for(const c of CLOUDS){const x=((c.x+now/1000*c.v)%(W+200))-100,y=c.y;ctx.moveTo(x+16*c.s,y);ctx.arc(x,y,16*c.s,0,7);ctx.moveTo(x+38*c.s,y-8*c.s);ctx.arc(x+18*c.s,y-8*c.s,20*c.s,0,7);ctx.moveTo(x+55*c.s,y);ctx.arc(x+40*c.s,y,15*c.s,0,7);}ctx.fill();
|
||||
|
|
@ -2565,6 +2566,7 @@ function drawBackhoe(x,y,now,sub){
|
|||
ctx.restore();
|
||||
}
|
||||
const LBLW={};
|
||||
try{document.fonts&&document.fonts.ready.then(()=>{for(const k in LBLW)delete LBLW[k];});}catch(e){}
|
||||
function drawCity(C,sx,sy,sc,now,lyOverride){
|
||||
const hot=(UI.hotMap||{})[C.id];
|
||||
const p=S.pops[C.id],down=p&&p.down>S.day,sel=UI.sel&&UI.sel.type==='city'&&UI.sel.id===C.id,hov=UI.hover===C.id||(UI.snap&&UI.snap.id===C.id);
|
||||
|
|
@ -2612,12 +2614,12 @@ function drawCity(C,sx,sy,sc,now,lyOverride){
|
|||
}
|
||||
|
||||
/* ---------- hit tests & input ---------- */
|
||||
function hitCity(x,y,r=28){let best=null,bd=r*iconScale();for(const C of CITIES)for(const k of [-1,0,1]){const [sx,sy]=toS(C.x,C.y,k);const d=Math.hypot(sx-x,sy+4-y);if(d<bd){bd=d;best={id:C.id,sx,sy};}}return best;}
|
||||
function hitLink(x,y){if(!S)return null;let best=null,bd=12;for(const l of S.links){const g=linkGeom(l);for(const k of [-1,0,1]){let prev=null;for(const p of g.pts){const q=toS(p[0],p[1],k);if(prev){const d=segDist(x,y,prev,q);if(d<bd){bd=d;best=l.id;}}prev=q;}}}return best;}
|
||||
function hitCity(x,y,r=28){let best=null,bd=r*iconScale();const KS=visibleKs();for(const C of CITIES)for(const k of KS){const [sx,sy]=toS(C.x,C.y,k);const d=Math.hypot(sx-x,sy+4-y);if(d<bd){bd=d;best={id:C.id,sx,sy};}}return best;}
|
||||
function hitLink(x,y){if(!S)return null;let best=null,bd=12;const KS=visibleKs();for(const l of S.links){const g=linkGeom(l);for(const k of KS){let prev=null;for(const p of g.pts){const q=toS(p[0],p[1],k);if(prev){const d=segDist(x,y,prev,q);if(d<bd){bd=d;best=l.id;}}prev=q;}}}return best;}
|
||||
function wrapCam(){cam.x=((cam.x%W)+W)%W;cam.y=clamp(cam.y,0,H);}
|
||||
const ptrs=new Map();
|
||||
cv.addEventListener('pointerdown',e=>{audioInit();cv.setPointerCapture(e.pointerId);ptrs.set(e.pointerId,{x:e.clientX,y:e.clientY});
|
||||
if(ptrs.size===2){const [a,b]=[...ptrs.values()];UI.drag={mode:'pinch',d0:Math.hypot(a.x-b.x,a.y-b.y)||1,z0:cam.z};return;}
|
||||
if(ptrs.size>=2){if(!UI.drag||UI.drag.mode!=='pinch'){const [a,b]=[...ptrs.values()];UI.drag={mode:'pinch',d0:Math.hypot(a.x-b.x,a.y-b.y)||1,z0:cam.z};UI.snap=null;cv.classList.remove('linking');}return;}
|
||||
const hit=S&&hitCity(e.clientX,e.clientY);
|
||||
if(hit&&S.pops[hit.id])UI.drag={mode:'maybeLink',from:hit.id,sx:e.clientX,sy:e.clientY,camx:cam.x,camy:cam.y,moved:false};
|
||||
else UI.drag={mode:'pan',sx:e.clientX,sy:e.clientY,camx:cam.x,camy:cam.y,moved:false};
|
||||
|
|
@ -2626,7 +2628,7 @@ cv.addEventListener('pointermove',e=>{
|
|||
if(ptrs.has(e.pointerId))ptrs.set(e.pointerId,{x:e.clientX,y:e.clientY});
|
||||
const d=UI.drag;
|
||||
if(!d){const h=S&&hitCity(e.clientX,e.clientY);UI.hover=h?h.id:null;cv.style.cursor=h?(S.pops[h.id]?'crosshair':'pointer'):(hitLink(e.clientX,e.clientY)?'pointer':'grab');return;}
|
||||
if(d.mode==='pinch'&&ptrs.size===2){const [a,b]=[...ptrs.values()];const mx=(a.x+b.x)/2,my=(a.y+b.y)/2;zoomAt(mx,my,clamp(d.z0*Math.hypot(a.x-b.x,a.y-b.y)/d.d0,0.35,3)/cam.z);return;}
|
||||
if(d.mode==='pinch'){if(ptrs.size>=2){const [a,b]=[...ptrs.values()];const mx=(a.x+b.x)/2,my=(a.y+b.y)/2;zoomAt(mx,my,clamp(d.z0*Math.hypot(a.x-b.x,a.y-b.y)/d.d0,ZMIN,ZMAX)/cam.z);}return;}
|
||||
const dx=e.clientX-d.sx,dy=e.clientY-d.sy;if(Math.hypot(dx,dy)>6)d.moved=true;
|
||||
if(d.mode==='maybeLink'&&d.moved){d.mode='link';cv.classList.add('linking');}
|
||||
if(d.mode==='link'){d.cx=e.clientX;d.cy=e.clientY;const h=hitCity(e.clientX,e.clientY,40);UI.snap=h&&h.id!==d.from?h:null;renderHint();}
|
||||
|
|
@ -2634,22 +2636,26 @@ cv.addEventListener('pointermove',e=>{
|
|||
});
|
||||
function endPtr(e){
|
||||
ptrs.delete(e.pointerId);const d=UI.drag;if(!d)return;
|
||||
if(d.mode==='pinch'){if(ptrs.size===0)UI.drag=null;return;}
|
||||
if(d.mode==='pinch'){if(ptrs.size===0){UI.drag=null;UI.snap=null;cv.classList.remove('linking');}return;}
|
||||
if(d.mode==='link'){if(UI.snap&&UI.snap.id!==d.from){openLinkModal(d.from,UI.snap.id);sfx('click');}}
|
||||
else if(!d.moved&&S){const h=hitCity(e.clientX,e.clientY);
|
||||
if(h){selectCity(h.id);sfx('click');}
|
||||
else{const l=hitLink(e.clientX,e.clientY);if(l){UI.sel={type:'link',id:l};UI.confirm=null;renderPanel();sfx('click');}else{UI.sel=null;renderPanel();}}}
|
||||
UI.drag=null;UI.snap=null;cv.classList.remove('linking');cv.style.cursor='grab';renderHint();
|
||||
}
|
||||
cv.addEventListener('pointerup',endPtr);cv.addEventListener('pointercancel',endPtr);
|
||||
function zoomAt(mx,my,f){const wx=cam.x+(mx-CW/2)/cam.z,wy=cam.y+(my-CH/2)/cam.z;cam.z=clamp(cam.z*f,0.35,6);cam.x=wx-(mx-CW/2)/cam.z;cam.y=wy-(my-CH/2)/cam.z;wrapCam();}
|
||||
// A cancelled pointer (scroll takeover, palm rejection, system gesture) is not a tap or a drop.
|
||||
function cancelPtr(e){ptrs.delete(e.pointerId);if(ptrs.size)return;UI.drag=null;UI.snap=null;cv.classList.remove('linking');cv.style.cursor='grab';renderHint();}
|
||||
cv.addEventListener('pointerup',endPtr);cv.addEventListener('pointercancel',cancelPtr);
|
||||
const ZMIN=0.35,ZMAX=6;
|
||||
function zoomAt(mx,my,f){const wx=cam.x+(mx-CW/2)/cam.z,wy=cam.y+(my-CH/2)/cam.z;cam.z=clamp(cam.z*f,ZMIN,ZMAX);cam.x=wx-(mx-CW/2)/cam.z;cam.y=wy-(my-CH/2)/cam.z;wrapCam();}
|
||||
cv.addEventListener('wheel',e=>{e.preventDefault();zoomAt(e.clientX,e.clientY,Math.exp(-e.deltaY*0.0015));},{passive:false});
|
||||
addEventListener('keydown',e=>{if(e.target.tagName==='INPUT')return;if(e.code==='Space'){e.preventDefault();UI.speed=UI.speed?0:1;renderHUD();}if(e.key==='0')ACT.speed({v:0.5});if(e.key==='1')ACT.speed({v:1});if(e.key==='2')ACT.speed({v:2});if(e.key==='3')ACT.speed({v:4});if(e.key==='4')ACT.speed({v:8});if(e.key==='Escape'&&!$('bankBox').hidden){$('bankBox').hidden=true;return;}if(e.key==='Escape'&&!$('dash').hidden){$('dash').hidden=true;return;}if(e.key==='Escape'){if(!$('modal').hidden){if(S&&UI.started&&!S.lost)closeModal();}else{UI.sel=null;renderPanel();}}});
|
||||
addEventListener('keydown',e=>{if(e.target.closest&&e.target.closest('input,textarea,select,[contenteditable]'))return;if(e.ctrlKey||e.metaKey||e.altKey)return;if(e.code==='Space'&&e.target.closest&&e.target.closest('button,a'))return;if(e.code==='Space'){e.preventDefault();UI.speed=UI.speed?0:1;renderHUD();}if(e.key==='0')ACT.speed({v:0.5});if(e.key==='1')ACT.speed({v:1});if(e.key==='2')ACT.speed({v:2});if(e.key==='3')ACT.speed({v:4});if(e.key==='4')ACT.speed({v:8});if(e.key==='Escape'&&!$('bankBox').hidden){$('bankBox').hidden=true;return;}if(e.key==='Escape'&&!$('dash').hidden){$('dash').hidden=true;return;}if(e.key==='Escape'){if(!$('modal').hidden){if(S&&UI.started&&!S.lost)closeModal();}else{UI.sel=null;renderPanel();}}});
|
||||
|
||||
/* ---------- click delegation ---------- */
|
||||
let pressing=false;
|
||||
document.addEventListener('pointerdown',e=>{if(e.target.closest('#panel,#left'))pressing=true;});
|
||||
addEventListener('pointerup',()=>setTimeout(()=>pressing=false,0));
|
||||
addEventListener('pointercancel',()=>{pressing=false;});addEventListener('blur',()=>{pressing=false;});
|
||||
document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(!b||b.disabled)return;audioInit();const fn=ACT[b.dataset.act];if(!fn)return;if(!S&&!['start','pickStart','cont','help','helpClose','newgame','mute','animSet','soundSet','closeModal','speed','bankClose','whatsNewShow','updateNow','updateLater','importPick','importGo','modeSet','scenarios','startScn','startWeekly'].includes(b.dataset.act))return;let a={};try{a=JSON.parse(b.dataset.args||'{}');}catch(_){}fn(a);});
|
||||
|
||||
/* ================= LOOP ================= */
|
||||
|
|
|
|||
|
|
@ -4,22 +4,23 @@ const fs = require('node:fs');
|
|||
const path = require('node:path');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
|
||||
const OUT = require('node:fs').mkdtempSync(require('node:path').join(require('node:os').tmpdir(), 'tubes-build-'));
|
||||
const root = path.join(__dirname, '..');
|
||||
|
||||
test('build stamps version and date into the site', () => {
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, VERSION: '9.9.9', BUILD_DATE: '2030-01-01' } });
|
||||
const html = fs.readFileSync(path.join(root, '_site', 'index.html'), 'utf8');
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, OUT, VERSION: '9.9.9', BUILD_DATE: '2030-01-01' } });
|
||||
const html = fs.readFileSync(path.join(OUT, 'index.html'), 'utf8');
|
||||
assert.match(html, /const APP_VERSION='9\.9\.9'/);
|
||||
assert.match(html, /"softwareVersion": "9\.9\.9"/);
|
||||
assert.match(fs.readFileSync(path.join(root, '_site', 'sitemap.xml'), 'utf8'), /<lastmod>2030-01-01<\/lastmod>/);
|
||||
assert.match(fs.readFileSync(path.join(OUT, 'sitemap.xml'), 'utf8'), /<lastmod>2030-01-01<\/lastmod>/);
|
||||
for (const f of ['favicon.svg', 'favicon.ico', 'apple-touch-icon.png', 'icon-192.png', 'icon-512.png', 'site.webmanifest', 'robots.txt', 'images/og-image.png', '404.html', 'CNAME', 'version.json']) {
|
||||
assert.ok(fs.existsSync(path.join(root, '_site', f)), `${f} is shipped`);
|
||||
assert.ok(fs.existsSync(path.join(OUT, f)), `${f} is shipped`);
|
||||
}
|
||||
});
|
||||
|
||||
test('version.json carries the release notes from the changelog', () => {
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, VERSION: '1.0.0', BUILD_DATE: '2026-10-23' } });
|
||||
const v = JSON.parse(fs.readFileSync(path.join(root, '_site', 'version.json'), 'utf8'));
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, OUT, VERSION: '1.0.0', BUILD_DATE: '2026-10-23' } });
|
||||
const v = JSON.parse(fs.readFileSync(path.join(OUT, 'version.json'), 'utf8'));
|
||||
assert.equal(v.version, '1.0.0');
|
||||
assert.ok(v.notes.length >= 5);
|
||||
assert.ok(v.notes.every((n) => !n.startsWith('-')));
|
||||
|
|
@ -34,3 +35,8 @@ test('head carries the SEO and social metadata', () => {
|
|||
JSON.parse(block.replace(/<\/?script[^>]*>/g, ''));
|
||||
}
|
||||
});
|
||||
|
||||
test('a release build refuses to ship without release notes', () => {
|
||||
assert.throws(() => execFileSync('bash', ['scripts/build.sh'], { cwd: root, stdio: 'pipe', env: { ...process.env, OUT, VERSION: '9.9.9', REQUIRE_NOTES: '1' } }));
|
||||
assert.throws(() => execFileSync('bash', ['scripts/build.sh'], { cwd: root, stdio: 'pipe', env: { ...process.env, OUT, VERSION: '1.0; rm -rf /' } }), 'junk versions are rejected');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ const path = require('node:path');
|
|||
const { execFileSync } = require('node:child_process');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const OUT = require('node:fs').mkdtempSync(require('node:path').join(require('node:os').tmpdir(), 'tubes-build-'));
|
||||
const root = path.join(__dirname, '..');
|
||||
|
||||
function playedGame() {
|
||||
|
|
@ -31,8 +32,8 @@ test('leaving the page saves the game', () => {
|
|||
|
||||
test('returning players see what is new after an update, once', () => {
|
||||
const { saved } = playedGame();
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, VERSION: '1.1.0', BUILD_DATE: '2026-10-23' } });
|
||||
const file = path.join(root, '_site', 'index.html');
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, OUT, VERSION: '1.1.0', BUILD_DATE: '2026-10-23' } });
|
||||
const file = path.join(OUT, 'index.html');
|
||||
const b = load({ file, storage: { 'sot-save-v1': saved, 'sot-seen-version': '1.0.0' } });
|
||||
const text = b.ev("document.getElementById('modalCard').textContent");
|
||||
assert.match(text, /New in Series of Tubes 1\.1\.0/);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue