/
lume_version.ts
41 lines (36 loc) 路 1.45 KB
/
lume_version.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
39
40
41
import { cyan, green, red } from "../../deps/colors.ts";
/** Return the latest stable version from the deno.land/x repository */
export async function getLatestVersion(): Promise<string> {
const response = await fetch("https://cdn.deno.land/lume/meta/versions.json");
const versions = await response.json();
return versions.latest;
}
/** Return the hash of the latest commit from the GitHub repository */
export async function getLatestDevelopmentVersion(): Promise<string> {
const response = await fetch(
`https://api.github.com/repos/lumeland/lume/commits/main`,
);
const commits = await response.json();
return commits.sha;
}
/** Return the current installed version */
export function getCurrentVersion(
url = new URL(import.meta.resolve("../")),
): string {
const { pathname } = url;
return pathname.match(/@([^/]+)/)?.[1] ?? `local (${pathname})`;
}
/** Check the compatibility with the current Deno version */
export function checkDenoSupport(): void {
const minimum = "1.38.0";
const current = Deno.version.deno;
if (current < minimum) {
console.log("----------------------------------------");
console.error(red("Your Deno version is not compatible with Lume"));
console.log(`Lume needs Deno ${green(minimum)} or greater`);
console.log(`Your current version is ${red(current)}`);
console.log(`Run ${cyan("deno upgrade")} and try again`);
console.log("----------------------------------------");
Deno.exit(1);
}
}