31 lines
730 B
JavaScript
31 lines
730 B
JavaScript
|
|
import { execSync } from "node:child_process"
|
||
|
|
import { createRequire } from "node:module";
|
||
|
|
import { download } from "./download";
|
||
|
|
|
||
|
|
const require = createRequire(import.meta.url);
|
||
|
|
const forceBuild = process.env["npm_config_build_from_source"] == "true";
|
||
|
|
|
||
|
|
function hasPrebuilt() {
|
||
|
|
let prebuilt = false;
|
||
|
|
|
||
|
|
try {
|
||
|
|
require("node-gyp-build")("..");
|
||
|
|
prebuilt = true;
|
||
|
|
} catch (error) {
|
||
|
|
prebuilt = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return prebuilt;
|
||
|
|
}
|
||
|
|
|
||
|
|
async function install() {
|
||
|
|
console.log("[Mw] Downloading Milsko library...");
|
||
|
|
await download();
|
||
|
|
|
||
|
|
console.log("[Mw] Building from source...");
|
||
|
|
execSync("npx node-gyp rebuild", { stdio: "inherit" });
|
||
|
|
}
|
||
|
|
|
||
|
|
if (forceBuild || !hasPrebuilt()) {
|
||
|
|
install();
|
||
|
|
}
|