@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.
- package/bin/faro.js +45 -13
- 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.
|
|
9
|
+
const MIN_VERSION = "0.3.0";
|
|
10
10
|
|
|
11
|
-
function
|
|
12
|
-
|
|
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
|
|
15
|
-
if (
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
|
68
|
-
|
|
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.
|
|
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": [
|
|
11
|
+
"keywords": [
|
|
12
|
+
"faro",
|
|
13
|
+
"ai",
|
|
14
|
+
"tools",
|
|
15
|
+
"marketplace",
|
|
16
|
+
"cli"
|
|
17
|
+
],
|
|
12
18
|
"license": "MIT",
|
|
13
19
|
"engines": {
|
|
14
20
|
"node": ">=16"
|