Skip to content

Commit 415f478

Browse files
committed
fix packing and global install
1 parent 94211f7 commit 415f478

File tree

4 files changed

+154
-262
lines changed

4 files changed

+154
-262
lines changed

cli/index.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import * as http from "http";
33
import { https } from "follow-redirects";
44
import * as path from "path";
55
import * as fs from "fs/promises";
6-
import * as unzip from "unzipper";
6+
import * as tar from "tar";
77
import { exists, isTsNode } from "../util";
88
import { spawnSync } from "child_process";
9-
import sleep from "@hyurl/utils/sleep";
109

1110
const nodeModulesDir = path.dirname(path.dirname(path.dirname(__dirname)));
1211
const hiddenDir = path.join(nodeModulesDir, ".ngrpc");
@@ -15,21 +14,21 @@ let zipName: string | undefined;
1514

1615
if (process.platform === "darwin") {
1716
if (process.arch === "arm64") {
18-
zipName = `ngrpc-mac-arm64.zip`;
17+
zipName = `ngrpc-mac-arm64.tgz`;
1918
} else if (process.arch === "x64") {
20-
zipName = "ngrpc-mac-amd64.zip";
19+
zipName = "ngrpc-mac-amd64.tgz";
2120
}
2221
} else if (process.platform === "linux") {
2322
if (process.arch === "arm64") {
24-
zipName = `ngrpc-linux-arm64.zip`;
23+
zipName = `ngrpc-linux-arm64.tgz`;
2524
} else if (process.arch === "x64") {
26-
zipName = "ngrpc-linux-amd64.zip";
25+
zipName = "ngrpc-linux-amd64.tgz";
2726
}
2827
} else if (process.platform === "win32") {
2928
if (process.arch === "arm64") {
30-
zipName = `ngrpc-linux-arm64.zip`;
29+
zipName = `ngrpc-windows-arm64.tgz`;
3130
} else if (process.arch === "x64") {
32-
zipName = "ngrpc-linux-amd64.zip";
31+
zipName = "ngrpc-windows-amd64.tgz";
3332
}
3433
}
3534

@@ -69,20 +68,17 @@ function reportImportFailure(err?: Error) {
6968
reportImportFailure(new Error(`unable to download ${zipName}`));
7069
}
7170

72-
res.pipe(unzip.Extract({ path: hiddenDir }));
73-
7471
await new Promise<void>((resolve, reject) => {
75-
res.on("error", (err) => {
72+
const out = tar.extract({ cwd: hiddenDir });
73+
const handleError = async (err: Error) => {
74+
try { await fs.unlink(cmdPath); } catch { }
7675
reject(err);
77-
}).on("end", () => {
78-
resolve();
79-
});
80-
});
76+
};
8177

82-
if (process.platform !== "win32") {
83-
spawnSync("chmod", ["+x", cmdPath], { stdio: "inherit" });
84-
await sleep(100); // need to wait a while, don't know why
85-
}
78+
res.pipe(out);
79+
res.on("error", handleError);
80+
out.on("error", handleError).on("finish", resolve);
81+
});
8682

8783
spawnSync(cmdPath, process.argv.slice(2), { stdio: "inherit" });
8884
} else {

pack.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
echo "packing for macOS..."
22
GOOS=darwin GOARCH=amd64 go build -o prebuild/mac/amd64/ngrpc github.com/ayonli/ngrpc/cli/ngrpc
3-
zip -j prebuild/ngrpc-mac-amd64.zip prebuild/mac/amd64/ngrpc
3+
tar -czvf prebuild/ngrpc-mac-amd64.tgz -C prebuild/mac/amd64 ngrpc
44
GOOS=darwin GOARCH=arm64 go build -o prebuild/mac/arm64/ngrpc github.com/ayonli/ngrpc/cli/ngrpc
5-
zip -j prebuild/ngrpc-mac-arm64.zip prebuild/mac/arm64/ngrpc
5+
tar -czvf prebuild/ngrpc-mac-arm64.tgz -C prebuild/mac/arm64 ngrpc
66

77
echo "packing for Linux..."
88
GOOS=linux GOARCH=amd64 go build -o prebuild/linux/amd64/ngrpc github.com/ayonli/ngrpc/cli/ngrpc
9-
zip -j prebuild/ngrpc-linux-amd64.zip prebuild/linux/amd64/ngrpc
9+
tar -czvf prebuild/ngrpc-linux-amd64.tgz -C prebuild/linux/amd64 ngrpc
1010
GOOS=linux GOARCH=arm64 go build -o prebuild/linux/arm64/ngrpc github.com/ayonli/ngrpc/cli/ngrpc
11-
zip -j prebuild/ngrpc-linux-arm64.zip prebuild/linux/arm64/ngrpc
11+
tar -czvf prebuild/ngrpc-linux-arm64.tgz -C prebuild/linux/arm64 ngrpc
1212

1313
echo "packing for Windows..."
1414
GOOS=windows GOARCH=amd64 go build -o prebuild/windows/amd64/ngrpc.exe github.com/ayonli/ngrpc/cli/ngrpc
15-
zip -j prebuild/ngrpc-windows-amd64.zip prebuild/windows/amd64/ngrpc.exe
15+
tar -czvf prebuild/ngrpc-windows-amd64.tgz -C prebuild/windows/amd64 ngrpc.exe
1616
GOOS=windows GOARCH=arm64 go build -o prebuild/windows/arm64/ngrpc.exe github.com/ayonli/ngrpc/cli/ngrpc
17-
zip -j prebuild/ngrpc-windows-arm64.zip prebuild/windows/arm64/ngrpc.exe
17+
tar -czvf prebuild/ngrpc-windows-arm64.tgz -C prebuild/windows/arm64 ngrpc.exe

0 commit comments

Comments
 (0)