-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathinstall.ts
52 lines (50 loc) · 1.68 KB
/
install.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
49
50
51
52
import puppeteer from "./mod.ts";
import { PUPPETEER_REVISIONS } from "./vendor/puppeteer-core/puppeteer/revisions.js";
import ProgressBar from "https://deno.land/x/[email protected]/mod.ts";
let product = Deno.env.get("PUPPETEER_PRODUCT");
if (product != "chrome" && product != "firefox") {
if (product != undefined) {
console.warn(`Unknown product '${product}', falling back to 'chrome'.`);
}
product = "chrome";
}
const fetcher = puppeteer.createBrowserFetcher({ product });
let revision;
if (product == "chrome") {
revision = Deno.env.get("PUPPETEER_CHROMIUM_REVISION") ||
PUPPETEER_REVISIONS.chromium;
} else if (product == "firefox") {
puppeteer._preferredRevision = PUPPETEER_REVISIONS.firefox;
const req = await fetch(
"https://product-details.mozilla.org/1.0/firefox_versions.json",
);
const versions = await req.json();
revision = versions.FIREFOX_NIGHTLY;
if (!versions.FIREFOX_NIGHTLY) {
throw new Error("Firefox version not found");
}
}
const revisionInfo = fetcher.revisionInfo(revision);
if (revisionInfo.local) {
console.log(`Already downloaded at ${revisionInfo.executablePath}`);
} else {
let progressBar: ProgressBar;
const newRevisionInfo = await fetcher.download(
revisionInfo.revision,
(current, total) => {
if (!progressBar) {
progressBar = new ProgressBar({
total,
});
}
if (!(progressBar as any).isCompleted) {
progressBar.render(current);
} else {
console.log("Done downloading. Installing now.");
}
},
);
console.log(
`Downloaded ${newRevisionInfo.product} ${newRevisionInfo.revision} to ${newRevisionInfo.executablePath} from ${newRevisionInfo.url}`,
);
}