// Stamp version.json before a push: node tools/stamp_version.mjs [major|minor|patch] // With a level it bumps the version (minor for a feature push, patch for a fix); it always // refreshes the build date and the git short SHA of the commit the build sits on. import { readFileSync, writeFileSync } from 'node:fs'; import { execSync } from 'node:child_process'; const f = new URL('../version.json', import.meta.url); const v = JSON.parse(readFileSync(f, 'utf8')); const level = process.argv[2]; if (level) { const [a, b, c] = v.version.split('.').map(Number); if (!['major', 'minor', 'patch'].includes(level)) { console.error('level must be major, minor or patch'); process.exit(1); } v.version = level === 'major' ? `${a + 1}.0.0` : level === 'minor' ? `${a}.${b + 1}.0` : `${a}.${b}.${c + 1}`; } v.date = new Date().toISOString().slice(0, 10); try { v.sha = execSync('git rev-parse --short=7 HEAD').toString().trim(); } catch { v.sha = 'unknown'; } writeFileSync(f, JSON.stringify(v, null, 2) + '\n'); console.log(`${v.version} ${v.date} ${v.sha}`);