#!/usr/bin/env node /** * Bump the app version one step: 0.1.7 -> 0.1.8, and 0.1.9 -> 0.2.0 — the * patch digit never reaches two digits (the working rule is one bump per * task; see AGENTS.md). * * npm run version:bump # one step up, prints old -> new * npm run version:bump -- 0.3.0 # set an explicit version * * The version is baked into the build (lib/version.ts) and shown in Settings * next to the running commit. */ import { readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; const file = path.join(import.meta.dirname, "..", "package.json"); const raw = readFileSync(file, "utf8"); const current = JSON.parse(raw).version; const explicit = process.argv[2]; let next = explicit; if (!next) { const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(current); if (!match) { console.error(`package.json version "${current}" is not x.y.z — pass one explicitly`); process.exit(1); } const major = Number(match[1]); const minor = Number(match[2]); const patch = Number(match[3]); next = patch >= 9 ? `${major}.${minor + 1}.0` : `${major}.${minor}.${patch + 1}`; } if (!/^\d+\.\d+\.\d+$/.test(next)) { console.error(`"${next}" is not a valid x.y.z version`); process.exit(1); } writeFileSync(file, raw.replace(`"version": "${current}"`, `"version": "${next}"`)); console.log(`${current} -> ${next}`);