- 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>
33 lines
No EOL
1.1 KiB
JavaScript
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);
|
|
} |