-
Notifications
You must be signed in to change notification settings - Fork 27
/
postinstall.js
53 lines (46 loc) · 1.59 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
48
49
50
51
52
53
const path = require("path");
const fs = require("fs");
const installMacLinuxBinary = (binary) => {
const source = path.join(__dirname, binary);
if (fs.existsSync(source)) {
// mac and linux support extension-less executables
// so just overwrite the shell script
const target = path.join(__dirname, "ppx")
fs.renameSync(source, target)
// The ppx should be executable in the bundle, but just in case
fs.chmodSync(target, 0777)
} else {
// assume we're in dev mode - nothing will break if the script
// isn't overwritten, it will just be slower
}
}
const installWindowsBinary = () => {
const source = path.join(__dirname, "ppx-windows.exe")
if (fs.existsSync(source)) {
const target = path.join(__dirname, "ppx.exe")
fs.renameSync(source, target)
// windows scripts use a different file extension to executables
// so we delete the script to make sure windows uses the exe now
const windowsScript = path.join(__dirname, "ppx.cmd")
fs.unlinkSync(windowsScript)
} else {
// assume we're in dev mode - nothing will break if the script
// isn't overwritten, it will just be slower
}
}
switch (process.platform) {
case "linux":
installMacLinuxBinary("ppx-linux.exe")
break
case "darwin":
installMacLinuxBinary("ppx-osx.exe")
break
case "win32":
installWindowsBinary()
break
default:
// This won't break the installation because the `ppx` shell script remains
// but that script will throw an error in this case anyway
console.warn(`No release available for "${process.platform}"`)
process.exit(1)
}