forked from teamwalnut/graphql-ppx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
copyPlatformBinaryInPlace.js
66 lines (54 loc) · 1.66 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
var fs = require('fs');
var arch = process.arch;
var platform = process.platform;
if (arch === 'ia32') {
arch = 'x86';
}
if (platform === 'win32') {
platform = 'win';
}
copyBinary("bin/bsb6/graphql_ppx-" + platform + "-" + arch + ".exe", "ppx6");
function copyBinary(filename, destFilename) {
var supported = fs.existsSync(filename);
if (!supported) {
console.error("graphql_ppx does not support this platform :(");
console.error("");
console.error(
"graphql_ppx comes prepacked as built binaries to avoid large"
);
console.error("dependencies at build-time.");
console.error("");
console.error("If you want graphql_ppx 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 (!process.env.IS_GRAPHQL_PPX_CI) {
process.exit(1);
}
}
if (process.env.IS_GRAPHQL_PPX_CI) {
console.log(
'graphql_ppx: IS_GRAPHQL_PPX_CI has been set, skipping moving binary in place',
);
process.exit(0);
}
if (!fs.existsSync(destFilename)) {
copyFileSync(filename, destFilename);
fs.chmodSync(destFilename, 0755);
}
var destFilenameExe = destFilename + ".exe";
if (!fs.existsSync(destFilenameExe)) {
copyFileSync(filename, destFilenameExe);
fs.chmodSync(destFilenameExe, 0755);
}
}
function copyFileSync(source, dest) {
if (typeof fs.copyFileSync === 'function') {
fs.copyFileSync(source, dest);
} else {
fs.writeFileSync(dest, fs.readFileSync(source));
}
}