Add local HTML download and release 0.0.3

This commit is contained in:
Schluffe committed 2026-10-09 15:25:56 +02:00
1 parent bee62a79a9
commit 62c749de73
10 files changed
+98 -12

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { readFile, writeFile } from 'node:fs/promises';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const dist = resolve(dirname(fileURLToPath(import.meta.url)), '../dist');
let html = await readFile(join(dist, 'index.html'), 'utf8');
const scriptTag = /<script type="module"(?: [^>]*)? src="(\.\/assets\/[^"<>]+\.js)"><\/script>/;
const scriptPath = html.match(scriptTag)?.[1];
if (!scriptPath) throw new Error('Expected a Vite JavaScript asset in dist/index.html');
const [javascript, icon] = await Promise.all([
readFile(join(dist, scriptPath)),
readFile(join(dist, 'HellNet_alt.png')),
]);
const js = javascript.toString('utf8');
if (/<\/script/i.test(js)) throw new Error('Built JavaScript contains an unsafe inline closing tag');
html = html.replace(scriptTag, '');
html = html.replace('href="./HellNet_alt.png"', `href="data:image/png;base64,${icon.toString('base64')}"`);
html = html.replace('</body>', () => ` <script>${js}</script>\n </body>`);
if (/src="\.\/assets\/|href="\.\/assets\/|href="\.\/HellNet_alt\.png"/.test(html)) {
throw new Error('Standalone HTML still references external build assets');
}
await writeFile(join(dist, 'hellcon-local.html'), html);