@lelu-auth/lelu 0.1.0 → 0.1.4

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.
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+
3
+ /*
4
+ * Lelu CLI
5
+ *
6
+ * Provides a one-command local dashboard bootstrap for SDK users.
7
+ */
8
+
9
+ const { spawnSync } = require("node:child_process");
10
+ const fs = require("node:fs");
11
+ const os = require("node:os");
12
+ const path = require("node:path");
13
+
14
+ const REPO_URL = "https://github.com/lelu-auth/lelu.git";
15
+ const STACK_DIR = path.join(os.homedir(), ".lelu-stack");
16
+ const DASHBOARD_URL = "http://localhost:3002/audit";
17
+
18
+ function run(cmd, args, options = {}) {
19
+ const result = spawnSync(cmd, args, {
20
+ stdio: "inherit",
21
+ shell: false,
22
+ ...options,
23
+ });
24
+
25
+ if (result.error) {
26
+ throw result.error;
27
+ }
28
+ if (result.status !== 0) {
29
+ throw new Error(`${cmd} ${args.join(" ")} failed with code ${result.status}`);
30
+ }
31
+ }
32
+
33
+ function checkTool(command, name) {
34
+ const check = spawnSync(command, ["--version"], { stdio: "ignore", shell: false });
35
+ if (check.error || check.status !== 0) {
36
+ console.error(`\n${name} is required but was not found in PATH.`);
37
+ process.exit(1);
38
+ }
39
+ }
40
+
41
+ function ensureRepo() {
42
+ if (!fs.existsSync(STACK_DIR)) {
43
+ console.log(`\nCloning Lelu stack into ${STACK_DIR} ...`);
44
+ run("git", ["clone", "--depth", "1", REPO_URL, STACK_DIR]);
45
+ return;
46
+ }
47
+
48
+ console.log("\nUpdating local Lelu stack...");
49
+ run("git", ["-C", STACK_DIR, "checkout", "main"]);
50
+ run("git", ["-C", STACK_DIR, "pull", "--ff-only", "origin", "main"]);
51
+ }
52
+
53
+ function startDashboard() {
54
+ checkTool("git", "Git");
55
+ checkTool("docker", "Docker");
56
+
57
+ ensureRepo();
58
+
59
+ console.log("\nStarting local Lelu dashboard stack (this may take a few minutes)...");
60
+ run("docker", ["compose", "up", "-d", "--build"], { cwd: STACK_DIR });
61
+
62
+ console.log("\nLelu dashboard is ready:");
63
+ console.log(` ${DASHBOARD_URL}`);
64
+ console.log("\nTo stop later:");
65
+ console.log(` cd ${STACK_DIR}`);
66
+ console.log(" docker compose down");
67
+ }
68
+
69
+ function printHelp() {
70
+ console.log(`
71
+ Lelu CLI
72
+
73
+ Usage:
74
+ lelu dashboard Start local dashboard stack and print URL
75
+ lelu help Show this help
76
+ `);
77
+ }
78
+
79
+ function main() {
80
+ const command = process.argv[2] || "dashboard";
81
+
82
+ if (command === "dashboard") {
83
+ startDashboard();
84
+ return;
85
+ }
86
+
87
+ if (command === "help" || command === "-h" || command === "--help") {
88
+ printHelp();
89
+ return;
90
+ }
91
+
92
+ console.error(`Unknown command: ${command}`);
93
+ printHelp();
94
+ process.exit(1);
95
+ }
96
+
97
+ main();