// Generates packaging/Payload.g.cs: the runtime plugin files embedded as C# // base64 arrays so the installer is a single self-contained .exe. // // usage: node packaging/generate-payload.mjs import fs from 'node:fs'; import path from 'node:path'; const root = path.resolve(process.argv[2] || '.'); const out = path.resolve(process.argv[3] || path.join(root, 'packaging', 'Payload.g.cs')); // Only the bundle runtime files: sources, docs and dev tooling are not needed // on an end user's machine. const FILES = [ 'package.json', 'cordis.patch.yml', 'index.js', 'client.js', 'icon.svg', 'locale/en.json', 'locale/zh.json', ]; const manifest = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); const chunks = []; for (const relative of FILES) { const buffer = fs.readFileSync(path.join(root, relative)); const base64 = buffer.toString('base64'); const parts = []; for (let i = 0; i < base64.length; i += 4000) parts.push(base64.slice(i, i + 4000)); chunks.push({ path: relative, parts }); } const quote = (value) => JSON.stringify(value); const lines = []; lines.push('// Generated by packaging/generate-payload.mjs — do not edit. '); lines.push('namespace DshThemeInstaller {'); lines.push(' internal static class Payload {'); lines.push(` internal const string BundleVersion = ${quote(manifest.version)};`); lines.push(` internal const string BundleName = ${quote(manifest.name)};`); lines.push(' internal static readonly string[] Paths = new string[] {'); for (const chunk of chunks) lines.push(` ${quote(chunk.path)},`); lines.push(' };'); lines.push(' internal static readonly string[] Data = new string[] {'); for (const chunk of chunks) lines.push(` ${chunk.parts.map((part) => quote(part)).join(' +\n ')},`); lines.push(' };'); lines.push(' }'); lines.push('}'); lines.push(''); fs.writeFileSync(out, lines.join('\n')); const bytes = chunks.reduce((total, chunk) => total + chunk.parts.join('').length, 0); console.log(`wrote ${out} (${FILES.length} files, ${(bytes / 1024).toFixed(1)} KiB base64 payload)`);