Open History to see the last commit
1const CLI_RELEASE_REPOSITORY = "pingdotgg/t3code";
2export const CLI_RELEASES_PAGE_URL = `https://github.com/${CLI_RELEASE_REPOSITORY}/releases`;
3export const CLI_RELEASE_CHECKSUMS_FILE = "SHA256SUMS";
4export const CLI_RELEASE_BASE_URL_ENV = "T3CODE_RELEASE_BASE_URL";
5
6// Keep archive keys aligned with the Linux matrix, Windows ARM64 build, and cli_archive rows in release.yml.
7// Node single-executables do not support darwin-x64 and segfault at startup.
8const CLI_ARCHIVE_PLATFORM_KEYS = [
9 "darwin-arm64",
10 "linux-arm64",
11 "linux-x64",
12 "win32-arm64",
13 "win32-x64",
14] as const;
15export type CliArchivePlatformKey = (typeof CLI_ARCHIVE_PLATFORM_KEYS)[number];
16
17export function cliArchivePlatformKey(
18 platform: NodeJS.Platform,
19 arch: string,
20): CliArchivePlatformKey | undefined {
21 const key = `${platform}-${arch}`;
22 return CLI_ARCHIVE_PLATFORM_KEYS.find((candidate) => candidate === key);
23}
24
25/** Use System32 bsdtar on Windows; Git-for-Windows GNU tar cannot open zip archives. */
26export function cliArchiveTarCommand(
27 platform: NodeJS.Platform,
28 env: Readonly<Record<string, string | undefined>>,
29): string {
30 if (platform !== "win32") return "tar";
31 const systemRoot = env["SystemRoot"] ?? env["windir"] ?? "C:\\Windows";
32 return `${systemRoot}\\System32\\tar.exe`;
33}
34
35export function cliArchiveFileName(version: string, platformKey: CliArchivePlatformKey): string {
36 return `t3-${version}-${platformKey}.${platformKey.startsWith("win32") ? "zip" : "tar.gz"}`;
37}
38
39const CLI_RELEASE_DEFAULT_BASE_URL = `https://github.com/${CLI_RELEASE_REPOSITORY}/releases/download`;
40
41export function cliReleaseDownloadBaseUrl(
42 version: string,
43 baseUrl: string | undefined = CLI_RELEASE_DEFAULT_BASE_URL,
44): string {
45 return `${(baseUrl?.trim() || CLI_RELEASE_DEFAULT_BASE_URL).replace(/\/+$/, "")}/v${version}`;
46}
47
48export function parseChecksums(text: string): ReadonlyMap<string, string> {
49 const checksums = new Map<string, string>();
50 for (const line of text.split(/\r?\n/)) {
51 const match = /^([0-9a-fA-F]{64})\s+\*?(\S.*)$/.exec(line.trim());
52 if (match?.[1] !== undefined && match[2] !== undefined) {
53 checksums.set(match[2], match[1].toLowerCase());
54 }
55 }
56 return checksums;
57}
58
59export type CliReleaseChannel = "stable" | "nightly" | "preview";
60export const CLI_RELEASE_CHANNELS: ReadonlyArray<CliReleaseChannel> = [
61 "stable",
62 "nightly",
63 "preview",
64];
65
66export function cliReleaseChannelOf(version: string): CliReleaseChannel {
67 const channel = /^[^-+]+-(nightly|preview)\.\d{8}\.\d+$/.exec(version)?.[1];
68 return channel === "nightly" || channel === "preview" ? channel : "stable";
69}
70
71/** Page until the channel matches; nightlies can push preview/stable releases past the first page. */
72export function cliReleaseIndexPageUrl(page: number): string {
73 return `https://api.github.com/repos/${CLI_RELEASE_REPOSITORY}/releases?per_page=100&page=${page}`;
74}
75
76/** Draft assets are not downloadable. */
77export function newestCliReleaseVersion(
78 releases: ReadonlyArray<{
79 readonly tag_name: string;
80 readonly draft?: boolean | undefined;
81 }>,
82 channel: CliReleaseChannel,
83): string | undefined {
84 for (const release of releases) {
85 if (release.draft) continue;
86 const version = /^v(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(release.tag_name)?.[1];
87 if (version === undefined) continue;
88 if (cliReleaseChannelOf(version) === channel) return version;
89 }
90 return undefined;
91}