-
Notifications
You must be signed in to change notification settings - Fork 1
/
copyPlatformBinaryInPlace.js
44 lines (36 loc) · 1.38 KB
/
copyPlatformBinaryInPlace.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
#!/usr/bin/env node
var fs = require("fs");
var path = require("path");
var arch = process.arch === "ia32" ? "x86" : process.arch;
var platform = process.platform === "win32" ? "win" : process.platform;
var rootDir = __dirname;
var sourceExePath = path.join(rootDir, `bin/ppx-${platform}-${arch}.exe`);
var destExePath = path.join(rootDir, "ppx.exe");
copyBinary(sourceExePath, destExePath);
function copyBinary(sourceFilename, destFilename) {
var supported = fs.existsSync(sourceFilename);
if (!supported) {
console.error("rescript-ppx-let does not support this platform :(");
console.error("");
console.error("rescript-ppx-let comes prepacked as built binaries to avoid large");
console.error("dependencies at build-time.");
console.error("");
console.error("If you want rescript-ppx-let to support this platform natively,");
console.error(
"please open an issue at our repository, linked above. Please"
);
console.error("specify that you are on the " + platform + " platform,");
console.error("on the " + arch + " architecture.");
}
if (!fs.existsSync(destFilename)) {
copyFileSync(sourceFilename, destFilename);
fs.chmodSync(destFilename, 0755);
}
}
function copyFileSync(source, dest) {
if (typeof fs.copyFileSync === "function") {
fs.copyFileSync(source, dest);
} else {
fs.writeFileSync(dest, fs.readFileSync(source));
}
}