-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.mjs
More file actions
30 lines (24 loc) · 900 Bytes
/
release.mjs
File metadata and controls
30 lines (24 loc) · 900 Bytes
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
import { execFileSync } from "node:child_process";
const [versionArg] = process.argv.slice(2).filter(arg => arg !== "--");
if (!versionArg) {
console.error("Release version or strategy is required. Example: yarn release -- patch");
process.exit(1);
}
const run = (command, args) => {
execFileSync(command, args, { stdio: "inherit" });
};
try {
run("yarn", ["version", "--immediate", versionArg]);
run("yarn", ["run", "version"]);
const version = execFileSync("node", ["-p", "require('./package.json').version"], {
encoding: "utf8",
}).trim();
run("git", ["add", "."]);
run("git", ["commit", "-m", `v${version}`]);
run("git", ["checkout", "-b", `release/${version}`]);
run("git", ["push", "origin", `release/${version}`]);
} catch (error) {
const message = error instanceof Error ? error.message : "Unknown error";
console.error(`Release failed: ${message}`);
process.exit(1);
}