Design election workspaces, per-election calendars and Starport cards

This commit is contained in:
unimatrix 2026-11-18 09:15:05 +00:00
commit d7b520d491
2 changed files with 2015 additions and 128 deletions

View file

@ -1,15 +1,17 @@
import {readFile,mkdir,writeFile} from 'node:fs/promises';
import {fileURLToPath} from 'node:url';
import path from 'node:path';
import {DESIGN_PAGES} from '../control-panel/public/cp-v2/cp-v2-design-catalog.mjs';
const menuSource=await readFile(new URL('../control-panel/public/cp-v2/v2.js',import.meta.url),'utf8');
const menu=JSON.parse(menuSource.slice('const menu='.length,menuSource.indexOf(';')));
const oldSource=await readFile(new URL('../control-panel/public/pages.mjs',import.meta.url),'utf8'),start=oldSource.indexOf('const pages=')+'const pages='.length;
const oldIds=new Set(Object.keys(JSON.parse(oldSource.slice(start,oldSource.indexOf(';',start)))));
const oldLayout=await readFile(new URL('../control-panel/public/panel-layout.mjs',import.meta.url),'utf8');for(const match of oldLayout.matchAll(/item\([^,]+,'([^']+)'/g))oldIds.add(match[1]);
for(const id of ['dev-panel','dev-queue','dev-approvals','dev-new','dev-archive'])oldIds.add(id);
export const designAliases={'realm/company-directory':'realm/companies','realm/company-registration':'realm/companies','realm/company-profile':'realm/companies','realm/company-members':'realm/companies','realm/company-finance':'realm/companies','realm/company-permissions':'realm/companies','realm/company-applications':'realm/companies','market/company-directory':'market/companies','market/company-profile':'market/companies'};
const implementedBankPages=new Set(['bank-authorisations','federal-reserve','dunemark-collection']);
export function auditDesign(){return menu.workspaces.flatMap(w=>w.groups.flatMap(g=>g.items.map(item=>{const key=w.id+'/'+item.id,design=DESIGN_PAGES[key],preserved=w.id==='realm'&&['item-exchange','item-listings','item-post'].includes(item.id)||['quests','kits'].includes(w.id)||w.id==='clan'&&!['clan-campaigns','clan-quests'].includes(item.id)||w.id==='bank'&&(item.id==='bank-information'||implementedBankPages.has(item.id))||w.id==='politics'||w.id==='market'&&['commodity-listings','commodity-mine'].includes(item.id)||w.id==='bureau'&&item.id!=='kit-claims'||w.id==='forge'&&['dev-panel','dev-queue','dev-approvals','dev-new','dev-archive','git-workspace','git-repositories','git-administration'].includes(item.id);return{workspace:w.label,group:g.label,key,title:item.label,existedInV1:oldIds.has(item.id),classification:w.id==='events'||['clan-campaigns','clan-quests'].includes(item.id)?'planned-placeholder':design?'new-design-only':preserved?'preserved-implemented':oldIds.has(item.id)?'v1-integration-next':'needs-design-spec',tabs:design?.tabs.map(t=>t.label)||[],fields:design?[...new Set(design.tabs.flatMap(t=>t.fields.map(f=>f.label)))]:[]};})));}
export async function writeDesignAudit(destination){const rows=auditDesign(),summary={menus:rows.length,designed:rows.filter(r=>r.classification==='new-design-only').length,integrationNext:rows.filter(r=>r.classification==='v1-integration-next').length,preserved:rows.filter(r=>r.classification==='preserved-implemented').length,uncovered:rows.filter(r=>r.classification==='needs-design-spec').map(r=>r.key),featureTabs:Object.values(DESIGN_PAGES).reduce((n,p)=>n+p.tabs.length,0)};await mkdir(destination,{recursive:true});await writeFile(path.join(destination,'design-batch.json'),JSON.stringify({summary,rows,aliases:designAliases},null,2));const lines=['DUNEREALMS V2 — NEW PAGE DESIGN BATCH','Design only. No API integration or live business changes.','',JSON.stringify(summary,null,2),''];for(const workspace of menu.workspaces){lines.push(workspace.label);for(const r of rows.filter(r=>r.workspace===workspace.label)){lines.push(' '+r.title+' ['+r.classification+'] — '+r.key);if(r.tabs.length)lines.push(' Tabs: '+r.tabs.join(' | '));}lines.push('');}lines.push('COMPANY BOOKMARK ALIASES');for(const [from,to]of Object.entries(designAliases))lines.push(from+' -> '+to);await writeFile(path.join(destination,'design-batch.txt'),lines.join('\n'));return summary;}
if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url)){const result=await writeDesignAudit(process.argv[2]||'output/cp-v2-design-batch');console.log(JSON.stringify(result));if(result.uncovered.length)process.exitCode=1;}
import {readFile,mkdir,writeFile} from 'node:fs/promises';
import {fileURLToPath} from 'node:url';
import path from 'node:path';
import {DESIGN_PAGES} from '../control-panel/public/cp-v2/cp-v2-design-catalog.mjs';
const menuSource=await readFile(new URL('../control-panel/public/cp-v2/v2.js',import.meta.url),'utf8');
const menu=JSON.parse(menuSource.slice('const menu='.length,menuSource.indexOf(';')));
const oldSource=await readFile(new URL('../control-panel/public/pages.mjs',import.meta.url),'utf8'),start=oldSource.indexOf('const pages=')+'const pages='.length;
const oldIds=new Set(Object.keys(JSON.parse(oldSource.slice(start,oldSource.indexOf(';',start)))));
const oldLayout=await readFile(new URL('../control-panel/public/panel-layout.mjs',import.meta.url),'utf8');for(const match of oldLayout.matchAll(/item\([^,]+,'([^']+)'/g))oldIds.add(match[1]);
for(const id of ['dev-panel','dev-queue','dev-approvals','dev-new','dev-archive'])oldIds.add(id);
export const designAliases={'realm/company-directory':'realm/companies','realm/company-registration':'realm/companies','realm/company-profile':'realm/companies','realm/company-members':'realm/companies','realm/company-finance':'realm/companies','realm/company-permissions':'realm/companies','realm/company-applications':'realm/companies','market/company-directory':'market/companies','market/company-profile':'market/companies'};
const electionPreview={tabs:['Applications','Voting','Results','Calendar'].map(label=>({label,fields:[]}))},advertisingPreview={tabs:['Booking agenda','Booking preview','Card templates'].map(label=>({label,fields:[]}))};
const authoredPreviewPages={'realm/citizen-elections':electionPreview,'clan/clan-elections':electionPreview,'clan/clan-advertising':advertisingPreview};
const implementedBankPages=new Set(['bank-authorisations','federal-reserve','dunemark-collection']);
export function auditDesign(){return menu.workspaces.flatMap(w=>w.groups.flatMap(g=>g.items.map(item=>{const key=w.id+'/'+item.id,design=DESIGN_PAGES[key]||authoredPreviewPages[key],preserved=w.id==='realm'&&['item-exchange','item-listings','item-post'].includes(item.id)||['quests','kits'].includes(w.id)||w.id==='clan'&&!['clan-campaigns','clan-quests'].includes(item.id)||w.id==='bank'&&(item.id==='bank-information'||implementedBankPages.has(item.id))||w.id==='politics'||w.id==='market'&&['commodity-listings','commodity-mine'].includes(item.id)||w.id==='bureau'&&item.id!=='kit-claims'||w.id==='forge'&&['dev-panel','dev-queue','dev-approvals','dev-new','dev-archive','git-workspace','git-repositories','git-administration'].includes(item.id);return{workspace:w.label,group:g.label,key,title:item.label,existedInV1:oldIds.has(item.id),classification:w.id==='events'||['clan-campaigns','clan-quests'].includes(item.id)?'planned-placeholder':design?'new-design-only':preserved?'preserved-implemented':oldIds.has(item.id)?'v1-integration-next':'needs-design-spec',tabs:design?.tabs.map(t=>t.label)||[],fields:design?[...new Set(design.tabs.flatMap(t=>t.fields.map(f=>f.label)))]:[]};})));}
export async function writeDesignAudit(destination){const rows=auditDesign(),summary={menus:rows.length,designed:rows.filter(r=>r.classification==='new-design-only').length,integrationNext:rows.filter(r=>r.classification==='v1-integration-next').length,preserved:rows.filter(r=>r.classification==='preserved-implemented').length,uncovered:rows.filter(r=>r.classification==='needs-design-spec').map(r=>r.key),featureTabs:Object.values(DESIGN_PAGES).reduce((n,p)=>n+p.tabs.length,0)};await mkdir(destination,{recursive:true});await writeFile(path.join(destination,'design-batch.json'),JSON.stringify({summary,rows,aliases:designAliases},null,2));const lines=['DUNEREALMS V2 — NEW PAGE DESIGN BATCH','Design only. No API integration or live business changes.','',JSON.stringify(summary,null,2),''];for(const workspace of menu.workspaces){lines.push(workspace.label);for(const r of rows.filter(r=>r.workspace===workspace.label)){lines.push(' '+r.title+' ['+r.classification+'] — '+r.key);if(r.tabs.length)lines.push(' Tabs: '+r.tabs.join(' | '));}lines.push('');}lines.push('COMPANY BOOKMARK ALIASES');for(const [from,to]of Object.entries(designAliases))lines.push(from+' -> '+to);await writeFile(path.join(destination,'design-batch.txt'),lines.join('\n'));return summary;}
if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url)){const result=await writeDesignAudit(process.argv[2]||'output/cp-v2-design-batch');console.log(JSON.stringify(result));if(result.uncovered.length)process.exitCode=1;}

View file

@ -1,57 +1,57 @@
import {withRealmSwitch,REALM_SWITCH_CSS} from './realm-switch.mjs';
import {HOUSE_STYLE_CSS} from './house-style.mjs';
import {bankRatesPage} from './bank-rates-page.mjs';
import{withCanonicalMenu,MAIN_MENU}from'./main-menu.mjs';
import{withMenuBadges}from'./menu-updates.mjs';
import{updatePortalNavigation}from'./portal-navigation.mjs';
// Package the authored web and worker sources without rewriting their content.
import {readFileSync,writeFileSync,openSync,writeSync,closeSync,readdirSync,statSync,mkdirSync,existsSync,rmSync,cpSync} from 'node:fs';import path from 'node:path';import {fileURLToPath} from 'node:url';
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..'),web=path.join(root,'web'),dist=path.join(root,'dist');
// Fail before packaging if a public menu destination or illustration is missing.
for(const [label,href,icon] of MAIN_MENU){
const url=new URL(href);
if(url.hostname==='www.dunerealms.com'){
const relative=url.pathname==='/'?'index.html':decodeURIComponent(url.pathname.slice(1));
if(!existsSync(path.join(web,relative)))throw Error('Broken public menu link: '+label+' -> '+relative);
}
if(!existsSync(path.join(web,'assets',icon)))throw Error('Missing menu artwork: '+label+' -> '+icon);
}
for(const [page,dependencies] of [['shop.html',['shop-landing.css','shop-embed.js']],['kits.html',['kits.css','kits.js']]]){
for(const file of dependencies)if(!existsSync(path.join(web,file)))throw Error('Missing '+page+' dependency: '+file);
}
// Menu badges are now published manually through Imperial Bureau.
const homepage=readFileSync(path.join(web,'index.html'),'utf8');
const legalNotice=homepage.match(/<aside class="legal-notice"[\s\S]*?<\/aside>/)?.[0];
if(!legalNotice)throw Error('Homepage legal notice is missing');
function preparePublicHtml(html){
let result=updatePortalNavigation(html);
if(!result.includes('class="legal-notice"')){
if(!result.includes('</body>'))throw Error('Public HTML page missing closing body');
result=result.replace('</body>',legalNotice+'</body>');
}
return result;
}
import {HOUSE_STYLE_CSS} from './house-style.mjs';
import {bankRatesPage} from './bank-rates-page.mjs';
import{withCanonicalMenu,MAIN_MENU}from'./main-menu.mjs';
import{withMenuBadges}from'./menu-updates.mjs';
import{updatePortalNavigation}from'./portal-navigation.mjs';
// Package the authored web and worker sources without rewriting their content.
import {readFileSync,writeFileSync,openSync,writeSync,closeSync,readdirSync,statSync,mkdirSync,existsSync,rmSync,cpSync} from 'node:fs';import path from 'node:path';import {fileURLToPath} from 'node:url';
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..'),web=path.join(root,'web'),dist=path.join(root,'dist');
// Fail before packaging if a public menu destination or illustration is missing.
for(const [label,href,icon] of MAIN_MENU){
const url=new URL(href);
if(url.hostname==='www.dunerealms.com'){
const relative=url.pathname==='/'?'index.html':decodeURIComponent(url.pathname.slice(1));
if(!existsSync(path.join(web,relative)))throw Error('Broken public menu link: '+label+' -> '+relative);
}
if(!existsSync(path.join(web,'assets',icon)))throw Error('Missing menu artwork: '+label+' -> '+icon);
}
for(const [page,dependencies] of [['shop.html',['shop-landing.css','shop-embed.js']],['kits.html',['kits.css','kits.js']]]){
for(const file of dependencies)if(!existsSync(path.join(web,file)))throw Error('Missing '+page+' dependency: '+file);
}
// Menu badges are now published manually through Imperial Bureau.
const homepage=readFileSync(path.join(web,'index.html'),'utf8');
const legalNotice=homepage.match(/<aside class="legal-notice"[\s\S]*?<\/aside>/)?.[0];
if(!legalNotice)throw Error('Homepage legal notice is missing');
function preparePublicHtml(html){
let result=updatePortalNavigation(html);
if(!result.includes('class="legal-notice"')){
if(!result.includes('</body>'))throw Error('Public HTML page missing closing body');
result=result.replace('</body>',legalNotice+'</body>');
}
return result;
}
// Publish the shared Exchange presentation on the public origin for strict CSP.
for(const [source,target] of [['cp-v2/cp-v2-exchange-design.mjs','codex-exchange.js'],['cp-v2/cp-v2-exchange-design.css','codex-exchange.css'],['organisation-tabs.mjs','codex-tabs.js'],['organisation-tabs.css','codex-tabs.css'],['jarvis-brand.mjs','jarvis-brand.js']]){
for(const [source,target] of [['cp-v2/cp-v2-exchange-design.mjs','codex-exchange.js'],['cp-v2/cp-v2-exchange-design.css','codex-exchange.css'],['organisation-tabs.mjs','codex-tabs.js'],['organisation-tabs.css','codex-tabs.css'],['jarvis-brand.mjs','jarvis-brand.js'],['cp-v2/cp-v2-exchange-cards.mjs','exchange-cards.js'],['cp-v2/cp-v2-exchange-cards.css','exchange-cards.css']]){
let content=readFileSync(path.join(root,'control-panel/public',source),'utf8');
if(target.endsWith('.js'))content=content.replaceAll('../jarvis-brand.mjs','./jarvis-brand.js').replaceAll('../organisation-tabs.mjs','./codex-tabs.js').replaceAll('./organisation-tabs.css','./codex-tabs.css').replaceAll('./cp-v2-exchange-design.css','./codex-exchange.css');
if(target.endsWith('.js'))content=content.replaceAll('../jarvis-brand.mjs','./jarvis-brand.js').replaceAll('../organisation-tabs.mjs','./codex-tabs.js').replaceAll('./organisation-tabs.css','./codex-tabs.css').replaceAll('./cp-v2-exchange-design.css','./codex-exchange.css').replaceAll('./cp-v2-exchange-cards.mjs','./exchange-cards.js').replaceAll('./cp-v2-exchange-cards.css','./exchange-cards.css');
writeFileSync(path.join(web,target),content);
}
writeFileSync(path.join(web,'rates-and-charges.html'),bankRatesPage());
let assetCount=0;let assetWriter=null;const types={'.html':'text/html; charset=utf-8','.css':'text/css; charset=utf-8','.js':'text/javascript; charset=utf-8','.json':'application/json; charset=utf-8','.webp':'image/webp','.png':'image/png','.mp4':'video/mp4','.zip':'application/zip','.svg':'image/svg+xml'};
function collect(directory){for(const entry of readdirSync(directory).sort()){const p=path.join(directory,entry);if(statSync(p).isDirectory())collect(p);else{const relative=path.relative(web,p).split(path.sep).join('/');if(/^assets\/seals\/[^/]+-provenance\.txt$/.test(relative)||/^assets\/organisation-deed(?:s)?-[a-z0-9-]+\.png$/.test(relative))continue;const type=types[path.extname(entry)];if(!type)throw Error('Unexpected asset: '+entry);const bytes=readFileSync(p);const payload=relative.endsWith('.html')?Buffer.from(preparePublicHtml(bytes.toString('utf8'))):relative==='portal-navigation.js'?Buffer.from(withRealmSwitch(withCanonicalMenu(withMenuBadges(bytes.toString('utf8'))))):relative==='portal-navigation.css'?Buffer.concat([bytes,Buffer.from(HOUSE_STYLE_CSS+REALM_SWITCH_CSS)]):bytes;writeSync(assetWriter,JSON.stringify('/'+relative)+':['+JSON.stringify(type)+','+JSON.stringify(payload.toString('base64'))+'],');assetCount++}}}if(existsSync(dist)){const resolved=path.resolve(dist);if(resolved!==path.join(root,'dist'))throw Error('Invalid dist directory');rmSync(resolved,{recursive:true,force:true})}
mkdirSync(path.join(dist,'server'),{recursive:true});mkdirSync(path.join(dist,'.openai'),{recursive:true});assetWriter=openSync(path.join(dist,'server/index.js'),'w');writeSync(assetWriter,'const ASSET_DATA={');collect(web);const buildCommit=process.env.GITHUB_SHA;if(buildCommit&&/^[0-9a-f]{40}$/.test(buildCommit)){writeSync(assetWriter,JSON.stringify('/ci-build.json')+':'+JSON.stringify(['application/json; charset=utf-8',Buffer.from(JSON.stringify({commit:buildCommit})).toString('base64')])+',');}writeSync(assetWriter,'};\n');
let api=['feed-api.mjs','exchange-api.mjs','forum-api.mjs','community-api.mjs','portal-api.mjs'].map(file=>readFileSync(path.join(root,'worker',file),'utf8').replace(/export /g,'')).join('\n');let runtime=readFileSync(path.join(root,'worker/runtime.mjs'),'utf8').replace(/^import .*;$/gm,'');
writeSync(assetWriter,api+'\n'+runtime);closeSync(assetWriter);cpSync(path.join(root,'.openai/hosting.json'),path.join(dist,'.openai/hosting.json'));console.log('Built Worker with',assetCount,'embedded website assets');
if(existsSync(path.join(root,'drizzle')))cpSync(path.join(root,'drizzle'),path.join(dist,'.openai/drizzle'),{recursive:true});
// Native applications consume the same compiled chrome as the public Worker.
// nginx follows the atomically promoted current release, so no stale host copy
// can retain an old Alpha version, navigation badge or rates page.
const shared=path.join(dist,'shared-chrome');mkdirSync(shared,{recursive:true});
for(const name of ['portal-navigation.js','portal-navigation.css','release.json','menu-new-items.json','rates-and-charges.html','bank-rates.css']){
let content=readFileSync(path.join(web,name));
if(name==='portal-navigation.js')content=Buffer.from(withRealmSwitch(withCanonicalMenu(withMenuBadges(content.toString('utf8')))));
if(name==='portal-navigation.css')content=Buffer.concat([content,Buffer.from(HOUSE_STYLE_CSS+REALM_SWITCH_CSS)]);
if(name.endsWith('.html'))content=Buffer.from(preparePublicHtml(content.toString('utf8')));
writeFileSync(path.join(shared,name),content);
}
writeFileSync(path.join(web,'rates-and-charges.html'),bankRatesPage());
let assetCount=0;let assetWriter=null;const types={'.html':'text/html; charset=utf-8','.css':'text/css; charset=utf-8','.js':'text/javascript; charset=utf-8','.json':'application/json; charset=utf-8','.webp':'image/webp','.png':'image/png','.mp4':'video/mp4','.zip':'application/zip','.svg':'image/svg+xml'};
function collect(directory){for(const entry of readdirSync(directory).sort()){const p=path.join(directory,entry);if(statSync(p).isDirectory())collect(p);else{const relative=path.relative(web,p).split(path.sep).join('/');if(/^assets\/seals\/[^/]+-provenance\.txt$/.test(relative)||/^assets\/organisation-deed(?:s)?-[a-z0-9-]+\.png$/.test(relative))continue;const type=types[path.extname(entry)];if(!type)throw Error('Unexpected asset: '+entry);const bytes=readFileSync(p);const payload=relative.endsWith('.html')?Buffer.from(preparePublicHtml(bytes.toString('utf8'))):relative==='portal-navigation.js'?Buffer.from(withRealmSwitch(withCanonicalMenu(withMenuBadges(bytes.toString('utf8'))))):relative==='portal-navigation.css'?Buffer.concat([bytes,Buffer.from(HOUSE_STYLE_CSS+REALM_SWITCH_CSS)]):bytes;writeSync(assetWriter,JSON.stringify('/'+relative)+':['+JSON.stringify(type)+','+JSON.stringify(payload.toString('base64'))+'],');assetCount++}}}if(existsSync(dist)){const resolved=path.resolve(dist);if(resolved!==path.join(root,'dist'))throw Error('Invalid dist directory');rmSync(resolved,{recursive:true,force:true})}
mkdirSync(path.join(dist,'server'),{recursive:true});mkdirSync(path.join(dist,'.openai'),{recursive:true});assetWriter=openSync(path.join(dist,'server/index.js'),'w');writeSync(assetWriter,'const ASSET_DATA={');collect(web);const buildCommit=process.env.GITHUB_SHA;if(buildCommit&&/^[0-9a-f]{40}$/.test(buildCommit)){writeSync(assetWriter,JSON.stringify('/ci-build.json')+':'+JSON.stringify(['application/json; charset=utf-8',Buffer.from(JSON.stringify({commit:buildCommit})).toString('base64')])+',');}writeSync(assetWriter,'};\n');
let api=['feed-api.mjs','exchange-api.mjs','forum-api.mjs','community-api.mjs','portal-api.mjs'].map(file=>readFileSync(path.join(root,'worker',file),'utf8').replace(/export /g,'')).join('\n');let runtime=readFileSync(path.join(root,'worker/runtime.mjs'),'utf8').replace(/^import .*;$/gm,'');
writeSync(assetWriter,api+'\n'+runtime);closeSync(assetWriter);cpSync(path.join(root,'.openai/hosting.json'),path.join(dist,'.openai/hosting.json'));console.log('Built Worker with',assetCount,'embedded website assets');
if(existsSync(path.join(root,'drizzle')))cpSync(path.join(root,'drizzle'),path.join(dist,'.openai/drizzle'),{recursive:true});
// Native applications consume the same compiled chrome as the public Worker.
// nginx follows the atomically promoted current release, so no stale host copy
// can retain an old Alpha version, navigation badge or rates page.
const shared=path.join(dist,'shared-chrome');mkdirSync(shared,{recursive:true});
for(const name of ['portal-navigation.js','portal-navigation.css','release.json','menu-new-items.json','rates-and-charges.html','bank-rates.css']){
let content=readFileSync(path.join(web,name));
if(name==='portal-navigation.js')content=Buffer.from(withRealmSwitch(withCanonicalMenu(withMenuBadges(content.toString('utf8')))));
if(name==='portal-navigation.css')content=Buffer.concat([content,Buffer.from(HOUSE_STYLE_CSS+REALM_SWITCH_CSS)]);
if(name.endsWith('.html'))content=Buffer.from(preparePublicHtml(content.toString('utf8')));
writeFileSync(path.join(shared,name),content);
}