-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpostinstall.js
executable file
·47 lines (39 loc) · 1.03 KB
/
postinstall.js
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
#!/usr/bin/env node
const fs = require("node:fs");
const path = require("node:path");
const ARCH_MAPPING = {
ia32: "386",
x64: "amd64",
arm: "arm",
arm64: "arm64",
};
const PLATFORM_MAPPING = {
darwin: "darwin",
linux: "linux",
win32: "windows",
freebsd: "freebsd",
};
const platform = PLATFORM_MAPPING[process.platform];
const arch = ARCH_MAPPING[process.arch];
const folder = fs
.readdirSync("dist")
.find((file) => file.includes(platform) && file.includes(arch));
if (!folder) {
console.error(`No binary found for platform ${platform} and arch ${arch}`);
process.exit(1);
}
const binP = path.join(
"dist",
folder,
`create-disploy-app${platform === "windows" ? ".exe" : ""}`
);
fs.writeFileSync(
"create-disploy-app.js",
[
"#!/usr/bin/env node",
"const { spawn } = require('node:child_process');",
"const { join } = require('node:path');",
`spawn(join(__dirname, '${binP}'), process.argv.slice(2), { stdio: 'inherit' })`,
".on('exit', (code) => process.exit(code));",
].join("\n")
);