@bluevs/vhcli 0.1.1 → 0.2.1

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.1",
3
+ "version": "0.2.1",
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
@@ -1,12 +1,61 @@
1
1
  #!/usr/bin/env node
2
- const { execFileSync } = require("child_process");
2
+ const { execFileSync, execSync } = 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
+ const binName = `vhcli${process.platform === "win32" ? ".exe" : ""}`;
26
+
27
+ function findBinary() {
28
+ try {
29
+ return require.resolve(`${pkgName}/bin/${binName}`);
30
+ } catch {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ let binPath = findBinary();
36
+
37
+ if (!binPath) {
38
+ const version = require("../package.json").version;
39
+ const spec = `${pkgName}@${version}`;
40
+ process.stderr.write(`Installing platform package ${spec}...\n`);
41
+ try {
42
+ execSync(`npm install --no-save ${spec}`, {
43
+ stdio: ["ignore", "ignore", "inherit"],
44
+ cwd: path.join(__dirname, ".."),
45
+ });
46
+ } catch {
47
+ console.error(`Failed to install ${spec}. Install manually: npm install ${spec}`);
48
+ process.exit(1);
49
+ }
50
+ binPath = findBinary();
51
+ if (!binPath) {
52
+ console.error(`Platform package ${pkgName} could not be resolved after install.`);
53
+ process.exit(1);
54
+ }
55
+ }
7
56
 
8
57
  try {
9
- execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
58
+ execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
10
59
  } catch (e) {
11
60
  process.exit(e.status || 1);
12
61
  }
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
- });