-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathauto-update.ts
42 lines (38 loc) · 1.57 KB
/
auto-update.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
42
import { ESCAPE_SEQUENCES } from "datex-core-legacy/utils/logger.ts";
import { Path } from "./src/utils/path.ts";
export async function handleAutoUpdate(baseLibPath: Path, name: string) {
const { renderMarkdown } = await import("https://deno.land/x/[email protected]/mod.ts");
baseLibPath = baseLibPath.asDir()
// console.log("Finding updates for " + name + " (" + baseLibPath + ")")
const currentCachedVersion = (await import(baseLibPath.getChildPath("./VERSION.ts").toString())).default;
const currentVersion = (await baseLibPath.getChildPath("VERSION").getTextContent()).replaceAll("\n","")
// TODO: check if current version higher?
if (currentCachedVersion !== currentVersion) {
let changelog = "";
try {
changelog = (await baseLibPath.getChildPath("CHANGELOG.md").getTextContent())
}
catch {
changelog = "Not available";
}
console.log(`\n${ESCAPE_SEQUENCES.BOLD}New ${name} release:${ESCAPE_SEQUENCES.RESET} ${currentCachedVersion} -> ${ESCAPE_SEQUENCES.UNYT_GREEN}${currentVersion}${ESCAPE_SEQUENCES.RESET}`)
console.log(`${ESCAPE_SEQUENCES.BOLD}Changelog:\n${ESCAPE_SEQUENCES.RESET}${renderMarkdown(changelog)}\n`)
return confirm("Update");
}
return false;
}
export async function updateCache(module: URL|string) {
const denoLock = Path.File(Deno.cwd()).asDir().getChildPath("deno.lock");
if (denoLock.fs_exists) {
Deno.removeSync(denoLock.normal_pathname)
}
console.log("-> updating " + module)
const cacheReloadCommand = new Deno.Command(Deno.execPath(), {
args: [
"cache",
"--reload",
module.toString()
]
});
await cacheReloadCommand.output()
}