a simple web player for subsonic
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import { readFileSync, writeFileSync } from "node:fs";import { resolve } from "node:path";
const files = [ "frontend/package.json", "frontend/package-lock.json", "build/config.yml", "frontend/src/lib/dialogs/SettingsModal.svelte", "flake.nix",];
const semver_re = /^(\d+)\.(\d+)\.(\d+)$/;const input = process.argv[2];
if (!input) { console.error("usage: node scripts/version.mjs <major|minor|patch|x.y.z>"); process.exit(1);}
const current_version = JSON.parse( readFileSync(resolve("frontend/package.json"), "utf8"),).version;
const match = current_version.match(semver_re);if (!match) { throw new Error( `frontend/package.json version not semver: ${current_version}`, );}
const [, major, minor, patch] = match;const new_version = input === "major" ? `${Number(major) + 1}.0.0` : input === "minor" ? `${major}.${Number(minor) + 1}.0` : input === "patch" ? `${major}.${minor}.${Number(patch) + 1}` : input;
if (!semver_re.test(new_version)) { throw new Error(`invalid semver: ${input}`);}
if (new_version === current_version) { console.log(`version unchanged: ${current_version}`); process.exit(0);}
for (const path of files) { const resolved = resolve(path); const original = readFileSync(resolved, "utf8"); const count = original.split(current_version).length - 1;
if (count === 0) { throw new Error(`missing ${current_version} in ${path}`); }
writeFileSync(resolved, original.replaceAll(current_version, new_version)); console.log(`updated ${path} (${count})`);}
console.log(`bumped ${current_version} -> ${new_version}`);