-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.ts
35 lines (31 loc) · 885 Bytes
/
utils.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
export function defer(callback: () => void): Disposable {
return {
[Symbol.dispose]: () => callback(),
};
}
export function asyncDefer(callback: () => Promise<void>): AsyncDisposable {
return {
[Symbol.asyncDispose]: async () => await callback(),
};
}
export async function getCommitSha() {
const cmd = new Deno.Command("git", {
args: ["rev-parse", "--short", "HEAD"],
});
try {
const { stdout } = await cmd.output();
const sha = new TextDecoder().decode(stdout).trim();
return sha;
} catch (error) {
console.error(`Failed to get commit SHA: ${error}`);
return undefined;
}
}
export async function getYalsVersion() {
try {
return Deno.readTextFileSync(`${import.meta.dirname}/gitSha.txt`)
.trim();
} catch {
return await getCommitSha();
}
}