@bluevs/vhcli 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/bin/vhcli +0 -0
- package/package.json +31 -0
- package/scripts/install.js +107 -0
- package/scripts/run.js +12 -0
package/bin/vhcli
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bluevs/vhcli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vision Hub CLI - query projects and resources, designed for AI Agent and developers",
|
|
5
|
+
"bin": {
|
|
6
|
+
"vhcli": "scripts/run.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {},
|
|
9
|
+
"os": [
|
|
10
|
+
"darwin",
|
|
11
|
+
"linux",
|
|
12
|
+
"win32"
|
|
13
|
+
],
|
|
14
|
+
"cpu": [
|
|
15
|
+
"x64",
|
|
16
|
+
"arm64"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=16"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": ""
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"files": [
|
|
27
|
+
"scripts/run.js",
|
|
28
|
+
"scripts/install.js",
|
|
29
|
+
"bin/"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const { execSync } = require("child_process");
|
|
5
|
+
const os = require("os");
|
|
6
|
+
|
|
7
|
+
const VERSION = require("../package.json").version;
|
|
8
|
+
|
|
9
|
+
// GitHub repo 地址,用于拼接 release 下载 URL
|
|
10
|
+
// 格式: https://github.com/{REPO}/releases/download/v{VERSION}/{archive}
|
|
11
|
+
const REPO = "bluevision-ai/vhcli";
|
|
12
|
+
const NAME = "vhcli";
|
|
13
|
+
|
|
14
|
+
const PLATFORM_MAP = {
|
|
15
|
+
darwin: "darwin",
|
|
16
|
+
linux: "linux",
|
|
17
|
+
win32: "windows",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const ARCH_MAP = {
|
|
21
|
+
x64: "amd64",
|
|
22
|
+
arm64: "arm64",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
26
|
+
const arch = ARCH_MAP[process.arch];
|
|
27
|
+
|
|
28
|
+
if (!platform || !arch) {
|
|
29
|
+
console.error(
|
|
30
|
+
`Unsupported platform: ${process.platform}-${process.arch}`
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isWindows = process.platform === "win32";
|
|
36
|
+
const ext = isWindows ? ".zip" : ".tar.gz";
|
|
37
|
+
const archiveName = `${NAME}-${VERSION}-${platform}-${arch}${ext}`;
|
|
38
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
|
|
39
|
+
const binDir = path.join(__dirname, "..", "bin");
|
|
40
|
+
const dest = path.join(binDir, NAME + (isWindows ? ".exe" : ""));
|
|
41
|
+
|
|
42
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
43
|
+
|
|
44
|
+
function download(url, destPath) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
https
|
|
47
|
+
.get(url, (res) => {
|
|
48
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
49
|
+
return download(res.headers.location, destPath).then(
|
|
50
|
+
resolve,
|
|
51
|
+
reject
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
if (res.statusCode !== 200) {
|
|
55
|
+
return reject(
|
|
56
|
+
new Error(`Download failed with status ${res.statusCode}: ${url}`)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
const file = fs.createWriteStream(destPath);
|
|
60
|
+
res.pipe(file);
|
|
61
|
+
file.on("finish", () => {
|
|
62
|
+
file.close();
|
|
63
|
+
resolve();
|
|
64
|
+
});
|
|
65
|
+
})
|
|
66
|
+
.on("error", reject);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function install() {
|
|
71
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "vhcli-"));
|
|
72
|
+
const archivePath = path.join(tmpDir, archiveName);
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
console.log(`Downloading ${NAME} v${VERSION} for ${platform}/${arch}...`);
|
|
76
|
+
await download(url, archivePath);
|
|
77
|
+
|
|
78
|
+
if (isWindows) {
|
|
79
|
+
execSync(
|
|
80
|
+
`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${tmpDir}'"`,
|
|
81
|
+
{ stdio: "ignore" }
|
|
82
|
+
);
|
|
83
|
+
} else {
|
|
84
|
+
execSync(`tar -xzf "${archivePath}" -C "${tmpDir}"`, {
|
|
85
|
+
stdio: "ignore",
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const binaryName = NAME + (isWindows ? ".exe" : "");
|
|
90
|
+
const extractedBinary = path.join(tmpDir, binaryName);
|
|
91
|
+
|
|
92
|
+
fs.copyFileSync(extractedBinary, dest);
|
|
93
|
+
fs.chmodSync(dest, 0o755);
|
|
94
|
+
console.log(`${NAME} v${VERSION} installed successfully`);
|
|
95
|
+
} finally {
|
|
96
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
install().catch((err) => {
|
|
101
|
+
console.error(`Failed to install ${NAME}:`, err.message);
|
|
102
|
+
console.error("");
|
|
103
|
+
console.error("You can also install manually:");
|
|
104
|
+
console.error(" go install vision_hub_cli@latest");
|
|
105
|
+
console.error(` or download from: https://github.com/${REPO}/releases`);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
});
|
package/scripts/run.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { execFileSync } = require("child_process");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
6
|
+
const bin = path.join(__dirname, "..", "bin", "vhcli" + ext);
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
10
|
+
} catch (e) {
|
|
11
|
+
process.exit(e.status || 1);
|
|
12
|
+
}
|