plugins/website/scripts/build-patchnotes.mjs
2026-11-27 23:43:05 +00:00

13 lines
7.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {readFileSync,writeFileSync,readdirSync} from 'node:fs';import {validatePatchnotes,releaseFile} from './patchnote-policy.mjs';
const scripts=new URL('./',import.meta.url),web=new URL('../web/',import.meta.url),read=name=>JSON.parse(readFileSync(new URL(name,scripts),'utf8')),pending=read('pending-patchnotes.json'),releases=read('changelog.json'),register=read('task-register.json');validatePatchnotes(register,pending,releases);
const esc=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
const urgent=releases.filter(r=>r.kind==='bugfix').slice(0,3);const urgentCards=urgent.length?'<section class="urgent-bugfix-news" aria-label="Urgent development bugfixes"><h2>Urgent bugfix reports</h2><div>'+urgent.map(r=>'<article><img src="assets/bugfix-seal.svg" alt=""><p>BUGFIX · '+esc(r.version)+'</p><h3><a href="'+releaseFile(r.version)+'">'+esc(r.title)+'</a></h3><p>'+esc(r.synopsis)+'</p><a href="'+releaseFile(r.version)+'">Problem, repair & verification →</a></article>').join('')+'</div></section>':'';
for(const file of readdirSync(web).filter(x=>x.endsWith('.html'))){let text=readFileSync(new URL(file,web),'utf8');text=text.replace(/<section class="urgent-bugfix-news"[\s\S]*?<\/section>/g,'');if(urgentCards&&['news.html','index.html'].includes(file))text=text.replace(/(<nav id="realm-menu"[\s\S]*?<\/nav>)/,'$1'+urgentCards);text=text.replace(/<footer>[\s\S]*?<\/footer>/,footer=>footer.includes('href="patch-notes.html"')?footer:footer.replace('<a href="staff.html">','<a href="patch-notes.html">Patch notes →</a><a href="staff.html">'));if(file==='news.html'&&!text.includes('class="development-news-link"'))text=text.replace(/(<nav id="realm-menu"[\s\S]*?<\/nav>)/,'$1<aside class="development-news-link"><a class="button gold" href="patch-notes.html">Website & plugin patch notes →</a><p>Game dispatches appear below. Development releases have their own register.</p></aside>');writeFileSync(new URL(file,web),text)}
const base=readFileSync(new URL('index.html',web),'utf8'),header=base.match(/<header\b[^>]*>[\s\S]*?<\/header>/)[0].replace(/ aria-current="page"/g,''),menu=(base.match(/<nav id="realm-menu"[\s\S]*?<\/nav>/)?.[0]||'<nav aria-label="Release register"><a href="patch-notes.html">All releases</a> · <a href="news.html">News</a></nav>'),footer=base.match(/<footer>[\s\S]*?<\/footer>/)[0];
function shell(title,body){return '<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>'+esc(title)+' — dunerealms.com</title><meta name="description" content="dunerealms.com development releases, urgent bugfix reports and pending feature bundles."><link rel="icon" href="assets/favicon.svg">'+['styles','pages','minecraft','lore','patchnotes'].map(x=>'<link rel="stylesheet" href="'+x+'.css">').join('')+'<link rel="stylesheet" href="portal-navigation.css"><script src="portal-navigation.js" defer></script><script src="pages.js" defer></script><script src="patchnotes.js" defer></script></head><body><a class="skip" href="#patchnotes-content">Skip to content</a>'+header+'<main><section class="page-intro intro-patchnotes"><p class="eyebrow">dunerealms.com / GUILD CHANGE REGISTER</p><h1>'+esc(title)+'</h1><p>Traceable changes to the website and plugin. Completed work, published bundles and urgent repairs.</p></section>'+menu+'<div id="patchnotes-content" class="patchnotes-content">'+body+'</div></main>'+footer+'<div class="toast" role="status" aria-live="polite"></div></body></html>'}
const stats='<section class="patch-stats"><div><strong>'+releases.filter(x=>x.kind==='normal').length+'</strong><span>Published bundles</span></div><div><strong>'+releases.filter(x=>x.kind==='bugfix').length+'</strong><span>Urgent bugfix reports</span></div><div><strong>'+pending.completed.length+' / 5</strong><span>Completed tasks toward next bundle</span></div></section>';
const cards=releases.map(r=>'<article class="patch-card kind-'+r.kind+'" data-kind="'+r.kind+'"><p class="patch-kind">'+(r.kind==='bugfix'?'URGENT BUGFIX':'BUNDLED PRODUCT UPDATE')+' · '+esc(r.version)+'</p><h3><a href="'+releaseFile(r.version)+'">'+esc(r.title)+'</a></h3><p>'+esc(r.synopsis)+'</p><small>'+esc(r.date)+' · '+r.tasks.length+' product '+(r.tasks.length===1?'task':'tasks')+'</small><a href="'+releaseFile(r.version)+'">Read full patch note →</a></article>').join('');
const waiting=pending.completed.map(t=>'<article class="pending-task"><p class="patch-kind">'+t.promptIds.map(esc).join(' · ')+' / '+esc(t.priority)+'</p><h3>'+esc(t.title)+'</h3><ul>'+t.changes.map(c=>'<li>'+esc(c)+'</li>').join('')+'</ul><small>Completed '+esc(t.completedAt)+' · awaiting a normal bundle</small></article>').join('');
writeFileSync(new URL('patch-notes.html',web),shell('Patch Notes',stats+'<section class="patch-register"><div class="patch-toolbar"><h2>Published register</h2><label>Type<select id="patch-kind"><option value="all">All releases</option><option value="normal">Product bundles</option><option value="bugfix">Urgent bugfixes</option></select></label></div><div id="patch-releases" class="patch-grid">'+cards+'</div><div id="patch-empty" class="patch-empty"'+(cards?' hidden':'')+'><h3>'+(cards?'No matching releases':'The first bundle is being assembled')+'</h3><p>Normal patchnotes collect 5–10 completed product tasks. Individual features can already be live while their release note is waiting for enough completed work.</p></div></section><section class="patch-pending"><p class="eyebrow">COMPLETED WORK / NOT YET A RELEASE NOTE</p><h2>Next normal bundle</h2><p>'+pending.completed.length+' completed product tasks are recorded. '+Math.max(0,5-pending.completed.length)+' more are needed before a normal bundle can be written. Workflow agreements do not count toward the threshold.</p><div class="patch-grid">'+waiting+'</div></section><aside class="patch-policy"><h3>How this register works</h3><p>Normal updates group 5–10 genuine completed product tasks, retaining their DUNE ticket IDs. Urgent bugfixes are published separately with the problem, repair and verification; they do not wait for a feature bundle. A deployment is not automatically a new patchnote.</p><p>This register starts with the new system. Earlier development remains in the repository and <a href="staff.html">contribution record</a>; no historical releases have been invented. <a href="news.html">Live game news</a> remains separate.</p><a href="tickets.html">Report a problem through support tickets →</a></aside>'));
for(const r of releases){const details=r.tasks.map(t=>'<section class="release-task"><p class="patch-kind">'+t.promptIds.map(esc).join(' · ')+'</p><h3>'+esc(t.title)+'</h3><ul>'+t.changes.map(c=>'<li>'+esc(c)+'</li>').join('')+'</ul>'+((t.checks||[]).length?'<h4>Verification</h4><ul>'+t.checks.map(c=>'<li>'+esc(c)+'</li>').join('')+'</ul>':'')+'</section>').join('');writeFileSync(new URL(releaseFile(r.version),web),shell(r.kind==='bugfix'?'Urgent Bugfix':'Product Update','<article class="patch-detail"><a href="patch-notes.html">← Patchnote archive</a><p class="patch-kind">'+esc(r.version)+' · '+esc(r.date)+'</p><h2>'+esc(r.title)+'</h2><p>'+esc(r.synopsis)+'</p>'+(r.kind==='bugfix'?'<div class="bugfix-report"><h3>Problem</h3><p>'+esc(r.problem)+'</p><h3>Repair</h3><p>'+esc(r.fix)+'</p><h3>Checks</h3><ul>'+r.checks.map(x=>'<li>'+esc(x)+'</li>').join('')+'</ul></div>':'')+details+'</article>'))}
console.log('Built patchnote register:',releases.length,'releases;',pending.completed.length,'normal tasks pending');