@bluevs/vhcli 0.1.0 → 0.2.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/package.json CHANGED
@@ -1,20 +1,19 @@
1
1
  {
2
2
  "name": "@bluevs/vhcli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Vision Hub CLI - query projects and resources, designed for AI Agent and developers",
5
5
  "bin": {
6
6
  "vhcli": "scripts/run.js"
7
7
  },
8
8
  "scripts": {},
9
- "os": [
10
- "darwin",
11
- "linux",
12
- "win32"
13
- ],
14
- "cpu": [
15
- "x64",
16
- "arm64"
17
- ],
9
+ "optionalDependencies": {
10
+ "@bluevs/vhcli-darwin-arm64": "0.2.0",
11
+ "@bluevs/vhcli-darwin-x64": "0.2.0",
12
+ "@bluevs/vhcli-linux-arm64": "0.2.0",
13
+ "@bluevs/vhcli-linux-x64": "0.2.0",
14
+ "@bluevs/vhcli-win32-arm64": "0.2.0",
15
+ "@bluevs/vhcli-win32-x64": "0.2.0"
16
+ },
18
17
  "engines": {
19
18
  "node": ">=16"
20
19
  },
@@ -24,8 +23,6 @@
24
23
  },
25
24
  "license": "MIT",
26
25
  "files": [
27
- "scripts/run.js",
28
- "scripts/install.js",
29
- "bin/"
26
+ "scripts/run.js"
30
27
  ]
31
28
  }
package/scripts/run.js CHANGED
@@ -2,11 +2,38 @@
2
2
  const { execFileSync } = require("child_process");
3
3
  const path = require("path");
4
4
 
5
- const ext = process.platform === "win32" ? ".exe" : "";
6
- const bin = path.join(__dirname, "..", "bin", "vhcli" + ext);
5
+ const PLATFORM_MAP = {
6
+ darwin: "darwin",
7
+ linux: "linux",
8
+ win32: "win32",
9
+ };
10
+
11
+ const ARCH_MAP = {
12
+ x64: "x64",
13
+ arm64: "arm64",
14
+ };
15
+
16
+ const platform = PLATFORM_MAP[process.platform];
17
+ const arch = ARCH_MAP[process.arch];
18
+
19
+ if (!platform || !arch) {
20
+ console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
21
+ process.exit(1);
22
+ }
23
+
24
+ const pkgName = `@bluevs/vhcli-${platform}-${arch}`;
25
+ let binPath;
26
+
27
+ try {
28
+ binPath = require.resolve(`${pkgName}/bin/vhcli${process.platform === "win32" ? ".exe" : ""}`);
29
+ } catch {
30
+ console.error(`Platform package ${pkgName} is not installed.`);
31
+ console.error(`Run: npm install ${pkgName}`);
32
+ process.exit(1);
33
+ }
7
34
 
8
35
  try {
9
- execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
36
+ execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
10
37
  } catch (e) {
11
38
  process.exit(e.status || 1);
12
39
  }
package/bin/vhcli DELETED
Binary file
@@ -1,107 +0,0 @@
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
- });