-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.ts
More file actions
66 lines (63 loc) · 1.85 KB
/
compile.ts
File metadata and controls
66 lines (63 loc) · 1.85 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { ProgressBar } from "./deps.ts";
async function checkExists(path: string) {
try {
const info = await Deno.lstat(path);
if (info.isFile && info.size !== 0) {
return true;
}
return false;
} catch {
return false;
}
}
async function prepareDenoWebview() {
let bin = localStorage.getItem("deuteron-binary");
if (bin === null || !(await checkExists(bin))) {
if (Deno.build.os !== "windows") {
console.log("Sorry only Windows is supported at the moment");
}
console.log("Deno-webview binary not found, downloading...");
bin = await Deno.makeTempFile({ prefix: "deuteron" });
localStorage.setItem("deuteron-binary", bin);
const file = await Deno.open(bin, {
write: true,
create: true,
truncate: true,
});
const response = await fetch(
"https://github.com/JasperVanEsveld/deno/releases/download/webview%2F0.1.0/deno-webview-windows.exe"
);
const length = Number.parseInt(
response.headers.get("content-length") || "70991360"
);
const progress = new ProgressBar({
title: "deno-webview-windows.exe",
total: length,
display: ":title :time :bar :percent ",
});
let current = 0;
for await (const buffer of response.body!) {
await file.write(buffer);
current += buffer.length;
progress.render(current);
}
await response.body?.pipeTo((await file).writable);
}
return bin;
}
export async function compile() {
const bin = await prepareDenoWebview();
const p = Deno.run({
cmd: [bin, "compile", ...Deno.args],
});
const code = await p.status();
if (code.success) {
console.log(
"Compilation happens in the background\nPlease wait untill the executable appears..."
);
} else {
console.log(
"Something went wrong, check to make sure if all the flags and filenames are correct"
);
}
}