generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathversion-bump.mjs
More file actions
34 lines (26 loc) · 1.5 KB
/
version-bump.mjs
File metadata and controls
34 lines (26 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { readFileSync, writeFileSync, existsSync } from "fs";
import semverPrerelease from "semver/functions/prerelease.js";
const targetVersion = process.env.npm_package_version;
// Check if this is a prerelease (beta) version
const isPreRelease = semverPrerelease(targetVersion) !== null;
// Determine which manifest file to read and update
const manifestFile = isPreRelease ? "manifest-beta.json" : "manifest.json";
// For beta releases, read from manifest-beta.json if it exists, otherwise from manifest.json
let sourceManifestFile = manifestFile;
if (isPreRelease && !existsSync("manifest-beta.json")) {
sourceManifestFile = "manifest.json";
}
// read minAppVersion from the appropriate manifest and bump version
let manifest = JSON.parse(readFileSync(sourceManifestFile, "utf8"));
const { minAppVersion } = manifest;
manifest.version = targetVersion;
// Only update the appropriate manifest file
// For beta releases: only update manifest-beta.json
// For stable releases: update manifest.json (and sync to manifest-beta.json is handled by ob-bumper)
writeFileSync(manifestFile, JSON.stringify(manifest, null, "\t"));
// Always update versions.json with target version and minAppVersion
let versions = JSON.parse(readFileSync("versions.json", "utf8"));
versions[targetVersion] = minAppVersion;
writeFileSync("versions.json", JSON.stringify(versions, null, "\t"));
console.log(`Version bumped to ${targetVersion} (${isPreRelease ? 'beta' : 'stable'} release)`);
console.log(`Updated: ${manifestFile}, versions.json`);