gurtcli 0.1.0
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/cli.js +17 -0
- package/install.js +106 -0
- package/package.json +23 -0
package/cli.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawn } = require("child_process");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const binName = process.platform === "win32" ? "gurtcli.exe" : "gurtcli";
|
|
7
|
+
const binPath = path.join(__dirname, "bin", binName);
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync(binPath)) {
|
|
10
|
+
console.error(
|
|
11
|
+
"gurtcli binary not found. Try reinstalling: npm install -g gurtcli"
|
|
12
|
+
);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const proc = spawn(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
17
|
+
proc.on("exit", (code) => process.exit(code ?? 0));
|
package/install.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const https = require("https");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { execSync } = require("child_process");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
|
|
8
|
+
const pkg = require("./package.json");
|
|
9
|
+
const version = pkg.version;
|
|
10
|
+
|
|
11
|
+
const platformMap = {
|
|
12
|
+
darwin: "darwin",
|
|
13
|
+
linux: "linux",
|
|
14
|
+
win32: "windows",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const archMap = {
|
|
18
|
+
x64: "amd64",
|
|
19
|
+
arm64: "arm64",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const goos = platformMap[process.platform];
|
|
23
|
+
const goarch = archMap[process.arch];
|
|
24
|
+
|
|
25
|
+
if (!goos || !goarch) {
|
|
26
|
+
console.error(
|
|
27
|
+
`gurtcli does not support ${process.platform} ${process.arch}`
|
|
28
|
+
);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const binaryName = goos === "windows" ? "gurtcli.exe" : "gurtcli";
|
|
33
|
+
const archive = `gurtcli_${version}_${goos}_${goarch}.tar.gz`;
|
|
34
|
+
const url = `https://github.com/gru/gurtcli/releases/download/v${version}/${archive}`;
|
|
35
|
+
const binDir = path.join(__dirname, "bin");
|
|
36
|
+
const binPath = path.join(binDir, binaryName);
|
|
37
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "gurtcli-"));
|
|
38
|
+
|
|
39
|
+
console.log(`Downloading gurtcli v${version} for ${goos}/${goarch}...`);
|
|
40
|
+
|
|
41
|
+
const archivePath = path.join(tmpDir, archive);
|
|
42
|
+
|
|
43
|
+
function download(url, dest) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const file = fs.createWriteStream(dest);
|
|
46
|
+
const req = https.get(url, (res) => {
|
|
47
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
48
|
+
file.close();
|
|
49
|
+
fs.unlinkSync(dest);
|
|
50
|
+
return download(res.headers.location, dest).then(resolve).catch(reject);
|
|
51
|
+
}
|
|
52
|
+
if (res.statusCode !== 200) {
|
|
53
|
+
file.close();
|
|
54
|
+
fs.unlinkSync(dest);
|
|
55
|
+
reject(new Error(`HTTP ${res.statusCode}`));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
res.pipe(file);
|
|
59
|
+
file.on("finish", () => {
|
|
60
|
+
file.close();
|
|
61
|
+
resolve();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
req.on("error", (err) => {
|
|
65
|
+
file.close();
|
|
66
|
+
if (fs.existsSync(dest)) fs.unlinkSync(dest);
|
|
67
|
+
reject(err);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
download(url, archivePath)
|
|
73
|
+
.then(() => {
|
|
74
|
+
console.log("Extracting...");
|
|
75
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
76
|
+
execSync(`tar -xzf "${archivePath}" -C "${binDir}"`, {
|
|
77
|
+
stdio: "pipe",
|
|
78
|
+
});
|
|
79
|
+
fs.unlinkSync(archivePath);
|
|
80
|
+
fs.rmdirSync(tmpDir);
|
|
81
|
+
|
|
82
|
+
const entries = fs.readdirSync(binDir);
|
|
83
|
+
for (const entry of entries) {
|
|
84
|
+
const entryPath = path.join(binDir, entry);
|
|
85
|
+
if (fs.statSync(entryPath).isDirectory()) {
|
|
86
|
+
const extractedBin = path.join(entryPath, binaryName);
|
|
87
|
+
if (fs.existsSync(extractedBin)) {
|
|
88
|
+
if (fs.existsSync(binPath)) fs.unlinkSync(binPath);
|
|
89
|
+
fs.renameSync(extractedBin, binPath);
|
|
90
|
+
}
|
|
91
|
+
fs.rmSync(entryPath, { recursive: true, force: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (process.platform !== "win32") {
|
|
96
|
+
fs.chmodSync(binPath, 0o755);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
console.log("gurtcli v" + version + " installed");
|
|
100
|
+
})
|
|
101
|
+
.catch((err) => {
|
|
102
|
+
console.error("Failed to install gurtcli:", err.message);
|
|
103
|
+
if (fs.existsSync(tmpDir))
|
|
104
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
105
|
+
process.exit(1);
|
|
106
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gurtcli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A coding agent in your terminal. Type what you want. It does the rest.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"gurtcli": "cli.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node install.js"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/gru/gurtcli.git"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/gru/gurtcli",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/gru/gurtcli/issues"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
}
|
|
23
|
+
}
|