unroll / tools /stamp_version.mjs
SharpMeow's picture
Public API at window.unroll (schema, help, coverage test; ui and bench groups), embed mode with postMessage bridge and oEmbed, version 0.9.4 in About and API, ink_9um (9 µm) label and credit, Ink Bench hardening from the audit, hashchange without reload, capped test hooks
cc6b6d8
Raw History Blame Contribute Delete
1.06 kB
// 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}`);