@askfaro/cli 0.1.0 → 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.
Files changed (2) hide show
  1. package/bin/faro.js +45 -13
  2. package/package.json +8 -2
package/bin/faro.js CHANGED
@@ -6,14 +6,34 @@ const { existsSync } = require("fs");
6
6
  const path = require("path");
7
7
 
8
8
  const PYPI_PACKAGE = "askfaro-cli";
9
- const MIN_VERSION = "0.1.0";
9
+ const MIN_VERSION = "0.3.0";
10
10
 
11
- function findFaro() {
12
- // Check if `faro` is already on PATH (e.g. installed via pip/pipx separately)
11
+ function parseVersion(s) {
12
+ const m = String(s).match(/(\d+)\.(\d+)\.(\d+)/);
13
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
14
+ }
15
+
16
+ function versionAtLeast(a, b) {
17
+ const va = parseVersion(a);
18
+ const vb = parseVersion(b);
19
+ if (!va || !vb) return false;
20
+ for (let i = 0; i < 3; i++) {
21
+ if (va[i] !== vb[i]) return va[i] > vb[i];
22
+ }
23
+ return true;
24
+ }
25
+
26
+ function getVersion(bin) {
13
27
  try {
14
- const result = spawnSync("faro", ["--version"], { encoding: "utf8" });
15
- if (result.status === 0) return "faro";
28
+ const r = spawnSync(bin, ["--version"], { encoding: "utf8" });
29
+ if (r.status === 0) return (r.stdout || "").trim();
16
30
  } catch {}
31
+ return null;
32
+ }
33
+
34
+ function findFaro() {
35
+ // Check if `faro` is already on PATH (e.g. installed via pip/pipx separately)
36
+ if (getVersion("faro") !== null) return "faro";
17
37
 
18
38
  // Check pipx-installed binary
19
39
  const pipxBin = path.join(
@@ -46,13 +66,15 @@ function hasPython() {
46
66
  return null;
47
67
  }
48
68
 
49
- function install() {
50
- console.error(`Installing ${PYPI_PACKAGE} via pipx or pip...`);
69
+ function install({ upgrade = false } = {}) {
70
+ const verb = upgrade ? "Upgrading" : "Installing";
71
+ console.error(`${verb} ${PYPI_PACKAGE} via pipx or pip...`);
51
72
 
52
73
  if (hasPipx()) {
53
- const r = spawnSync("pipx", ["install", PYPI_PACKAGE], { stdio: "inherit" });
74
+ const args = upgrade ? ["upgrade", PYPI_PACKAGE] : ["install", PYPI_PACKAGE];
75
+ const r = spawnSync("pipx", args, { stdio: "inherit" });
54
76
  if (r.status === 0) return;
55
- console.error("pipx install failed, falling back to pip.");
77
+ console.error(`pipx ${args[0]} failed, falling back to pip.`);
56
78
  }
57
79
 
58
80
  const python = hasPython();
@@ -64,11 +86,12 @@ function install() {
64
86
  process.exit(1);
65
87
  }
66
88
 
67
- const r = spawnSync(python, ["-m", "pip", "install", "--user", PYPI_PACKAGE], {
68
- stdio: "inherit",
69
- });
89
+ const pipArgs = ["-m", "pip", "install", "--user"];
90
+ if (upgrade) pipArgs.push("--upgrade");
91
+ pipArgs.push(PYPI_PACKAGE);
92
+ const r = spawnSync(python, pipArgs, { stdio: "inherit" });
70
93
  if (r.status !== 0) {
71
- console.error(`Failed to install ${PYPI_PACKAGE}. Try: pip install ${PYPI_PACKAGE}`);
94
+ console.error(`Failed to install ${PYPI_PACKAGE}. Try: pip install --upgrade ${PYPI_PACKAGE}`);
72
95
  process.exit(1);
73
96
  }
74
97
  }
@@ -85,6 +108,15 @@ if (!faroBin) {
85
108
  );
86
109
  process.exit(1);
87
110
  }
111
+ } else {
112
+ // Existing install — check it meets MIN_VERSION and upgrade if not.
113
+ const current = getVersion(faroBin);
114
+ if (current && !versionAtLeast(current, MIN_VERSION)) {
115
+ console.error(
116
+ `${PYPI_PACKAGE} ${current} is below the minimum ${MIN_VERSION} required by this wrapper.`
117
+ );
118
+ install({ upgrade: true });
119
+ }
88
120
  }
89
121
 
90
122
  // Forward all arguments to the real faro binary
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askfaro/cli",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Faro AI tool marketplace CLI",
5
5
  "bin": {
6
6
  "faro": "./bin/faro.js"
@@ -8,7 +8,13 @@
8
8
  "scripts": {
9
9
  "test": "node bin/faro.js --version"
10
10
  },
11
- "keywords": ["faro", "ai", "tools", "marketplace", "cli"],
11
+ "keywords": [
12
+ "faro",
13
+ "ai",
14
+ "tools",
15
+ "marketplace",
16
+ "cli"
17
+ ],
12
18
  "license": "MIT",
13
19
  "engines": {
14
20
  "node": ">=16"