53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const templatePath = path.join(root, 'shared-html', 'index.template.html');
|
|
const template = fs.readFileSync(templatePath, 'utf8');
|
|
|
|
const variants = {
|
|
web: {
|
|
styles_href: '/static/styles.css',
|
|
app_src: '/static/app.js?v=20260227-shared-core-1',
|
|
web_downloads: `<div class="auth-downloads">
|
|
<span>Desktop downloads:</span>
|
|
<a href="/static/installers/chattz-windows.exe">Windows</a>
|
|
<a href="/static/installers/chattz-linux.rpm">Linux (RPM)</a>
|
|
</div>`,
|
|
desktop_updater: '',
|
|
outPath: path.join(root, 'static', 'index.html'),
|
|
},
|
|
desktop: {
|
|
styles_href: '../static/styles.css',
|
|
app_src: 'app.js?v=20260227-shared-core-1',
|
|
web_downloads: '',
|
|
desktop_updater: `<div id="update-notifier" class="update-notifier hidden">
|
|
<button id="update-download-btn" title="Download Update"><i data-lucide="download"></i></button>
|
|
<button id="update-install-btn" title="Install Update" class="hidden"><i data-lucide="arrow-up-circle"></i></button>
|
|
</div>`,
|
|
outPath: path.join(root, 'desktop', 'index.html'),
|
|
},
|
|
};
|
|
|
|
for (const variant of Object.values(variants)) {
|
|
let output = template;
|
|
for (const [key, value] of Object.entries(variant)) {
|
|
if (key === 'outPath') continue;
|
|
const token = `{{${key}}}`;
|
|
if (value === '') {
|
|
output = output.replace(new RegExp(`^[ \\t]*\\{\\{${key}\\}\\}[ \\t]*\\n?`, 'm'), '');
|
|
continue;
|
|
}
|
|
output = output.replaceAll(token, value);
|
|
}
|
|
|
|
if (/\{\{[a-z_]+\}\}/i.test(output)) {
|
|
throw new Error(`Unresolved template placeholders remain in ${variant.outPath}`);
|
|
}
|
|
|
|
fs.writeFileSync(
|
|
variant.outPath,
|
|
`<!-- Generated from shared-html/index.template.html. Do not edit directly. -->\n${output}`,
|
|
'utf8'
|
|
);
|
|
}
|