brein 0.1.0 → 0.1.2
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/brein.js +31 -10
- package/package.json +1 -1
package/bin/brein.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
const { spawnSync, spawn } = require("node:child_process");
|
|
6
6
|
const { platform } = require("node:os");
|
|
7
|
+
const path = require("node:path");
|
|
7
8
|
|
|
8
9
|
const REPO_URL = "git+https://github.com/brein-sh/brein.git";
|
|
9
10
|
const MIN_PY = [3, 11];
|
|
@@ -95,13 +96,27 @@ function installBrein(branch) {
|
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
function uvToolBin() {
|
|
100
|
+
// Resolve the installed brein binary directly via uv. PATH lookup is
|
|
101
|
+
// unreliable inside `npx` (which prepends its own .bin and finds this
|
|
102
|
+
// wrapper instead of the Python CLI → recursion).
|
|
103
|
+
const r = spawnSync("uv", ["tool", "dir", "--bin"], { encoding: "utf8" });
|
|
104
|
+
if (r.status !== 0) return null;
|
|
105
|
+
const dir = r.stdout.trim();
|
|
106
|
+
const exe = platform() === "win32" ? "brein.exe" : "brein";
|
|
107
|
+
return path.join(dir, exe);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function resolveInstalledBrein() {
|
|
111
|
+
const direct = uvToolBin();
|
|
112
|
+
if (direct) {
|
|
113
|
+
const fs = require("node:fs");
|
|
114
|
+
if (fs.existsSync(direct)) return direct;
|
|
104
115
|
}
|
|
116
|
+
// Fallback: trust PATH (only safe outside npx, but worth a try).
|
|
117
|
+
const onPath = which("brein");
|
|
118
|
+
if (onPath && onPath !== process.argv[1]) return onPath;
|
|
119
|
+
return null;
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
function usage() {
|
|
@@ -132,18 +147,24 @@ function main() {
|
|
|
132
147
|
const branch = branchIdx >= 0 ? rest[branchIdx + 1] : null;
|
|
133
148
|
preflight();
|
|
134
149
|
installBrein(branch);
|
|
135
|
-
|
|
150
|
+
const installed = resolveInstalledBrein();
|
|
151
|
+
if (!installed) {
|
|
152
|
+
console.error(C.red("✗") + " brein installed but binary not found.");
|
|
153
|
+
console.error(" → run: " + C.bold("uv tool update-shell"));
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
136
156
|
console.log(C.bold("\nRunning ") + C.bold("brein setup") + C.bold("...\n"));
|
|
137
|
-
execReplace(
|
|
157
|
+
execReplace(installed, ["setup"]);
|
|
138
158
|
return;
|
|
139
159
|
}
|
|
140
160
|
|
|
141
161
|
// Forward anything else to the installed CLI.
|
|
142
|
-
|
|
162
|
+
const installed = resolveInstalledBrein();
|
|
163
|
+
if (!installed) {
|
|
143
164
|
console.error(C.red("✗") + " brein is not installed. Run: npx brein init");
|
|
144
165
|
process.exit(1);
|
|
145
166
|
}
|
|
146
|
-
execReplace(
|
|
167
|
+
execReplace(installed, [cmd, ...rest]);
|
|
147
168
|
}
|
|
148
169
|
|
|
149
170
|
main();
|