-
Notifications
You must be signed in to change notification settings - Fork 0
/
reload.ts
48 lines (42 loc) · 1.17 KB
/
reload.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
43
44
45
46
47
48
/**
* @file reload.ts
* @description CLI to reload Deno files as required. Pass number of commits to have the files reloaded.
* @copyright 2020-2024 Brandon Kalinowski (brandonkal)
* @license MIT
*/
export default async function reload() {
const count = Deno.args[0];
const p = new Deno.Command("git", {
args: ["diff", "--name-only", "HEAD", `HEAD~${count}`],
stdout: "piped",
});
const s1 = await p.output();
const out = new TextDecoder().decode(s1.stdout);
if (!s1.success) {
console.error("Unable to read git diff");
Deno.exit(s1.code);
}
const files = out.split("\n").filter((f) => {
f = f.trim();
if (!f) return false;
if (f.includes("wip/") || f.match(/\.test\.(ts|tsx|js|jsx)$/)) {
return false;
}
return true;
});
console.error("Fetching files:");
console.error(files.join("\n"));
async function fetchFile(mod: string) {
const url = `https://x.kite.run/lib/${mod}`;
const p = new Deno.Command("deno", {
args: ["cache", "--unstable", `-r=${url}`, url],
});
const s = await p.output();
if (!s.success) {
console.error(`Unable to fetch ${url}`);
Deno.exit(s.code);
}
}
files.forEach(fetchFile);
}
if (import.meta.main) reload();