Something went wrong. Try again.
Local-first knowledge base made for Typst and the Atmosphere. typbase.at
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122#!/usr/bin/env node
// Bumps every version source in the repo to the same value:// Cargo.toml, Cargo.lock, apps/native/tauri.conf.json,// packages/engine/pkg/package.json, packages/*/package.json, and the nix// derivations.//// Android versionName/versionCode are not here: `tauri android build` writes// gen/android/app/tauri.properties from tauri.conf.json on every build (the// file is generated and gitignored).//// Usage: node scripts/release/bump-version.mjs <patch|minor|major|x.y.z> [--dry-run]// Prints the new version to stdout.
import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";import { join } from "node:path";
const root = new URL("../../", import.meta.url).pathname;const [, , bump, ...flags] = process.argv;const dryRun = flags.includes("--dry-run");
if (!bump) { console.error( "Usage: node scripts/release/bump-version.mjs <patch|minor|major|x.y.z> [--dry-run]", ); process.exit(1);}
function read(path) { return readFileSync(join(root, path), "utf8");}
function write(path, text) { if (!dryRun) writeFileSync(join(root, path), text);}
function parseVersion(value) { const match = /^(\d+)\.(\d+)\.(\d+)/.exec(value); if (!match) throw new Error(`not a semantic version: ${value}`); return [Number(match[1]), Number(match[2]), Number(match[3])];}
function nextVersion(current, kind) { if (/^\d+\.\d+\.\d+/.test(kind)) return kind;
const [major, minor, patch] = parseVersion(current); if (kind === "major") return `${major + 1}.0.0`; if (kind === "minor") return `${major}.${minor + 1}.0`; if (kind === "patch") return `${major}.${minor}.${patch + 1}`;
throw new Error(`unknown bump: ${kind}`);}
const tauriPath = "apps/native/tauri.conf.json";const tauri = JSON.parse(read(tauriPath));const version = nextVersion(tauri.version, bump);
// Cargo.toml{ const path = "Cargo.toml"; const text = read(path).replace(/^package\.version = ".*"$/m, `package.version = "${version}"`); write(path, text);}
// Cargo.lock{ const path = "Cargo.lock"; let text = read(path); for (const name of ["typbase", "engine"]) { const pattern = new RegExp(`(\\[\\[package\\]\\]\\nname = "${name}"\\nversion = ")[^"]+(")`); text = text.replace(pattern, `$1${version}$2`); } write(path, text);}
// packages/engine/pkg/package.json// wasm-pack output, but tracked so the npm manifest does not lag a bump// between engine builds. The moon build tasks reset it before wasm-pack runs.{ const path = "packages/engine/pkg/package.json"; if (existsSync(join(root, path))) { const text = read(path).replace(/^ "version": "[^"]+"/m, ` "version": "${version}"`); write(path, text); }}
// apps/native/tauri.conf.json// Patch the version line instead of re-serializing: JSON.stringify expands// arrays that oxfmt collapses, which fails fmt:check after every bump.{ const text = read(tauriPath).replace(/^ "version": "[^"]+"/m, ` "version": "${version}"`); write(tauriPath, text);}
// packages/*/package.json{ const dir = join(root, "packages"); for (const name of readdirSync(dir)) { const path = `packages/${name}/package.json`; let pkg; try { pkg = JSON.parse(read(path)); } catch { continue; } if (pkg.private) continue;
pkg.version = version; write(path, `${JSON.stringify(pkg, null, 2)}\n`); }}
// nix derivationsfor (const path of ["nix/typbase.nix", "nix/typbase-bin.nix", "nix/nixpkgs/typbase.nix"]) { const text = read(path); const pattern = /(pname = "typbase";\n\s*version = ")[^"]+(")/; if (!pattern.test(text)) throw new Error(`${path}: Typbase derivation version not found`); write(path, text.replace(pattern, `$1${version}$2`));}
console.log(version);