generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathupdate-version.mjs
executable file
·92 lines (79 loc) · 3.16 KB
/
update-version.mjs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
import { readFileSync, writeFileSync } from "fs";
import { execSync } from "child_process";
// Get command line arguments
const newVersion = process.argv[2];
const isBeta = process.argv[3] === "beta";
if (!newVersion) {
console.error("Error: Version number is required");
console.log("Usage: node update-version.mjs <version> [beta]");
process.exit(1);
}
// Base version validation (x.y.z format)
if (!/^\d+\.\d+\.\d+(-\w+(\.\d+)?)?$/.test(newVersion)) {
console.error("Error: Version must be in format x.y.z or x.y.z-label.n");
process.exit(1);
}
// Apply the -beta suffix if it's a beta version and doesn't already have a suffix
let versionWithSuffix = newVersion;
if (isBeta && !newVersion.includes("-")) {
versionWithSuffix = `${newVersion}-beta`;
}
console.log(`Updating to version ${versionWithSuffix}${isBeta ? " (beta)" : ""}`);
// Update package.json
try {
const packageJson = JSON.parse(readFileSync("package.json", "utf8"));
packageJson.version = versionWithSuffix;
writeFileSync("package.json", JSON.stringify(packageJson, null, 2) + "\n");
console.log("✅ Updated package.json");
} catch (error) {
console.error("❌ Failed to update package.json:", error.message);
process.exit(1);
}
// Get minAppVersion from manifest.json
let minAppVersion;
try {
const manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
minAppVersion = manifest.minAppVersion;
} catch (error) {
console.error("❌ Failed to read minAppVersion from manifest.json:", error.message);
process.exit(1);
}
// Update manifest.json
try {
const manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
manifest.version = versionWithSuffix;
writeFileSync("manifest.json", JSON.stringify(manifest, null, 2) + "\n");
console.log(`✅ Updated manifest.json`);
} catch (error) {
console.error(`❌ Failed to update manifest.json:`, error.message);
process.exit(1);
}
// Update versions.json
try {
const versions = JSON.parse(readFileSync("versions.json", "utf8"));
versions[versionWithSuffix] = minAppVersion;
writeFileSync("versions.json", JSON.stringify(versions, null, 2) + "\n");
console.log("✅ Updated versions.json");
} catch (error) {
console.error("❌ Failed to update versions.json:", error.message);
process.exit(1);
}
// Create git commit and tag
try {
const filesToCommit = ["package.json", "manifest.json", "versions.json"];
execSync(`git add ${filesToCommit.join(" ")}`);
execSync(`git commit -m "Bump version to ${versionWithSuffix}${isBeta ? " (beta)" : ""}"`);
execSync(`git tag -a ${versionWithSuffix} -m "Version ${versionWithSuffix}${isBeta ? " (beta)" : ""}"`);
console.log(`✅ Created git commit and tag ${versionWithSuffix}`);
console.log("\nNext steps:");
console.log(`- Push changes: git push origin master`);
console.log(`- Push tag: git push origin ${versionWithSuffix}`);
console.log(`- Create a GitHub release for tag ${versionWithSuffix} and upload the plugin files`);
if (isBeta) {
console.log(` (Mark this release as a pre-release on GitHub)`);
}
} catch (error) {
console.error("❌ Failed to create git commit or tag:", error.message);
console.log("You may need to commit and tag manually.");
}