This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.js
50 lines (46 loc) · 1.62 KB
/
Build.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
const path = require("path");
const fs = require("fs");
const child_process = require("child_process");
const os = require("os");
// Clone repo Function
async function CloneDragonfly(){
const TmpDir = path.join(os.tmpdir(), Math.random() + Math.random().toString());
child_process.execFileSync("git", ["clone", "https://github.com/df-mc/dragonfly", "--depth", 1, TmpDir]);
return TmpDir;
}
// Build
function BuildGo(arch = "", RepoPath = "", Out = ""){
return new Promise((resolve, reject) => {
const Ll = child_process.execFile("go", ["build", "-o", Out], {
cwd: RepoPath,
env: {
...process.env,
GOARCH: arch,
}
});
Ll.stdout.on("data", data => process.stdout.write(data));
Ll.stderr.on("data", data => process.stdout.write(data));
Ll.on("exit", code => {
if (code === 0) resolve(); else reject(code);
});
});
}
// Build Bin File
async function Build(){
const RepoPath = await CloneDragonfly();
const arch = [];
if (process.platform === "linux") {
if (!(process.env.GOOS)) arch.push("amd64", "arm64", "386", "arm");
else arch.push("arm64", "amd64");
}
else if (process.platform === "win32") arch.push("amd64", "386");
else if (process.platform === "darwin") arch.push("amd64", "arm64");
else if (process.platform === "android") arch.push("arm64");
else throw new Error("Not valid platform");
for (let Arch of arch) {
let OutPutFile = path.join(__dirname, "BuildOut", `Dragonfly_${process.env.GOOS || process.platform}_${Arch}`);
if (process.platform === "win32") OutPutFile += ".exe";
await BuildGo(Arch, RepoPath, OutPutFile);
}
}
Build()