|
| 1 | +const path = require("path"); |
| 2 | +const fs = require("fs"); |
| 3 | + |
| 4 | +const installMacLinuxBinary = (binary) => { |
| 5 | + const source = path.join(__dirname, binary); |
| 6 | + if (fs.existsSync(source)) { |
| 7 | + // mac and linux support extension-less executables |
| 8 | + // so just overwrite the shell script |
| 9 | + const target = path.join(__dirname, "rewatch"); |
| 10 | + fs.renameSync(source, target); |
| 11 | + |
| 12 | + // The ppx should be executable in the bundle, but just in case |
| 13 | + fs.chmodSync(target, 0777); |
| 14 | + } else { |
| 15 | + // assume we're in dev mode - nothing will break if the script |
| 16 | + // isn't overwritten, it will just be slower |
| 17 | + } |
| 18 | +}; |
| 19 | + |
| 20 | +const installWindowsBinary = () => { |
| 21 | + const source = path.join(__dirname, "ppx-windows.exe"); |
| 22 | + if (fs.existsSync(source)) { |
| 23 | + const target = path.join(__dirname, "rewatch.exe"); |
| 24 | + fs.renameSync(source, target); |
| 25 | + |
| 26 | + // windows scripts use a different file extension to executables |
| 27 | + // so we delete the script to make sure windows uses the exe now |
| 28 | + const windowsScript = path.join(__dirname, "ppx.cmd"); |
| 29 | + fs.unlinkSync(windowsScript); |
| 30 | + } else { |
| 31 | + // assume we're in dev mode - nothing will break if the script |
| 32 | + // isn't overwritten, it will just be slower |
| 33 | + } |
| 34 | +}; |
| 35 | + |
| 36 | +switch (process.platform) { |
| 37 | + case "linux": |
| 38 | + installMacLinuxBinary("rewatch-linux"); |
| 39 | + break; |
| 40 | + case "darwin": |
| 41 | + installMacLinuxBinary("rewatch-macos"); |
| 42 | + break; |
| 43 | + case "win32": |
| 44 | + installWindowsBinary(); |
| 45 | + break; |
| 46 | + default: |
| 47 | + // This won't break the installation because the `ppx` shell script remains |
| 48 | + // but that script will throw an error in this case anyway |
| 49 | + console.warn(`No release available for "${process.platform}"`); |
| 50 | + process.exit(1); |
| 51 | +} |
0 commit comments