gitquarry 0.1.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/README.md +18 -0
- package/bin/gitquarry.cjs +31 -0
- package/lib/install.cjs +145 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# gitquarry
|
|
2
|
+
|
|
3
|
+
Node wrapper that installs the native `gitquarry` CLI binary from GitHub Releases.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g gitquarry
|
|
9
|
+
pnpm add -g gitquarry
|
|
10
|
+
bun add -g gitquarry
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
gitquarry --help
|
|
17
|
+
gitquarry search "rust cli"
|
|
18
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require("node:child_process");
|
|
4
|
+
const { ensureInstalled, getBinaryPath } = require("../lib/install.cjs");
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await ensureInstalled({ quiet: false });
|
|
8
|
+
|
|
9
|
+
const child = spawn(getBinaryPath(), process.argv.slice(2), {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
child.on("exit", (code, signal) => {
|
|
14
|
+
if (signal) {
|
|
15
|
+
process.kill(process.pid, signal);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
process.exit(code ?? 0);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
child.on("error", (error) => {
|
|
23
|
+
console.error(`failed to start gitquarry: ${error.message}`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
main().catch((error) => {
|
|
29
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
30
|
+
process.exit(1);
|
|
31
|
+
});
|
package/lib/install.cjs
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const fsp = require("node:fs/promises");
|
|
5
|
+
const https = require("node:https");
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
|
|
8
|
+
const packageRoot = path.resolve(__dirname, "..");
|
|
9
|
+
const packageJson = require(path.join(packageRoot, "package.json"));
|
|
10
|
+
|
|
11
|
+
const binaryBaseName = process.platform === "win32" ? "gitquarry.exe" : "gitquarry";
|
|
12
|
+
const releaseTag = `v${packageJson.version}`;
|
|
13
|
+
const repo = "Microck/gitquarry";
|
|
14
|
+
|
|
15
|
+
function detectTarget() {
|
|
16
|
+
const os = process.platform;
|
|
17
|
+
const arch = process.arch;
|
|
18
|
+
|
|
19
|
+
if (arch !== "x64" && arch !== "arm64") {
|
|
20
|
+
throw new Error(`unsupported CPU architecture for gitquarry: ${arch}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (os === "linux") {
|
|
24
|
+
return `${arch === "x64" ? "x86_64" : "aarch64"}-unknown-linux-gnu`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (os === "darwin") {
|
|
28
|
+
return `${arch === "x64" ? "x86_64" : "aarch64"}-apple-darwin`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (os === "win32") {
|
|
32
|
+
if (arch !== "x64") {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"unsupported Windows architecture for gitquarry: arm64. Use x86_64 Windows or a GitHub Release asset for another supported platform."
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return "x86_64-pc-windows-msvc";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
throw new Error(`unsupported operating system for gitquarry: ${os}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getBinaryPath() {
|
|
45
|
+
return path.join(packageRoot, "vendor", detectTarget(), binaryBaseName);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getAssetFileName() {
|
|
49
|
+
return `${binaryBaseName.replace(/\.exe$/, "")}-${releaseTag}-${detectTarget()}${process.platform === "win32" ? ".exe" : ""}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getAssetUrl() {
|
|
53
|
+
return `https://github.com/${repo}/releases/download/${releaseTag}/${getAssetFileName()}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function download(url, destination) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const request = https.get(
|
|
59
|
+
url,
|
|
60
|
+
{
|
|
61
|
+
headers: {
|
|
62
|
+
"User-Agent": "gitquarry-installer",
|
|
63
|
+
Accept: "application/octet-stream",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
(response) => {
|
|
67
|
+
if (
|
|
68
|
+
response.statusCode &&
|
|
69
|
+
response.statusCode >= 300 &&
|
|
70
|
+
response.statusCode < 400 &&
|
|
71
|
+
response.headers.location
|
|
72
|
+
) {
|
|
73
|
+
response.resume();
|
|
74
|
+
download(response.headers.location, destination).then(resolve, reject);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (response.statusCode !== 200) {
|
|
79
|
+
response.resume();
|
|
80
|
+
reject(
|
|
81
|
+
new Error(
|
|
82
|
+
`failed to download ${url} - HTTP ${response.statusCode ?? "unknown"}`
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const file = fs.createWriteStream(destination, { mode: 0o755 });
|
|
89
|
+
response.pipe(file);
|
|
90
|
+
|
|
91
|
+
file.on("finish", () => {
|
|
92
|
+
file.close(resolve);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
file.on("error", (error) => {
|
|
96
|
+
reject(error);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
request.on("error", reject);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function ensureInstalled({ quiet }) {
|
|
106
|
+
const binaryPath = getBinaryPath();
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
await fsp.access(binaryPath, fs.constants.X_OK);
|
|
110
|
+
return binaryPath;
|
|
111
|
+
} catch {
|
|
112
|
+
const vendorDir = path.dirname(binaryPath);
|
|
113
|
+
const tempPath = `${binaryPath}.tmp`;
|
|
114
|
+
const assetUrl = getAssetUrl();
|
|
115
|
+
|
|
116
|
+
if (!quiet) {
|
|
117
|
+
console.error(`Downloading native gitquarry binary from ${assetUrl}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
await fsp.mkdir(vendorDir, { recursive: true });
|
|
121
|
+
await download(assetUrl, tempPath);
|
|
122
|
+
await fsp.rename(tempPath, binaryPath);
|
|
123
|
+
|
|
124
|
+
if (process.platform !== "win32") {
|
|
125
|
+
await fsp.chmod(binaryPath, 0o755);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return binaryPath;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (require.main === module) {
|
|
133
|
+
ensureInstalled({ quiet: false }).catch((error) => {
|
|
134
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
135
|
+
process.exit(1);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = {
|
|
140
|
+
detectTarget,
|
|
141
|
+
ensureInstalled,
|
|
142
|
+
getAssetFileName,
|
|
143
|
+
getAssetUrl,
|
|
144
|
+
getBinaryPath,
|
|
145
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gitquarry",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Node wrapper that installs the native gitquarry CLI binary",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Microck/gitquarry.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/Microck/gitquarry#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/Microck/gitquarry/issues"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"gitquarry": "bin/gitquarry.cjs"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"lib",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"postinstall": "node lib/install.cjs"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"github",
|
|
30
|
+
"search",
|
|
31
|
+
"cli",
|
|
32
|
+
"repositories",
|
|
33
|
+
"rust"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"preferGlobal": true
|
|
39
|
+
}
|