generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.release.mjs
67 lines (53 loc) · 2.96 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
56
57
58
59
60
61
62
63
64
65
66
67
import { spawn } from "node:child_process";
import { readFileSync, writeFileSync } from "node:fs";
import readlinePromises from "node:readline/promises";
/** @param {string} filepath */
function readJson(filepath) {
return JSON.parse(readFileSync(filepath, "utf8"));
}
/** @param {string} filepath @param {object} jsonObj */
function writeJson(filepath, jsonObj) {
writeFileSync(filepath, JSON.stringify(jsonObj, null, "\t") + "\n");
}
//──────────────────────────────────────────────────────────────────────────────
// PROMPT FOR TARGET VERSION
const manifest = readJson("manifest.json");
const currentVersion = manifest.version;
const rl = readlinePromises.createInterface({ input: process.stdin, output: process.stdout });
console.info(`current version: ${currentVersion}`);
const nextVersion = await rl.question(" next version: ");
console.info("───────────────────────────");
if (!nextVersion?.match(/\d+\.\d+\.\d+/) || nextVersion === currentVersion) {
console.error("\x1b[1;31mInvalid target version given, aborting.\x1b[0m");
process.exit(1);
}
rl.close();
//──────────────────────────────────────────────────────────────────────────────
// UPDATE VERSION IN VARIOUS JSONS
manifest.version = nextVersion;
writeJson("manifest.json", manifest);
const versionsJson = readJson("versions.json");
versionsJson[nextVersion] = manifest.minAppVersion;
writeJson("versions.json", versionsJson);
const packageJson = readJson("package.json");
packageJson.version = nextVersion;
writeJson("package.json", packageJson);
const packageLock = readJson("package-lock.json");
packageLock.version = nextVersion;
packageLock.packages[""].version = nextVersion;
writeJson("package-lock.json", packageLock);
//──────────────────────────────────────────────────────────────────────────────
// UPDATE GIT REPO
const gitCommands = [
"git add manifest.json versions.json package.json package-lock.json",
`git commit --no-verify --message="release: ${nextVersion}"`, // skip hook, since only bumping
"git pull --no-progress",
"git push --no-progress",
`git tag ${nextVersion}`, // tag triggers the release action
"git push --no-progress origin --tags",
];
// INFO as opposed to `exec`, `spawn` does not buffer the output
const gitProcess = spawn(gitCommands.join(" && "), [], { shell: true });
gitProcess.stdout.on("data", (data) => console.info(data.toString().trim()));
gitProcess.stderr.on("data", (data) => console.info(data.toString().trim()));
gitProcess.on("error", (_err) => process.exit(1));