This commit is contained in:
NotII
2025-04-06 15:48:11 +01:00
parent a651bd3ec4
commit 59a9063bfc
5 changed files with 130 additions and 2 deletions

45
scripts/get-git-hash.js Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
// Ensure the directory exists
const gitDataDir = path.resolve(__dirname, '../.next/static/git');
if (!fs.existsSync(gitDataDir)) {
fs.mkdirSync(gitDataDir, { recursive: true });
}
let gitHash = 'unknown';
try {
// Try to get the git hash
gitHash = execSync('git rev-parse --short HEAD').toString().trim();
console.log(`✅ Git commit hash: ${gitHash}`);
} catch (error) {
console.error('⚠️ Could not get git commit hash:', error.message);
}
// Write the git hash to a file that can be imported
const gitInfoFilePath = path.resolve(gitDataDir, 'git-info.json');
fs.writeFileSync(
gitInfoFilePath,
JSON.stringify({
commitHash: gitHash,
buildTime: new Date().toISOString()
}, null, 2)
);
console.log(`📝 Git info written to: ${gitInfoFilePath}`);
// Also write to a location that can be imported during development
const gitInfoDevPath = path.resolve(__dirname, '../public/git-info.json');
fs.writeFileSync(
gitInfoDevPath,
JSON.stringify({
commitHash: gitHash,
buildTime: new Date().toISOString()
}, null, 2)
);
console.log(`📝 Git info written to: ${gitInfoDevPath}`);