cheatingchelsea/scripts/set-git-commit.js
Derek Slenk f6ddce9290
All checks were successful
CI / test (push) Successful in 14m6s
Deploy / deploy (push) Successful in 11m25s
Add commit hash to footer for deployment verification
- Display git commit hash in footer to track deployed version
- Create cross-platform build script to inject commit hash
- Update build process to include version information

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-16 17:42:21 -04:00

33 lines
No EOL
1.1 KiB
JavaScript

const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
try {
// Get the short commit hash
const gitCommit = execSync('git rev-parse --short HEAD').toString().trim();
// Create .env.local file with the commit hash
const envContent = `NEXT_PUBLIC_GIT_COMMIT=${gitCommit}\n`;
const envPath = path.join(process.cwd(), '.env.local');
// Read existing .env.local if it exists
let existingContent = '';
if (fs.existsSync(envPath)) {
existingContent = fs.readFileSync(envPath, 'utf8');
// Remove any existing NEXT_PUBLIC_GIT_COMMIT line
existingContent = existingContent.split('\n')
.filter(line => !line.startsWith('NEXT_PUBLIC_GIT_COMMIT='))
.join('\n');
if (existingContent && !existingContent.endsWith('\n')) {
existingContent += '\n';
}
}
// Write the updated content
fs.writeFileSync(envPath, existingContent + envContent);
console.log(`Git commit hash set: ${gitCommit}`);
} catch (error) {
console.error('Error setting git commit:', error.message);
process.exit(1);
}