import {recipeCatalogue,recipeIcons} from './recipe-catalogue.mjs'; import {applySharedHeader,applySharedFooter,SHARED_FOOTER_SCRIPT,cleanLegacyChromeScript,assertSharedChrome,sharedFooterBrandScript} from './site-chrome.mjs'; import {SHARED_HEADER} from './portal-navigation.mjs'; import {sharedHomepageHeaderScript} from './homepage-header.mjs'; import {applyRealmPageDesign} from './realm-page-design.mjs'; import {publishExchangeAssets} from './public-exchange-assets.mjs'; import {createHash} from 'node:crypto'; 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 as writePlain,renameSync,unlinkSync,openSync,writeSync,closeSync,readdirSync,statSync,mkdirSync,existsSync,rmSync,cpSync} from 'node:fs';import path from 'node:path';import {fileURLToPath} from 'node:url'; function writeFileSync(file,content){const temporary=file+'.build-'+process.pid;writePlain(temporary,content);renameSync(temporary,file);} const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..'),web=path.join(root,'web'),dist=path.join(root,'dist'); const sharedRealmRuntime=readFileSync(path.join(web,'realm-design.js'),'utf8')+sharedHomepageHeaderScript()+sharedFooterBrandScript(); const sharedRealmCSS=Buffer.concat([readFileSync(path.join(web,'realm-design.css')),readFileSync(new URL('./homepage-header.css',import.meta.url)),readFileSync(new URL('./osticket-presentation.css',import.meta.url)),readFileSync(new URL('./mybb-presentation.css',import.meta.url)),readFileSync(new URL('./shared-footer.css',import.meta.url))]); // Embedded workspaces execute the same runtime through their permitted origin. writeFileSync(path.join(root,'control-panel/public/cp-v2/cp-v2-realm-design.mjs'),sharedRealmRuntime); // CP entry documents are served directly by the existing CP process. Compile their // shared chrome from the same templates as public pages, without altering forms. function compileCPChrome(directory){for(const entry of readdirSync(directory,{withFileTypes:true})){const file=path.join(directory,entry.name);if(entry.isDirectory()){if(entry.name!=='native-editor')compileCPChrome(file);continue;}if(!entry.name.endsWith('.html'))continue;const old=readFileSync(file,'utf8');if(!old.includes('dune-site-header'))continue;const next=assertSharedChrome(applySharedFooter(applySharedHeader(old,SHARED_HEADER)),SHARED_HEADER,file);if(next!==old)writeFileSync(file,next);}} compileCPChrome(path.join(root,'control-panel/public')); // 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','oscommerce-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(/