@nexgensys/nexgit 0.0.0-stage → 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.
Files changed (4) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +25 -2
  3. package/bin/nexgit.js +148 -0
  4. package/package.json +42 -4
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2016 The Gitea Authors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,26 @@
1
- # Temporary Holding Version
1
+ # nexgit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ CLI de [git.nexgen.systems](https://git.nexgen.systems/IANexgen@nexgensys/nexgit) para administrar
4
+ repositorios, issues, pull requests, releases, Actions y demás recursos de la instancia.
5
+
6
+ ```sh
7
+ npx @nexgensys/nexgit version
8
+ npx @nexgensys/nexgit auth login --host https://git.nexgen.systems --with-token
9
+
10
+ # instalación global
11
+ npm install -g @nexgensys/nexgit
12
+ nexgit --help
13
+ ```
14
+
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é.
19
+
20
+ - Plataformas: linux (amd64, arm64, armv7), macOS (amd64, arm64), Windows (amd64, arm64),
21
+ FreeBSD (amd64, arm64).
22
+ - Variables: `NEXGIT_BINARY` usa un binario local sin descargar; `NEXGIT_CACHE_DIR` cambia la caché;
23
+ `NEXGIT_DOWNLOAD_URL` apunta a otro origen de releases.
24
+ - Documentación completa: <https://git.nexgen.systems/IANexgen/nexgit>.
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,6 +1,44 @@
1
1
  {
2
2
  "name": "@nexgensys/nexgit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.6",
4
+ "description": "CLI de git.nexgen.systems: repositorios, issues, pull requests, releases y Actions desde la terminal",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "nexgit": "bin/nexgit.js"
8
+ },
9
+ "files": [
10
+ "bin@nexgensys/nexgit.js",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "engines": {
15
+ "node": ">=18"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://git.nexgen.systems/IANexgen@nexgensys/nexgit.git"
20
+ },
21
+ "homepage": "https://git.nexgen.systems/IANexgen@nexgensys/nexgit",
22
+ "bugs": {
23
+ "url": "https://git.nexgen.systems/IANexgen@nexgensys/nexgit/issues"
24
+ },
25
+ "keywords": [
26
+ "gitea",
27
+ "git",
28
+ "cli",
29
+ "nexgit",
30
+ "pull-requests",
31
+ "actions"
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
+ }
44
+ }