mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-04 03:42:26 +00:00
feat: display version hash and build date in footer
Refactored scripts/hash-dist.mjs to export buildHashState and support module import. Modified scripts/build-dist.mjs to calculate the dist hash after asset rewriting and inject it along with the current date into dist/index.html below the tagline. Verified with Playwright screenshot. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
f1c7c5755d
commit
80f6aba4a8
4 files changed
+69
-2
No files matched your search
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { execSync } from 'node:child_process';
|
||||
import crypto from 'node:crypto';
|
||||
import { buildHashState } from './hash-dist.mjs';
|
||||
|
||||
const DIST = 'dist';
|
||||
const FILES_TO_COPY = [
|
||||
@@ -154,6 +155,38 @@ function rewriteEntryHtmlAssetPaths(manifest) {
|
||||
}
|
||||
}
|
||||
|
||||
function injectVersionInfo() {
|
||||
console.log('Injecting version hash and date...');
|
||||
try {
|
||||
const hashState = buildHashState(DIST);
|
||||
const hash = hashState.combined;
|
||||
const date = new Date().toISOString().split('T')[0];
|
||||
|
||||
const indexHtmlPath = path.join(DIST, 'index.html');
|
||||
if (fs.existsSync(indexHtmlPath)) {
|
||||
let content = fs.readFileSync(indexHtmlPath, 'utf8');
|
||||
|
||||
const versionHtml = `
|
||||
<div class="mt-4 text-xs text-muted opacity-50 font-mono">
|
||||
v: ${hash.slice(0, 8)} • ${date}
|
||||
</div>`;
|
||||
|
||||
// Fallback search if whitespace differs
|
||||
const taglineRegex = /(seed\. zap\. subscribe\.\s*<\/h2>)/;
|
||||
if (taglineRegex.test(content)) {
|
||||
content = content.replace(taglineRegex, '$1' + versionHtml);
|
||||
fs.writeFileSync(indexHtmlPath, content);
|
||||
console.log(`Injected version: ${hash.slice(0, 8)} • ${date}`);
|
||||
} else {
|
||||
console.warn('Could not find tagline to inject version info.');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to inject version info:', error);
|
||||
// Continue even if injection fails, as it's not critical for functionality
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
console.log('Validating service worker compatibility guard...');
|
||||
try {
|
||||
@@ -209,6 +242,8 @@ function main() {
|
||||
console.log('Rewriting HTML entry points with hashed assets...');
|
||||
rewriteEntryHtmlAssetPaths(manifest);
|
||||
|
||||
injectVersionInfo();
|
||||
|
||||
console.log('Build complete.');
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import crypto from 'node:crypto';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
function parseArgs(argv) {
|
||||
const args = {
|
||||
@@ -72,7 +73,7 @@ function hashBuffer(buffer) {
|
||||
return crypto.createHash('sha256').update(buffer).digest('hex');
|
||||
}
|
||||
|
||||
function buildHashState(distDir) {
|
||||
export function buildHashState(distDir) {
|
||||
const resolvedDistDir = path.resolve(distDir);
|
||||
if (!fs.existsSync(resolvedDistDir)) {
|
||||
throw new Error(`Dist directory does not exist: ${resolvedDistDir}`);
|
||||
@@ -112,4 +113,6 @@ function main() {
|
||||
console.log(serialized);
|
||||
}
|
||||
|
||||
main();
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
main();
|
||||
}
|
||||
Reference in new issue
Block a user