forked from ivan-lednev/obsidian-day-planner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.mjs
55 lines (45 loc) · 1.64 KB
/
release.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
// Source: https://github.com/vslinko/obsidian-outliner/blob/main/release.mjs
import cp from "node:child_process";
import fs from "node:fs";
import simpleGit from "simple-git";
const manifestFile = JSON.parse(fs.readFileSync("manifest.json"));
const version = manifestFile.version.split(".").map((p) => Number(p));
function stringify(obj) {
return JSON.stringify(obj, null, 2) + "\n";
}
if (process.argv[2] === "major") {
version[0]++;
version[1] = 0;
version[2] = 0;
} else if (process.argv[2] === "minor") {
version[1]++;
version[2] = 0;
} else if (process.argv[2] === "patch") {
version[2]++;
} else {
console.log("Usage: node release.js (major|minor|patch)");
process.exit(1);
}
const versionString = version.join(".");
manifestFile.version = versionString;
fs.writeFileSync("manifest.json", stringify(manifestFile));
const packageLockFile = JSON.parse(fs.readFileSync("package-lock.json"));
packageLockFile.version = versionString;
packageLockFile.packages[""].version = versionString;
fs.writeFileSync("package-lock.json", stringify(packageLockFile));
const packageFile = JSON.parse(fs.readFileSync("package.json"));
packageFile.version = versionString;
fs.writeFileSync("package.json", stringify(packageFile));
const versionsFile = JSON.parse(fs.readFileSync("versions.json"));
const newVersionsFile = {
[versionString]: manifestFile.minAppVersion,
...versionsFile
};
fs.writeFileSync("versions.json", stringify(newVersionsFile));
const git = simpleGit();
git
.add(["manifest.json", "package-lock.json", "package.json", "versions.json"])
.commit(versionString, { "--no-verify": null })
.tag([versionString])
.push()
.pushTags();