feat: auto bump version

This commit is contained in:
Simon 2026-01-17 13:21:10 +01:00
parent 0e17ce2c87
commit 714475881a
4 changed files with 49 additions and 15 deletions

View file

@ -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",

View file

@ -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"
}
}
}

View file

@ -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"));
}

View file

@ -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"
}