import {readFile,writeFile} from 'node:fs/promises'; import path from 'node:path'; const root=path.resolve(import.meta.dirname,'..'); const read=p=>readFile(path.join(root,p),'utf8'); let html=await read('public/index.html'); html=html.replace('data-theme="dark"','data-single-file="true" data-theme="dark"'); html=html.replace(/]*\bsrc\s*=\s*["'][^"']+["'][^>]*>\s*<\/script>/gi,''); html=html.replace(//g,''); let css=(await read('public/style.css')).replace(/^@import[^\n]*\n/gm,'')+'\n'+await read('public/personality.css')+'\n'+await read('public/ui-refinement.css')+'\n'+await read('public/navigation.css')+'\n'+await read('public/workspace.css')+'\n'+await read('public/feature-ui.css')+'\n'+await read('public/design-system.css'); const data=async asset=>{const ext=path.extname(asset),mime=ext==='.png'?'image/png':ext==='.svg'?'image/svg+xml':'font/otf';return 'data:'+mime+';base64,'+(await readFile(path.join(root,'public',asset.replace(/^\//,'')))).toString('base64');}; for(const asset of new Set([...css.matchAll(/url\(['"]?(\/assets\/[^)'" ]+)['"]?\)/g)].map(x=>x[1])))css=css.replaceAll(asset,await data(asset)); for(const asset of new Set([...html.matchAll(/(?:src|href)="(\/assets\/[^\"]+)"/g)].map(x=>x[1])))html=html.replaceAll(asset,await data(asset)); html=html.replace('',''); const {build}=await import('esbuild'); let hub=(await build({entryPoints:[path.join(root,'public/hub.js')],bundle:true,format:'iife',platform:'browser',target:'es2022',write:false,legalComments:'inline',plugins:[{name:'hub-libraries',setup(b){b.onResolve({filter:/^\/hub-libraries\.js$/},()=>({path:path.join(root,'public/hub-libraries.js')}));}}]})).outputFiles[0].text; for(const asset of new Set([...hub.matchAll(/"(\/assets\/[^"\n]+)"/g)].map(m=>m[1])))hub=hub.replaceAll(asset,await data(asset)); html=html.replace('',()=>''); const notice='
Single file mode — read this first

This HTML includes the UI, font, images, games and tools. Open the file in a browser. No install needed.

Open hosted site

'; html=html.replace('
','
'+notice); html=html.replace(/
[\s\S]*?<\/details>/,'

Enter the relay passphrase in the embedded hosted view.

'); html=html.replaceAll('href="/requests"','href="https://zeyadsstuffv2.zeyadmused.workers.dev/requests"'); for(const page of ['about','terms','privacy','source/index.html'])html=html.replaceAll('href="/'+page+'"','href="https://zeyadsstuffv2.zeyadmused.workers.dev/'+page+'"'); for(const page of ['friends','profile'])html=html.replaceAll('href="/'+page+'"','href="https://zeyadsstuffv2.zeyadmused.workers.dev/'+page+'"'); html=html.replaceAll('href="/users"','href="https://zeyadsstuffv2.zeyadmused.workers.dev/users"').replaceAll('href="/account"','href="https://zeyadsstuffv2.zeyadmused.workers.dev/account"'); html=html.replace('href="/about.html"','href="https://zeyadsstuffv2.zeyadmused.workers.dev/about.html"'); html=html.replace('Download HTML','You are using the single HTML version.'); // No network code or passphrase is bundled. Local tools run directly in this file. html=html.replace('class="brand" href="/"','class="brand" href="#"'); await writeFile(path.join(root,'public/ZeyadsStuffV2.html'),html); console.log('Built single HTML file ('+Buffer.byteLength(html).toLocaleString()+' bytes).'); // Keep the older download URLs on the same current UI and embedded relay flow. await writeFile(path.join(root,'public/ZeyadsStuffV2-latest.html'),html); await writeFile(path.join(root,'public/ZeyadsStuffV2-Wisp-Dev.html'),html.replace('data-single-file="true"','data-single-file="true" data-wisp-development="true"'));