ice/scripts/generate-version.js
Claude Code ec60d6bd2a Add version footer and disable map scroll wheel zoom
- Add build-time version generation script that captures git commit info
- Create /api/version endpoint to serve version data
- Add version footer component showing commit SHA, date, and branch
- Link version SHA to commit on git.deco.sh for easy navigation
- Fix footer text duplication issue with i18n translations
- Disable mouse wheel zoom on map, require +/- buttons for better UX
- Update service worker cache to v4 with new version-footer.js

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-07 22:37:20 -04:00

72 lines
No EOL
2.1 KiB
JavaScript

#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
try {
// Get the current commit SHA (short version)
const fullSha = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
const shortSha = fullSha.substring(0, 7);
// Get the current branch name
const branch = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }).trim();
// Get the commit date
const commitDate = execSync('git log -1 --format=%cI', { encoding: 'utf8' }).trim();
// Get the commit message (first line only)
const commitMessage = execSync('git log -1 --format=%s', { encoding: 'utf8' }).trim();
const versionInfo = {
sha: fullSha,
shortSha: shortSha,
branch: branch,
commitDate: commitDate,
commitMessage: commitMessage,
buildDate: new Date().toISOString(),
gitUrl: 'https://git.deco.sh/deco/ice'
};
// Ensure dist directory exists
const distDir = path.join(__dirname, '..', 'dist');
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir, { recursive: true });
}
// Write version info to dist directory
fs.writeFileSync(
path.join(distDir, 'version.json'),
JSON.stringify(versionInfo, null, 2)
);
console.log(`✅ Generated version info: ${shortSha} (${branch})`);
console.log(`📅 Commit date: ${commitDate}`);
console.log(`📝 Message: ${commitMessage}`);
} catch (error) {
console.warn('⚠️ Could not generate version info (not in git repository?):', error.message);
// Create fallback version info
const fallbackVersion = {
sha: 'unknown',
shortSha: 'unknown',
branch: 'unknown',
commitDate: new Date().toISOString(),
commitMessage: 'No git information available',
buildDate: new Date().toISOString(),
gitUrl: 'https://git.deco.sh/deco/ice'
};
const distDir = path.join(__dirname, '..', 'dist');
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir, { recursive: true });
}
fs.writeFileSync(
path.join(distDir, 'version.json'),
JSON.stringify(fallbackVersion, null, 2)
);
console.log('📦 Created fallback version info');
}