-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpack.js
48 lines (44 loc) · 1.27 KB
/
pack.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
const { spawnSync } = require("child_process");
const path = require("path");
const cfg = require("./package.json");
const pkg = "github.com/ayonli/ngrpc/cli/ngrpc";
/** @typedef {"linux" | "darwin" | "windows"} OS */
/** @typedef {"amd64" | "arm64"} Arch */
/**
* @type {{ os: OS, arch: Arch[] }[]} targets
*/
const targets = [
{ os: "linux", arch: ["amd64", "arm64"] },
{ os: "darwin", arch: ["amd64", "arm64"] },
{ os: "windows", arch: ["amd64", "arm64"] }
];
for (const { os, arch } of targets) {
console.log("packing for", os, "...");
for (const _arch of arch) {
const wd = path.join("prebuild", os, _arch);
const exeName = os === "windows" ? "ngrpc.exe" : "ngrpc";
const outPath = path.join(wd, exeName);
spawnSync("go", [
"build",
"-o",
outPath,
`-ldflags`,
`-X '${pkg}/cmd.version=v${cfg.version}'`,
pkg
], {
stdio: "inherit",
env: {
...process.env,
GOOS: os,
GOARCH: _arch,
}
});
spawnSync("tar", [
"-czf",
path.join("prebuild", `ngrpc-${os}-${_arch}.tgz`),
"-C",
wd,
exeName
]);
}
}