forked from Vignesh-772/rewatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postinstall.js
51 lines (46 loc) · 1.62 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
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, "rewatch");
fs.renameSync(source, target);
// The binary 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, "rewatch-windows.exe");
if (fs.existsSync(source)) {
const target = path.join(__dirname, "rewatch.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, "rewatch.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("rewatch-linux");
break;
case "darwin":
installMacLinuxBinary("rewatch-macos");
break;
case "win32":
installWindowsBinary();
break;
default:
// This won't break the installation because the 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);
}