-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
67 lines (49 loc) · 1.69 KB
/
index.mjs
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
67
import child_process from "node:child_process";
import fs from "node:fs";
import https from "node:https";
import path from "node:path";
import process from "node:process";
import * as semver from "semver";
import * as tar from "tar";
import nodeManifest from "./package.json" assert { type: "json"};
const version = nodeManifest.devDependencies.nw.slice(1);
const parsedVersion = semver.parse(version);
const nwVersion = `${parsedVersion.major}.${parsedVersion.minor}.${parsedVersion.patch}`;
const headersUrl = `https://dl.nwjs.io/v${nwVersion}/nw-headers-v${nwVersion}.tar.gz`;
const headersPath = path.resolve(process.cwd(), `nw-headers-v${nwVersion}.tar.gz`);
await main();
async function downloadHeaders() {
const writeStream = fs.createWriteStream(headersPath);
return new Promise((resolve, reject) => {
https.get(headersUrl, (res) => {
let chunks = 0;
res.on("data", (chunk) => {
chunks += chunk;
});
res.on("end", () => {
resolve(chunks);
});
res.on("error", (error) => {
reject(error);
});
res.pipe(writeStream);
});
});
}
async function decompressHeaders() {
await fs.promises.rm('./node', { recursive: true, force: true });
await tar.extract({
file: headersPath,
C: process.cwd(),
});
}
async function rebuild() {
child_process.execSync(`node-gyp rebuild --target=${nodeManifest.volta.node} --nodedir=${path.resolve('node')}`);
}
export async function main() {
if (fs.existsSync(headersPath) === false) {
await downloadHeaders();
}
await decompressHeaders();
rebuild();
}