Update: version 1.2.0, new version UI features, CSP hash auto-update, bug fixes

This commit is contained in:
Krystie
2026-05-14 21:04:35 -07:00
parent a216dd882d
commit 947007438f
12 changed files with 385 additions and 44 deletions
+32 -1
View File
@@ -1,9 +1,11 @@
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const esbuild = require('esbuild');
const JS = (...parts) => path.join(__dirname, 'js', ...parts);
const DIST = path.join(__dirname, 'dist');
const INDEX_HTML = path.join(__dirname, 'index.html');
// Bundle definitions — files are concatenated in order, then minified
const bundles = {
@@ -64,6 +66,32 @@ const bundles = {
],
};
function updateInlineScriptCspHash() {
const html = fs.readFileSync(INDEX_HTML, 'utf8');
const scripts = [...html.matchAll(/<script>([\s\S]*?)<\/script>/g)];
const target = scripts.find(match => {
const block = match[1] || '';
return block.includes("license-topbar-version") || block.includes("openVersionInfo") || block.includes("widget-");
});
if (!target) {
throw new Error('Could not find inline dashboard bootstrap script in index.html');
}
const scriptContent = target[1];
const hash = crypto.createHash('sha256').update(scriptContent).digest('base64');
const updatedHtml = html.replace(
/script-src 'self' 'sha256-[^']+';/,
`script-src 'self' 'sha256-${hash}';`
);
if (updatedHtml !== html) {
fs.writeFileSync(INDEX_HTML, updatedHtml);
}
return hash;
}
async function build() {
// Ensure dist/ exists
if (!fs.existsSync(DIST)) fs.mkdirSync(DIST);
@@ -96,6 +124,8 @@ async function build() {
results[outName] = { rawSize, minSize, fileCount: files.length };
}
const cspHash = updateInlineScriptCspHash();
// Summary
console.log('\n DashCaddy Frontend Build\n');
console.log(' Bundle Files Raw Min');
@@ -108,7 +138,8 @@ async function build() {
}
console.log(' ─────────────────────────────────────────');
console.log(` ${'Total'.padEnd(18)} ${totalRaw.toFixed(1).padStart(6)} KB ${totalMin.toFixed(1).padStart(6)} KB`);
console.log(`\n Output: ${DIST}\n`);
console.log(`\n Output: ${DIST}`);
console.log(` CSP Hash: sha256-${cspHash}\n`);
}
// Watch mode