#!/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/signal-works/icewatch' }; // 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/signal-works/icewatch' }; 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'); }