-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.ts
More file actions
84 lines (68 loc) · 2.1 KB
/
Copy pathupdate.ts
File metadata and controls
84 lines (68 loc) · 2.1 KB
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
82
83
84
#!/usr/bin/env bun
const REPO = "indent-com/blit";
const NAME = "blit";
const DESC = "Low-latency terminal streaming client";
const PLATFORMS = [
{ os: "darwin", arch: "aarch64" },
{ os: "linux", arch: "x86_64" },
{ os: "linux", arch: "aarch64" },
] as const;
async function sha256(url: string): Promise<string> {
const res = await fetch(url, { redirect: "follow" });
if (!res.ok) throw new Error(`GET ${url}: ${res.status}`);
const hash = new Bun.CryptoHasher("sha256").update(await res.arrayBuffer()).digest("hex");
return hash;
}
async function main() {
let version = process.argv[2]?.replace(/^v/, "");
if (!version) {
const res = await fetch(`https://api.github.com/repos/${REPO}/releases/latest`);
if (!res.ok) throw new Error(`GitHub API: ${res.status}`);
version = ((await res.json()).tag_name as string).replace(/^v/, "");
}
console.log(`version: ${version}`);
process.stdout.write(`${NAME}: `);
const hashes = new Map<string, string>();
for (const p of PLATFORMS) {
const url = `https://github.com/${REPO}/releases/download/v${version}/${NAME}_${version}_${p.os}_${p.arch}.tar.gz`;
process.stdout.write(`${p.os}/${p.arch} `);
hashes.set(`${p.os}_${p.arch}`, await sha256(url));
}
console.log("ok");
const urlBase = `https://github.com/${REPO}/releases/download/v${version}/${NAME}_${version}`;
const rb = `class Blit < Formula
desc "${DESC}"
homepage "https://blit.sh"
version "${version}"
license "MIT"
on_macos do
on_arm do
url "${urlBase}_darwin_aarch64.tar.gz"
sha256 "${hashes.get("darwin_aarch64")}"
end
end
on_linux do
on_intel do
url "${urlBase}_linux_x86_64.tar.gz"
sha256 "${hashes.get("linux_x86_64")}"
end
on_arm do
url "${urlBase}_linux_aarch64.tar.gz"
sha256 "${hashes.get("linux_aarch64")}"
end
end
def install
bin.install "${NAME}"
end
test do
assert_match version.to_s, shell_output("#{bin}/${NAME} --version")
end
end
`;
await Bun.write(`Formula/${NAME}.rb`, rb);
console.log("done");
}
main().catch((e) => {
console.error(e);
process.exit(1);
});