forked from dylanpyle/version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.ts
38 lines (29 loc) · 971 Bytes
/
git.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
import UserError from "./user-error.ts";
async function runCommand(...args: string[]): Promise<string> {
const cmd = Deno.run({
cmd: ["git", ...args],
stdout: "piped",
stderr: "piped",
});
const stdout = await cmd.output();
const stdoutString = new TextDecoder().decode(stdout);
const stderr = await cmd.stderrOutput();
const stderrString = new TextDecoder().decode(stderr);
const { code } = await cmd.status();
cmd.close();
if (code !== 0) {
throw new Error(`Git error: ${stderrString}`);
}
return stdoutString;
}
export async function checkPrerequisites(): Promise<void> {
const status = await runCommand("status", "--porcelain");
if (status !== "") {
throw new UserError("Cannot release with uncommitted changes");
}
}
export async function commitAndTag(version: string, fileName: string) {
await runCommand("add", fileName);
await runCommand("commit", "-m", version);
await runCommand("tag", version);
}