47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
#!/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 };
|