invgate-cli 0.3.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/install.js +82 -0
- package/package.json +15 -0
package/install.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { execSync } = require("child_process");
|
|
3
|
+
const { existsSync, mkdirSync, createWriteStream } = require("fs");
|
|
4
|
+
const { join } = require("path");
|
|
5
|
+
const { homedir, platform } = require("os");
|
|
6
|
+
const https = require("https");
|
|
7
|
+
|
|
8
|
+
const BIN = "invgate-cli" + (platform() === "win32" ? ".exe" : "");
|
|
9
|
+
const RELEASES = "https://github.com/wdelcant/invgate-cli/releases";
|
|
10
|
+
const DIR = join(homedir(), ".invgate", "bin");
|
|
11
|
+
const BIN_PATH = join(DIR, BIN);
|
|
12
|
+
|
|
13
|
+
async function getLatestVersion() {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
https.get(`${RELEASES}/latest`, (res) => {
|
|
16
|
+
const location = res.headers.location || "";
|
|
17
|
+
const tag = location.split("/").pop();
|
|
18
|
+
resolve(tag.startsWith("v") ? tag.slice(1) : tag);
|
|
19
|
+
}).on("error", () => resolve(require("./package.json").version));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getAssetName(version) {
|
|
24
|
+
const osMap = { darwin: "macOS", linux: "Linux", win32: "Windows" };
|
|
25
|
+
const archMap = { x64: "amd64", arm64: "arm64" };
|
|
26
|
+
const osName = osMap[platform()] || "Linux";
|
|
27
|
+
const archName = archMap[process.arch] || "amd64";
|
|
28
|
+
const ext = platform() === "win32" ? "zip" : "tar.gz";
|
|
29
|
+
return `invgate-cli_v${VERSION}_${osName}_${archName}.${ext}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function download(url, dest) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const file = createWriteStream(dest);
|
|
35
|
+
https
|
|
36
|
+
.get(url, (res) => {
|
|
37
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
38
|
+
return download(res.headers.location, dest).then(resolve).catch(reject);
|
|
39
|
+
}
|
|
40
|
+
if (res.statusCode !== 200) {
|
|
41
|
+
return reject(new Error(`Download failed: HTTP ${res.statusCode}`));
|
|
42
|
+
}
|
|
43
|
+
res.pipe(file);
|
|
44
|
+
file.on("finish", () => { file.close(); resolve(); });
|
|
45
|
+
})
|
|
46
|
+
.on("error", reject);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function main() {
|
|
51
|
+
if (existsSync(BIN_PATH)) {
|
|
52
|
+
try {
|
|
53
|
+
execSync(`"${BIN_PATH}"`, { stdio: "inherit" });
|
|
54
|
+
return;
|
|
55
|
+
} catch {}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const version = await getLatestVersion();
|
|
59
|
+
const asset = getAssetName(version);
|
|
60
|
+
const url = `${RELEASES}/download/v${version}/${asset}`;
|
|
61
|
+
const tmp = join(DIR, asset);
|
|
62
|
+
|
|
63
|
+
mkdirSync(DIR, { recursive: true });
|
|
64
|
+
console.error(`Downloading invgate-cli v${VERSION} for ${platform()}/${process.arch}...`);
|
|
65
|
+
await download(url, tmp);
|
|
66
|
+
|
|
67
|
+
if (asset.endsWith(".zip")) {
|
|
68
|
+
execSync(`powershell -Command "Expand-Archive -Path '${tmp}' -DestinationPath '${DIR}' -Force"`, { stdio: "ignore" });
|
|
69
|
+
} else {
|
|
70
|
+
execSync(`tar -xzf "${tmp}" -C "${DIR}"`, { stdio: "ignore" });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
try { require("fs").unlinkSync(tmp); } catch {}
|
|
74
|
+
|
|
75
|
+
execSync(`"${BIN_PATH}"`, { stdio: "inherit" });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
main().catch((err) => {
|
|
79
|
+
console.error("invgate-cli:", err.message);
|
|
80
|
+
console.error("Install manually: brew install wdelcant/tap/invgate-cli");
|
|
81
|
+
process.exit(1);
|
|
82
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "invgate-cli",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Runtime OpenAPI/Swagger CLI for InvGate Asset Management",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "github:wdelcant/invgate-cli",
|
|
7
|
+
"bin": {
|
|
8
|
+
"invgate-cli": "./install.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"install.js"
|
|
12
|
+
],
|
|
13
|
+
"os": ["darwin", "linux", "win32"],
|
|
14
|
+
"cpu": ["x64", "arm64"]
|
|
15
|
+
}
|