-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
prepare.ts
44 lines (37 loc) · 1.3 KB
/
prepare.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
//
// mdn-bcd-collector: prepare.ts
// A main entry point to run various scripts in a cross-platform friendly way
//
// © Gooborg Studios
// See the LICENSE file for copyright details
//
import fs from "node:fs";
import esMain from "es-main";
import exec from "./lib/exec.js";
/**
* Prepares the environment for the MDN BCD Collector.
* This function checks if the secrets.json file exists and copies it from secrets.sample.json if it doesn't.
* If the environment is not set to "production", it installs Firefox for Puppeteer.
* @returns A promise that resolves when the preparation is complete.
*/
const prepare = async () => {
// Copy secrets.sample.json to secrets.json if needed
const secretsPath = new URL("./secrets.json", import.meta.url);
const secretsSamplePath = new URL("./secrets.sample.json", import.meta.url);
if (!fs.existsSync(secretsPath)) {
fs.copyFileSync(secretsSamplePath, secretsPath);
}
if (process.env.NODE_ENV !== "production") {
// Install Firefox for Puppeteer
process.chdir("node_modules/puppeteer");
try {
await exec("node install.mjs", {PUPPETEER_PRODUCT: "firefox"}, false);
} catch (e) {
console.error(`Failure preparing Puppeteer Firefox: ${e}`);
}
process.chdir("../..");
}
};
if (esMain(import.meta)) {
await prepare();
}