@nexgensys/nexgit 0.1.3 → 0.1.6
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 +5 -4
- package/bin/nexgit.js +148 -0
- package/package.json +14 -3
package/README.md
CHANGED
|
@@ -12,14 +12,15 @@ npm install -g @nexgensys/nexgit
|
|
|
12
12
|
nexgit --help
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
El
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
El binario de tu plataforma llega como dependencia opcional (`@nexgensys/nexgit-<os>-<arch>`), así
|
|
16
|
+
que no hay descargas en tiempo de ejecución. Alpine/musl no está soportado. Si la plataforma no
|
|
17
|
+
tiene paquete, o se define `NEXGIT_BINARY`, el lanzador descarga la release, verifica su SHA-256 y la
|
|
18
|
+
guarda en caché.
|
|
18
19
|
|
|
19
20
|
- Plataformas: linux (amd64, arm64, armv7), macOS (amd64, arm64), Windows (amd64, arm64),
|
|
20
21
|
FreeBSD (amd64, arm64).
|
|
21
22
|
- Variables: `NEXGIT_BINARY` usa un binario local sin descargar; `NEXGIT_CACHE_DIR` cambia la caché;
|
|
22
23
|
`NEXGIT_DOWNLOAD_URL` apunta a otro origen de releases.
|
|
23
|
-
- Documentación completa: <https://git.nexgen.systems/IANexgen
|
|
24
|
+
- Documentación completa: <https://git.nexgen.systems/IANexgen/nexgit>.
|
|
24
25
|
|
|
25
26
|
Licencia MIT.
|
package/bin/nexgit.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Launcher for the nexgit binary. Platform packages carry the binary; when one is not installed
|
|
4
|
+
// (an unsupported platform, or a manual install), it falls back to downloading the release asset,
|
|
5
|
+
// verifying its SHA-256 and caching it.
|
|
6
|
+
const { spawnSync } = require("node:child_process");
|
|
7
|
+
const { createHash } = require("node:crypto");
|
|
8
|
+
const fs = require("node:fs");
|
|
9
|
+
const os = require("node:os");
|
|
10
|
+
const path = require("node:path");
|
|
11
|
+
const https = require("node:https");
|
|
12
|
+
|
|
13
|
+
const pkg = require("../package.json");
|
|
14
|
+
const version = pkg.version;
|
|
15
|
+
|
|
16
|
+
const platforms = {
|
|
17
|
+
"linux-x64": { asset: "linux-amd64", pkg: "linux-x64" },
|
|
18
|
+
"linux-arm64": { asset: "linux-arm64", pkg: "linux-arm64" },
|
|
19
|
+
"linux-arm": { asset: "linux-arm-7", pkg: "linux-arm" },
|
|
20
|
+
"darwin-x64": { asset: "darwin-amd64", pkg: "darwin-x64" },
|
|
21
|
+
"darwin-arm64": { asset: "darwin-arm64", pkg: "darwin-arm64" },
|
|
22
|
+
"win32-x64": { asset: "windows-amd64", pkg: "win32-x64" },
|
|
23
|
+
"win32-arm64": { asset: "windows-arm64", pkg: "win32-arm64" },
|
|
24
|
+
"freebsd-x64": { asset: "freebsd-amd64", pkg: "freebsd-x64" },
|
|
25
|
+
"freebsd-arm64": { asset: "freebsd-arm64", pkg: "freebsd-arm64" },
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function platform() {
|
|
29
|
+
const key = `${process.platform}-${process.arch}`;
|
|
30
|
+
const found = platforms[key];
|
|
31
|
+
if (!found) {
|
|
32
|
+
throw new Error(`unsupported platform ${key}; install nexgit with its install script`);
|
|
33
|
+
}
|
|
34
|
+
const binary = process.platform === "win32" ? "nexgit.exe" : "nexgit";
|
|
35
|
+
return { ...found, binary, file: `nexgit-${version}-${found.asset}${process.platform === "win32" ? ".exe" : ""}` };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function packagedBinary(target) {
|
|
39
|
+
try {
|
|
40
|
+
const metadata = require.resolve(`@nexgensys/nexgit-${target.pkg}/package.json`);
|
|
41
|
+
return path.join(path.dirname(metadata), target.binary);
|
|
42
|
+
} catch {
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function downloadBase() {
|
|
48
|
+
return (process.env.NEXGIT_DOWNLOAD_URL ||
|
|
49
|
+
"https://git.nexgen.systems/IANexgen/nexgit/releases/download").replace(/\/+$/, "");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function cacheDir() {
|
|
53
|
+
if (process.env.NEXGIT_CACHE_DIR) return process.env.NEXGIT_CACHE_DIR;
|
|
54
|
+
const base = process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
|
|
55
|
+
return path.join(base, "nexgit", version);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function headers() {
|
|
59
|
+
const result = { "User-Agent": `nexgit-npm/${version}` };
|
|
60
|
+
if (process.env.NEXGIT_TOKEN) result.Authorization = `token ${process.env.NEXGIT_TOKEN}`;
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function get(url, redirects = 0) {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
if (redirects > 5) return reject(new Error(`too many redirects for ${url}`));
|
|
67
|
+
https
|
|
68
|
+
.get(url, { headers: headers() }, (response) => {
|
|
69
|
+
if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
|
|
70
|
+
response.resume();
|
|
71
|
+
resolve(get(new URL(response.headers.location, url).toString(), redirects + 1));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (response.statusCode !== 200) {
|
|
75
|
+
response.resume();
|
|
76
|
+
reject(new Error(`${url} answered HTTP ${response.statusCode}`));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
resolve(response);
|
|
80
|
+
})
|
|
81
|
+
.on("error", reject);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function download(url, target) {
|
|
86
|
+
const response = await get(url);
|
|
87
|
+
await new Promise((resolve, reject) => {
|
|
88
|
+
const out = fs.createWriteStream(target);
|
|
89
|
+
response.pipe(out);
|
|
90
|
+
out.on("finish", resolve);
|
|
91
|
+
out.on("error", reject);
|
|
92
|
+
response.on("error", reject);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function text(url) {
|
|
97
|
+
const response = await get(url);
|
|
98
|
+
const chunks = [];
|
|
99
|
+
for await (const chunk of response) chunks.push(chunk);
|
|
100
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function downloadBinary(target) {
|
|
104
|
+
const base = downloadBase();
|
|
105
|
+
const binary = path.join(cacheDir(), target.file);
|
|
106
|
+
if (fs.existsSync(binary)) return binary;
|
|
107
|
+
fs.mkdirSync(path.dirname(binary), { recursive: true });
|
|
108
|
+
const expected = (await text(`${base}/v${version}/${target.file}.sha256`)).trim().split(/\s+/)[0];
|
|
109
|
+
if (!/^[0-9a-f]{64}$/i.test(expected)) {
|
|
110
|
+
throw new Error(`invalid checksum for ${target.file}; set NEXGIT_TOKEN if the instance requires sign-in`);
|
|
111
|
+
}
|
|
112
|
+
const temporary = `${binary}.${process.pid}.tmp`;
|
|
113
|
+
console.error(`nexgit: downloading ${target.file} ${version}`);
|
|
114
|
+
await download(`${base}/v${version}/${target.file}`, temporary);
|
|
115
|
+
const digest = createHash("sha256").update(fs.readFileSync(temporary)).digest("hex");
|
|
116
|
+
if (digest !== expected.toLowerCase()) {
|
|
117
|
+
fs.rmSync(temporary, { force: true });
|
|
118
|
+
throw new Error(`checksum mismatch for ${target.file}; nexgit was not installed`);
|
|
119
|
+
}
|
|
120
|
+
fs.chmodSync(temporary, 0o755);
|
|
121
|
+
fs.renameSync(temporary, binary);
|
|
122
|
+
return binary;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function main() {
|
|
126
|
+
if (process.env.NEXGIT_BINARY) return process.env.NEXGIT_BINARY;
|
|
127
|
+
const target = platform();
|
|
128
|
+
const installed = packagedBinary(target);
|
|
129
|
+
if (installed && fs.existsSync(installed)) {
|
|
130
|
+
fs.chmodSync(installed, 0o755);
|
|
131
|
+
return installed;
|
|
132
|
+
}
|
|
133
|
+
return downloadBinary(target);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
main()
|
|
137
|
+
.then((binary) => {
|
|
138
|
+
const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
139
|
+
if (result.error) {
|
|
140
|
+
console.error(`nexgit: ${result.error.message}`);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
process.exit(result.status === null ? 1 : result.status);
|
|
144
|
+
})
|
|
145
|
+
.catch((error) => {
|
|
146
|
+
console.error(`nexgit: ${error.message}`);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexgensys/nexgit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "CLI de git.nexgen.systems: repositorios, issues, pull requests, releases y Actions desde la terminal",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
7
|
-
"nexgit": "bin
|
|
7
|
+
"nexgit": "bin/nexgit.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"bin@nexgensys/nexgit.js",
|
|
@@ -29,5 +29,16 @@
|
|
|
29
29
|
"nexgit",
|
|
30
30
|
"pull-requests",
|
|
31
31
|
"actions"
|
|
32
|
-
]
|
|
32
|
+
],
|
|
33
|
+
"optionalDependencies": {
|
|
34
|
+
"@nexgensys/nexgit-linux-x64": "0.1.6",
|
|
35
|
+
"@nexgensys/nexgit-linux-arm64": "0.1.6",
|
|
36
|
+
"@nexgensys/nexgit-linux-arm": "0.1.6",
|
|
37
|
+
"@nexgensys/nexgit-darwin-x64": "0.1.6",
|
|
38
|
+
"@nexgensys/nexgit-darwin-arm64": "0.1.6",
|
|
39
|
+
"@nexgensys/nexgit-win32-x64": "0.1.6",
|
|
40
|
+
"@nexgensys/nexgit-win32-arm64": "0.1.6",
|
|
41
|
+
"@nexgensys/nexgit-freebsd-x64": "0.1.6",
|
|
42
|
+
"@nexgensys/nexgit-freebsd-arm64": "0.1.6"
|
|
43
|
+
}
|
|
33
44
|
}
|