forked from p2r3/convert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildCache.js
More file actions
37 lines (31 loc) · 991 Bytes
/
buildCache.js
File metadata and controls
37 lines (31 loc) · 991 Bytes
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
import puppeteer from "puppeteer";
const server = Bun.serve({
async fetch (req) {
const path = new URL(req.url).pathname.replace("/convert/", "") || "index.html";
const file = Bun.file(`${__dirname}/dist/${path}`);
if (!(await file.exists())) return new Response("Not Found", { status: 404 });
return new Response(file);
},
port: 8080
});
const browser = await puppeteer.launch({
headless: "new",
args: ["--no-sandbox", "--disable-setuid-sandbox"]
});
const page = await browser.newPage();
await Promise.all([
new Promise(resolve => {
page.on("console", msg => {
const text = msg.text();
if (text === "Built initial format list.") resolve();
});
}),
page.goto("http://localhost:8080/convert/index.html")
]);
const cacheJSON = await page.evaluate(() => {
return window.printSupportedFormatCache();
});
const outputPath = process.argv[2] || "cache.json";
await Bun.write(outputPath, cacheJSON);
await browser.close();
server.stop();