@akiojin/gwt 9.0.2 → 9.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/gwt.js +116 -0
- package/package.json +2 -2
package/bin/gwt.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper script to execute the gwt Rust binary.
|
|
4
|
+
* If the binary is not found (e.g., bunx skips postinstall),
|
|
5
|
+
* it will be downloaded on-demand from GitHub Releases.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { spawn } = require("child_process");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const fs = require("fs");
|
|
11
|
+
const https = require("https");
|
|
12
|
+
const os = require("os");
|
|
13
|
+
|
|
14
|
+
const REPO = "akiojin/gwt";
|
|
15
|
+
const BIN_DIR = __dirname;
|
|
16
|
+
const BIN_NAME = process.platform === "win32" ? "gwt-tui.exe" : "gwt-tui";
|
|
17
|
+
const BIN_PATH = path.join(BIN_DIR, BIN_NAME);
|
|
18
|
+
|
|
19
|
+
function releaseAssetName() {
|
|
20
|
+
const platform = os.platform();
|
|
21
|
+
const arch = os.arch();
|
|
22
|
+
|
|
23
|
+
if (platform === "darwin" && arch === "arm64") return "gwt-macos-aarch64";
|
|
24
|
+
if (platform === "darwin" && arch === "x64") return "gwt-macos-x86_64";
|
|
25
|
+
if (platform === "linux" && arch === "x64") return "gwt-linux-x86_64";
|
|
26
|
+
if (platform === "linux" && arch === "arm64") return "gwt-linux-aarch64";
|
|
27
|
+
if (platform === "win32" && arch === "x64") return "gwt-windows-x86_64.exe";
|
|
28
|
+
|
|
29
|
+
console.error(`Unsupported platform: ${platform}-${arch}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function readVersion() {
|
|
34
|
+
const pkg = path.join(__dirname, "..", "package.json");
|
|
35
|
+
return JSON.parse(fs.readFileSync(pkg, "utf8")).version;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function download(url, dest) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const file = fs.createWriteStream(dest);
|
|
41
|
+
const request = (u) => {
|
|
42
|
+
https
|
|
43
|
+
.get(u, { headers: { "User-Agent": "gwt-postinstall" } }, (res) => {
|
|
44
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
45
|
+
request(res.headers.location);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (res.statusCode !== 200) {
|
|
49
|
+
file.close();
|
|
50
|
+
fs.unlink(dest, () => {});
|
|
51
|
+
reject(new Error(`HTTP ${res.statusCode} for ${u}`));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
res.pipe(file);
|
|
55
|
+
file.on("finish", () => file.close(resolve));
|
|
56
|
+
})
|
|
57
|
+
.on("error", (err) => {
|
|
58
|
+
file.close();
|
|
59
|
+
fs.unlink(dest, () => {});
|
|
60
|
+
reject(err);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
request(url);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function ensureBinary() {
|
|
68
|
+
if (fs.existsSync(BIN_PATH)) return;
|
|
69
|
+
|
|
70
|
+
const version = readVersion();
|
|
71
|
+
const asset = releaseAssetName();
|
|
72
|
+
const tag = `v${version}`;
|
|
73
|
+
const url = `https://github.com/${REPO}/releases/download/${tag}/${asset}`;
|
|
74
|
+
|
|
75
|
+
console.log(`Downloading gwt binary for ${os.platform()}-${os.arch()}...`);
|
|
76
|
+
console.log(`Downloading from: ${url}`);
|
|
77
|
+
|
|
78
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
79
|
+
await download(url, BIN_PATH);
|
|
80
|
+
|
|
81
|
+
if (os.platform() !== "win32") {
|
|
82
|
+
fs.chmodSync(BIN_PATH, 0o755);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log("gwt binary installed successfully!");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function main() {
|
|
89
|
+
try {
|
|
90
|
+
await ensureBinary();
|
|
91
|
+
} catch (err) {
|
|
92
|
+
console.error(`Failed to download gwt binary: ${err.message}`);
|
|
93
|
+
console.error(`https://github.com/${REPO}/releases`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const child = spawn(BIN_PATH, process.argv.slice(2), {
|
|
98
|
+
stdio: "inherit",
|
|
99
|
+
env: process.env,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
child.on("error", (err) => {
|
|
103
|
+
console.error(`Failed to start gwt: ${err.message}`);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
child.on("exit", (code, signal) => {
|
|
108
|
+
if (signal) {
|
|
109
|
+
process.kill(process.pid, signal);
|
|
110
|
+
} else {
|
|
111
|
+
process.exit(code ?? 0);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akiojin/gwt",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.3",
|
|
4
4
|
"description": "TUI for Git worktree management and coding agent launch",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"gwt": "bin/gwt
|
|
7
|
+
"gwt": "bin/gwt.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"postinstall": "node scripts/postinstall.js",
|