generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 7
/
bumpVersion.ts
81 lines (68 loc) · 1.89 KB
/
bumpVersion.ts
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
// USAGE: bun bumpVersion major OR bun bumpVersion minor OR bun bumpVersion patch [OPTIONAL: --alpha for an alpha github release]
import { readFileSync, writeFileSync } from "fs";
import { stdout } from "process";
import { parseArgs } from "util";
const { values, positionals } = parseArgs({
args: Bun.argv,
options: {
alpha: {
type: "boolean",
},
},
strict: true,
allowPositionals: true,
});
const bumpType = positionals[positionals.length - 1].toLowerCase();
if (!["major", "minor", "patch"].includes(bumpType)) {
console.error(
`Invalid bump type "${bumpType}". Must be major, minor, or patch.`,
);
process.exit(1);
}
const manifest = JSON.parse(
readFileSync(
values.alpha ? "manifest-beta.json" : "manifest.json",
"utf-8",
),
) as {
version: string;
};
console.log(manifest.version);
const [currMajor, currMinor, currPatch] = manifest.version.split(".");
if (bumpType === "major") {
manifest.version = `${parseInt(currMajor) + 1}.0.0`;
} else if (bumpType === "minor") {
console.log(currMajor);
console.log(currMinor);
console.log(currPatch);
manifest.version = `${currMajor}.${parseInt(currMinor) + 1}.0`;
} else if (bumpType === "patch") {
manifest.version = `${currMajor}.${currMinor}.${parseInt(currPatch) + 1}`;
}
if (values.alpha) {
writeFileSync("manifest-beta.json", JSON.stringify(manifest, null, 4));
manifest.version = `${manifest.version}-alpha`;
} else {
writeFileSync("manifest.json", JSON.stringify(manifest, null, 4));
}
console.log(manifest.version);
// create and push git commit and tag
(async () => {
Bun.spawnSync(["git", "add", "."]);
const commitCmd = [
"git",
"commit",
"-m",
`release version ${manifest.version}`,
];
Bun.spawnSync(commitCmd, { stdio: ["inherit", "inherit", "inherit"] });
Bun.spawnSync(["git", "tag", manifest.version]);
Bun.spawnSync([
"git",
"push",
"--atomic",
"origin",
"master",
manifest.version,
]);
})();