@yuanchuan/aivo 0.22.0 → 0.22.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.
Files changed (2) hide show
  1. package/bin/aivo.js +54 -4
  2. package/package.json +1 -1
package/bin/aivo.js CHANGED
@@ -1,10 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { spawn } = require("node:child_process");
3
+ const { spawn, spawnSync } = require("node:child_process");
4
4
  const os = require("node:os");
5
5
  const { getInstalledBinaryPath, getPackageRoot } = require("../lib/paths");
6
6
  const { formatLaunchError } = require("../lib/launcher");
7
- const { shouldDelegateWindowsNpmUpdate, spawnWindowsNpmUpdate } = require("../lib/update");
7
+ const {
8
+ WINDOWS_NPM_UPDATE_COMMAND,
9
+ shouldDelegateWindowsNpmUpdate,
10
+ spawnWindowsNpmUpdate
11
+ } = require("../lib/update");
8
12
 
9
13
  const args = process.argv.slice(2);
10
14
 
@@ -19,13 +23,59 @@ function forwardExit(child) {
19
23
  });
20
24
  }
21
25
 
22
- if (shouldDelegateWindowsNpmUpdate(args, { packageRoot: getPackageRoot() })) {
26
+ const useColor =
27
+ Boolean(process.stdout.isTTY) &&
28
+ !process.env.NO_COLOR &&
29
+ !args.includes("--no-color");
30
+ const CYAN = useColor ? "\x1b[36m" : "";
31
+ const GREEN = useColor ? "\x1b[32m" : "";
32
+ const DIM = useColor ? "\x1b[2m" : "";
33
+ const RESET = useColor ? "\x1b[0m" : "";
34
+
35
+ function readInstalledVersion() {
36
+ try {
37
+ const result = spawnSync(getInstalledBinaryPath(), ["--version"], {
38
+ encoding: "utf8",
39
+ timeout: 5000
40
+ });
41
+ if (result.status === 0 && typeof result.stdout === "string") {
42
+ const trimmed = result.stdout.trim();
43
+ if (trimmed) {
44
+ const parts = trimmed.split(/\s+/);
45
+ return parts[parts.length - 1];
46
+ }
47
+ }
48
+ } catch {
49
+ // best-effort: fall through to null
50
+ }
51
+ return null;
52
+ }
53
+
54
+ function runWindowsNpmUpdate() {
55
+ console.log(`${CYAN}→${RESET} Updating via npm...`);
56
+ console.log(` ${DIM}Running:${RESET} ${GREEN}${WINDOWS_NPM_UPDATE_COMMAND}${RESET}`);
57
+
23
58
  const child = spawnWindowsNpmUpdate(spawn);
24
- forwardExit(child);
25
59
  child.on("error", (error) => {
26
60
  console.error(`Failed to launch npm.cmd for update: ${error.message}`);
27
61
  process.exit(1);
28
62
  });
63
+ child.on("exit", (code, signal) => {
64
+ if (signal) {
65
+ process.exitCode = 128 + (os.constants.signals[signal] || 1);
66
+ return;
67
+ }
68
+ if (code === 0) {
69
+ const version = readInstalledVersion();
70
+ const suffix = version ? ` to version ${version}` : "";
71
+ console.log(`${GREEN}✓${RESET} Updated${suffix}`);
72
+ }
73
+ process.exit(code ?? 1);
74
+ });
75
+ }
76
+
77
+ if (shouldDelegateWindowsNpmUpdate(args, { packageRoot: getPackageRoot() })) {
78
+ runWindowsNpmUpdate();
29
79
  } else {
30
80
  const binaryPath = getInstalledBinaryPath();
31
81
  const child = spawn(binaryPath, args, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuanchuan/aivo",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
4
4
  "description": "npm wrapper for the aivo CLI",
5
5
  "license": "MIT",
6
6
  "repository": {