cache versions

This commit is contained in:
Andrey Kondratev
2025-11-10 14:27:58 +05:00
parent 712c25a881
commit f6b696a5f8
7 changed files with 242 additions and 5 deletions

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
function generateVersion() {
const timestamp = Date.now();
const date = new Date().toISOString();
let gitHash = null;
let gitBranch = null;
try {
gitHash = execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).trim();
gitBranch = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }).trim();
} catch (e) {
console.warn('Warning: Could not get git info');
}
const version = {
timestamp,
date,
version: gitHash ? `${timestamp}-${gitHash}` : timestamp.toString(),
gitHash,
gitBranch,
buildDate: date
};
const outputPath = path.join(__dirname, '../public/version.json');
fs.writeFileSync(outputPath, JSON.stringify(version, null, 2));
console.log('✅ Version file generated:', version.version);
console.log(` Date: ${date}`);
if (gitHash) {
console.log(` Git: ${gitHash} (${gitBranch})`);
}
return version;
}
if (require.main === module) {
generateVersion();
}
module.exports = { generateVersion };