From 714475881a4aecdf1d6c554e83792a8302fc7e1a Mon Sep 17 00:00:00 2001 From: Simon <> Date: Sat, 17 Jan 2026 13:21:10 +0100 Subject: [PATCH] feat: auto bump version --- manifest.json | 2 +- package.json | 4 ++-- version-bump.mjs | 52 ++++++++++++++++++++++++++++++++++++++---------- versions.json | 6 ++++-- 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/manifest.json b/manifest.json index 51547cb..f3aff9d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-rich-text-editor", "name": "Rich Text Editor", - "version": "1.0.1", + "version": "1.0.3", "minAppVersion": "1.5.0", "description": "A rich text markdown editor for Obsidian based on MDXEditor.", "author": "Simon Tysland", diff --git a/package.json b/package.json index 2d00ebd..372443b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "main.js", "scripts": { "dev": "node esbuild.config.mjs", - "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", + "build": "node version-bump.mjs patch && tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", "version": "node version-bump.mjs && git add manifest.json versions.json" }, "keywords": [], @@ -31,4 +31,4 @@ "react": "^19.2.0", "react-dom": "^19.2.0" } -} \ No newline at end of file +} diff --git a/version-bump.mjs b/version-bump.mjs index 55d631f..6b61a07 100644 --- a/version-bump.mjs +++ b/version-bump.mjs @@ -1,17 +1,49 @@ import { readFileSync, writeFileSync } from "fs"; -const targetVersion = process.env.npm_package_version; - -// read minAppVersion from manifest.json and bump version to target version +const requestedBump = process.argv[2]; +const bumpLevel = requestedBump ?? "patch"; +const shouldPreferPackageVersion = requestedBump === undefined; const manifest = JSON.parse(readFileSync("manifest.json", "utf8")); -const { minAppVersion } = manifest; +const versions = JSON.parse(readFileSync("versions.json", "utf8")); + +const resolveTargetVersion = () => { + if (shouldPreferPackageVersion) { + const candidate = process.env.npm_package_version; + if (candidate) { + return candidate; + } + } + + const currentVersion = manifest.version; + const [major, minor, patch] = currentVersion + .split(".") + .map((value) => Number(value)); + + if ([major, minor, patch].some((value) => Number.isNaN(value))) { + throw new Error(`invalid version string "${currentVersion}"`); + } + + if (bumpLevel === "major") { + return `${major + 1}.0.0`; + } + + if (bumpLevel === "minor") { + return `${major}.${minor + 1}.0`; + } + + if (bumpLevel !== "patch") { + throw new Error(`unsupported bump level "${bumpLevel}"`); + } + + return `${major}.${minor}.${patch + 1}`; +}; + +const targetVersion = resolveTargetVersion(); manifest.version = targetVersion; writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t")); -// update versions.json with target version and minAppVersion from manifest.json -// but only if the target version is not already in versions.json -const versions = JSON.parse(readFileSync('versions.json', 'utf8')); -if (!Object.values(versions).includes(minAppVersion)) { - versions[targetVersion] = minAppVersion; - writeFileSync('versions.json', JSON.stringify(versions, null, '\t')); +const { minAppVersion } = manifest; +if (versions[targetVersion] !== minAppVersion) { + versions[targetVersion] = minAppVersion; + writeFileSync("versions.json", JSON.stringify(versions, null, "\t")); } diff --git a/versions.json b/versions.json index 26382a1..d522255 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,5 @@ { - "1.0.0": "0.15.0" -} + "1.0.0": "0.15.0", + "1.0.2": "1.5.0", + "1.0.3": "1.5.0" +} \ No newline at end of file