broekema41_obsidian-vcf-con.../version-bump.mjs

67 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

import { execSync } from "child_process";
2022-12-09 22:00:16 +00:00
import { readFileSync, writeFileSync } from "fs";
const type = process.argv[2];
2022-12-09 22:00:16 +00:00
if (!["patch", "minor", "major"].includes(type)) {
console.error("Usage: npm run patch | minor | major");
process.exit(1);
}
2022-12-09 22:00:16 +00:00
try {
2026-04-17 13:31:59 +00:00
const output = execSync("git diff --name-only", { encoding: "utf-8" });
const changedFiles = output
.split("\n")
.map(f => f.trim())
.filter(Boolean);
const allowed = new Set([
"release_changelog.txt",
"release_title.txt"
]);
const invalid = changedFiles.filter(f => !allowed.has(f));
if (invalid.length > 0) {
console.error("❌ You have uncommitted changes in disallowed files:");
invalid.forEach(f => console.error(" -", f));
process.exit(1);
}
} catch (err) {
console.error("❌ Failed to check git status");
process.exit(1);
}
execSync(`npm version ${type} --no-git-tag-version`, { stdio: "inherit" });
const pkg = JSON.parse(readFileSync("package.json", "utf8"));
const version = pkg.version;
const manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
const minAppVersion = manifest.minAppVersion;
manifest.version = version;
writeFileSync("manifest.json", JSON.stringify(manifest, null, 2) + "\n");
const versions = JSON.parse(readFileSync("versions.json", "utf8"));
if (!versions[version]) {
versions[version] = minAppVersion;
}
writeFileSync("versions.json", JSON.stringify(versions, null, 2) + "\n");
execSync("git add -A", {
stdio: "inherit"
});
execSync(`git commit -m "version bump: ${version}"`, {
stdio: "inherit"
});
execSync(`git tag ${version}`, { stdio: "inherit" });
console.log(`🚀 Released ${version} ready for push \n git push && git push origin --tags`);