import {readFile,writeFile,readdir,mkdir,rm,copyFile,mkdtemp} from 'node:fs/promises'; import {createHash} from 'node:crypto'; import {tmpdir} from 'node:os'; import path from 'node:path'; import {execFileSync} from 'node:child_process'; import {standardHeader,standardFooter} from './site-chrome.mjs'; const root=path.resolve(import.meta.dirname,'..'); const output=path.join(root,'public/source'); const stage=await mkdtemp(path.join(tmpdir(),'zs-corresponding-source-')); const entries=[]; const hash=data=>createHash('sha256').update(data).digest('hex'); const escape=s=>s.replaceAll('&','&').replaceAll('<','<').replaceAll('"','"'); async function put(name,data){ const bytes=Buffer.isBuffer(data)?data:Buffer.from(data); const target=path.join(stage,name);await mkdir(path.dirname(target),{recursive:true});await writeFile(target,bytes); entries.push({path:name,bytes:bytes.length,sha256:hash(bytes)}); } async function include(name){await put(name,await readFile(path.join(root,name)));} async function walk(name,predicate){ for(const entry of await readdir(path.join(root,name),{withFileTypes:true})){ if(entry.isSymbolicLink())throw Error('Source export does not follow symlinks: '+name+'/'+entry.name); const file=name+'/'+entry.name; if(entry.isDirectory())await walk(file,predicate);else if(predicate(file))await include(file); } } try{ // These are implementation/build inputs, not a repository or deployment dump. await walk('src',name=>name.endsWith('.ts')); await walk('client',name=>name.endsWith('.js')); await walk('supabase/migrations',name=>name.endsWith('.sql')); const generated=/^(?:ZeyadsStuffV2.*\.html|index\.optimized\.html|inject\.js|hub-libraries\.js|account-base\.js|.+-client\.js)$/; for(const entry of await readdir(path.join(root,'public'),{withFileTypes:true})){ if(entry.isFile()&&/\.(?:html|js|css|json)$/.test(entry.name)&&!generated.test(entry.name))await include('public/'+entry.name); } await walk('public/assets',()=>true); for(const name of ['prepare-assets.mjs','prepare-source.mjs','prepare-shell.mjs','optimize-assets.mjs','site-chrome.mjs','build-single.mjs'])await include('scripts/'+name); for(const name of ['LICENSE','THIRD_PARTY.md','tsconfig.json','package-lock.json'])await include(name); const pkg=JSON.parse(await readFile(path.join(root,'package.json'),'utf8')); pkg.scripts={ 'prepare:assets':'node scripts/prepare-assets.mjs', dev:'npm run prepare:assets && wrangler dev --config wrangler.jsonc --ip 127.0.0.1', types:'wrangler types',check:'tsc --noEmit', build:'npm run prepare:assets && wrangler deploy --dry-run --outdir dist', deploy:'npm run prepare:assets && wrangler deploy --config wrangler.jsonc --keep-vars' }; await put('package.json',JSON.stringify(pkg,null,2)+'\n'); // Deployment-specific values are not program source. Supply a usable template instead. await put('wrangler.jsonc',JSON.stringify({ '$schema':'./node_modules/wrangler/config-schema.json',name:'example-hub',main:'src/index.ts', compatibility_date:'2026-10-30',compatibility_flags:['nodejs_compat'],secrets:{required:['PROXY_PASSWORD']}, assets:{directory:'./public',binding:'ASSETS',run_worker_first:true,not_found_handling:'none',html_handling:'none'}, vars:{AUTH_MODE:'accounts',SUPABASE_URL:'https://YOUR_PROJECT.supabase.co',SUPABASE_PUBLISHABLE_KEY:'REPLACE_WITH_YOUR_PUBLISHABLE_KEY',GOOGLE_AUTH_ENABLED:'false',ALLOWED_HOSTS:'discord.com,discordapp.com,discordapp.net',RENDER_RELAY_URL:'https://YOUR_RELAY.example/',JIMMY_RELAY_ENABLED:'false'} },null,2)+'\n'); const upstream=JSON.parse(await readFile(path.join(root,'compliance/upstream/manifest.json'),'utf8')); for(const item of upstream){ const data=await readFile(path.join(root,'compliance/upstream',item.archive)); if(hash(data)!==item.sha256)throw Error('Upstream source integrity mismatch: '+item.name); await put('compliance/upstream/'+item.archive,data); } await include('compliance/upstream/manifest.json'); // Carry notices for the shipped npm libraries and their installed dependencies. const visited=new Set(); async function notices(name,from=path.join(root,'node_modules')){ let directory=path.join(from,name); try{await readFile(path.join(directory,'package.json'));}catch{directory=path.join(root,'node_modules',name);} if(visited.has(directory))return;visited.add(directory); const info=JSON.parse(await readFile(path.join(directory,'package.json'),'utf8')); const label=name.replaceAll('/','__')+'-'+info.version; for(const filename of await readdir(directory))if(/^(?:licen[cs]e|copying|notice)(?:[.-]|$)/i.test(filename)){ try{await put('compliance/notices/'+label+'/'+filename,await readFile(path.join(directory,filename)));}catch(e){if(e.code!=='EISDIR')throw e;} } for(const dependency of Object.keys(info.dependencies||{}))await notices(dependency,path.join(directory,'node_modules')); } for(const name of ['@mercuryworkshop/scramjet','@mercuryworkshop/scramjet-controller','@mercuryworkshop/bare-transport','@mercuryworkshop/libcurl-transport',...Object.keys(pkg.dependencies||{})])await notices(name); const instructions=`# Corresponding source for Zeyad's Stuff\n\nApplication implementation is supplied under AGPL-3.0-only; upstream components retain their licenses. This archive contains application source, browser assets, database schema definitions, pinned dependency versions and the scripts needed to build the site.\n\n## Build\nInstall Node.js 22.12 or later and npm. Run npm ci, npm run types, then npm run build. The resulting public/ directory and Worker can be deployed with Wrangler. No original production credentials are needed to build.\n\nTo run an independent installation, replace the example values in wrangler.jsonc with your own Supabase project and relay, apply supabase/migrations in filename order to an empty project, and configure the secret bindings your chosen relay/auth mode needs using wrangler secret put. This package contains schema code, not account records, storage uploads or user content.\n\n## Proxy components\nThe immutable source snapshots and checksums in compliance/upstream cover Scramjet ${upstream.find(x=>x.name==='scramjet').version}, Bare transport and libcurl transport. Extract each archive to see its own build instructions and pinned dependency manifests. For submodule archives, extract their contents into the parent repository path specified by submoduleFor and submodulePath in manifest.json. libcurl-js includes the pinned Wisp client source separately; its client/tools scripts pin and obtain the native dependency sources required by its upstream build. The Scramjet snapshot contains its controller and Rust/Wasm rewriter sources. npm ci obtains the exact published browser distributions used by this application; building those dependencies from preferred source uses their upstream build tools.\n\nThe site copies upstream proxy distributions unmodified. Its generated inject.js prepends a dated diagnostic wrapper; the preferred wrapper source is in scripts/prepare-assets.mjs.\n\n## Scope\nExcluded: review notes, test harnesses, local experiments outside the deployed application, live development/production configurations, private keys, environment files, logs and user data. The supplied deployment template and package scripts replace environment-specific publishing instructions only. Application and schema implementation remain intact because removing them could make the corresponding source incomplete.\n\npublic/assets contains the supplied UI artwork/fonts used to build this release. Their respective owners retain their rights; inclusion does not change upstream third-party licenses.\n\nThis package can be downloaded and copied without signing in, approval, payment or unpacking keys.\n`; await put('BUILDING.md',instructions); const manifest={format:1,license:'AGPL-3.0-only',generatedAt:new Date().toISOString(),files:entries.sort((a,b)=>a.path.localeCompare(b.path)),upstream}; await rm(output,{recursive:true,force:true});await mkdir(output,{recursive:true}); for(const item of entries){ const destination=path.join(output,'files',item.path+'.txt');await mkdir(path.dirname(destination),{recursive:true}); // Binary assets and archives are offered in the download, not mislabeled as text. if(!/\.(?:png|otf|gz)$/.test(item.path))await copyFile(path.join(stage,item.path),destination); } await writeFile(path.join(output,'manifest.json'),JSON.stringify(manifest,null,2)+'\n'); await copyFile(path.join(root,'LICENSE'),path.join(output,'LICENSE.txt')); await copyFile(path.join(root,'THIRD_PARTY.md'),path.join(output,'THIRD_PARTY.md.txt')); await copyFile(path.join(stage,'BUILDING.md'),path.join(output,'BUILDING.md.txt')); await mkdir(path.join(output,'upstream'),{recursive:true}); for(const item of upstream)await copyFile(path.join(stage,'compliance/upstream',item.archive),path.join(output,'upstream',item.archive)); execFileSync('tar',['-czf',path.join(output,'corresponding-source.tar.gz'),'-C',stage,'.']); const optimized=await readdir(path.join(root,'public/optimized')); const css='/optimized/'+optimized.find(n=>n.endsWith('-design-system.css')); const js='/optimized/'+optimized.find(n=>n.endsWith('-site-shell.js')); const shell=(title,body)=>'
Open-source licenses and the source needed to build this release.
Download corresponding source · Browse source · Build instructions
AGPL license · Third-party notices · File checksums
No sign-in is needed to download source. Private configuration and user data are excluded.
')); await writeFile(path.join(output,'project.html'),shell('Application source','Download source and required assets