@uselegion/cli 0.0.1-rc.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 +27 -0
- package/run.js +76 -0
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uselegion/cli",
|
|
3
|
+
"version": "0.0.1-rc.1",
|
|
4
|
+
"description": "Self-hosted, multi-channel AI agent gateway and CLI \u2014 installer wrapper that resolves the prebuilt `legion` binary for your platform.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/dawnswwwww/uselegion"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/dawnswwwww/uselegion#readme",
|
|
11
|
+
"bin": {
|
|
12
|
+
"legion": "run.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"run.js"
|
|
16
|
+
],
|
|
17
|
+
"optionalDependencies": {
|
|
18
|
+
"@uselegion/cli-darwin-arm64": "0.0.0",
|
|
19
|
+
"@uselegion/cli-darwin-x64": "0.0.0",
|
|
20
|
+
"@uselegion/cli-linux-arm64-musl": "0.0.0",
|
|
21
|
+
"@uselegion/cli-linux-x64-musl": "0.0.0",
|
|
22
|
+
"@uselegion/cli-win32-x64-msvc": "0.0.0"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/run.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `legion` entry point for the @uselegion/cli npm wrapper.
|
|
3
|
+
//
|
|
4
|
+
// Resolves the prebuilt `legion` binary that ships in the matching
|
|
5
|
+
// platform-specific optional dependency (@uselegion/cli-<plat>-<arch>) and
|
|
6
|
+
// spawns it with forwarded stdio + args. Falls back to a `legion` found on
|
|
7
|
+
// PATH if no platform package is installed (e.g. global installs where the
|
|
8
|
+
// optional dep was pruned).
|
|
9
|
+
|
|
10
|
+
const { spawn } = require("node:child_process");
|
|
11
|
+
const { existsSync } = require("node:fs");
|
|
12
|
+
const { join } = require("node:path");
|
|
13
|
+
|
|
14
|
+
// Map the current process to a platform package suffix.
|
|
15
|
+
const PLATFORMS = {
|
|
16
|
+
"darwin-arm64": "@uselegion/cli-darwin-arm64",
|
|
17
|
+
"darwin-x64": "@uselegion/cli-darwin-x64",
|
|
18
|
+
"linux-arm64": "@uselegion/cli-linux-arm64-musl",
|
|
19
|
+
"linux-x64": "@uselegion/cli-linux-x64-musl",
|
|
20
|
+
"win32-x64": "@uselegion/cli-win32-x64-msvc",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function resolveBinary() {
|
|
24
|
+
const key = `${process.platform}-${process.arch}`;
|
|
25
|
+
const pkg = PLATFORMS[key];
|
|
26
|
+
if (!pkg) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORMS).join(", ")}`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
let pkgDir;
|
|
32
|
+
try {
|
|
33
|
+
pkgDir = require.resolve(`${pkg}/package.json`);
|
|
34
|
+
} catch {
|
|
35
|
+
// Optional dependency was pruned — fall back to PATH lookup.
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const dir = require("node:path").dirname(pkgDir);
|
|
39
|
+
const exe =
|
|
40
|
+
process.platform === "win32" ? "legion.exe" : "legion";
|
|
41
|
+
// Platform packages ship the archive under bin/; we extract on install.
|
|
42
|
+
const candidate = join(dir, "bin", exe);
|
|
43
|
+
if (existsSync(candidate)) return candidate;
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function main() {
|
|
48
|
+
let bin = resolveBinary();
|
|
49
|
+
const args = process.argv.slice(2);
|
|
50
|
+
|
|
51
|
+
if (!bin) {
|
|
52
|
+
// Fall back to a `legion` on PATH (e.g. installed via cargo/brew).
|
|
53
|
+
const child = spawn("legion", args, { stdio: "inherit" });
|
|
54
|
+
child.on("error", (err) => {
|
|
55
|
+
if (err.code === "ENOENT") {
|
|
56
|
+
console.error(
|
|
57
|
+
"legion: no platform binary installed and `legion` not found on PATH.\n" +
|
|
58
|
+
"Install via Homebrew (`brew install dawnswwwww/tap/legion`) or Cargo (`cargo install legion-cli`).",
|
|
59
|
+
);
|
|
60
|
+
process.exit(127);
|
|
61
|
+
}
|
|
62
|
+
throw err;
|
|
63
|
+
});
|
|
64
|
+
child.on("exit", (code) => process.exit(code ?? 1));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const child = spawn(bin, args, { stdio: "inherit" });
|
|
69
|
+
child.on("error", (err) => {
|
|
70
|
+
console.error("legion: failed to spawn binary:", err.message);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
});
|
|
73
|
+
child.on("exit", (code) => process.exit(code ?? 1));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
main();
|