vibeman 0.0.6 → 0.0.7

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/dist/cli.js DELETED
@@ -1,135 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/index.ts
4
- import { spawn } from "node:child_process";
5
- import { basename, dirname, resolve } from "node:path";
6
- import { fileURLToPath } from "node:url";
7
- var args = process.argv.slice(2);
8
- var command = args[0];
9
- if (!command || command === "--help" || command === "-h" || command === "help") {
10
- printHelp();
11
- process.exit(0);
12
- }
13
- if (command !== "start") {
14
- console.error(`Unknown command: ${command}`);
15
- printHelp();
16
- process.exit(1);
17
- }
18
- var options = parseStartArgs(args.slice(1));
19
- await startApps(options);
20
- function parseStartArgs(argv) {
21
- const output = {
22
- path: ".",
23
- apiPort: 6970,
24
- uiPort: 6969,
25
- open: true
26
- };
27
- for (let i = 0;i < argv.length; i += 1) {
28
- const arg = argv[i];
29
- if (!arg)
30
- continue;
31
- if (arg === "--port") {
32
- const mainPort = Number(argv[i + 1]);
33
- output.uiPort = mainPort;
34
- output.apiPort = mainPort + 1;
35
- i += 1;
36
- continue;
37
- }
38
- if (arg === "--no-open") {
39
- output.open = false;
40
- continue;
41
- }
42
- if (!arg.startsWith("-") && output.path === ".") {
43
- output.path = arg;
44
- }
45
- }
46
- return output;
47
- }
48
- async function startApps(options2) {
49
- const selfDir = dirname(fileURLToPath(import.meta.url));
50
- const isDist = basename(selfDir) === "dist";
51
- const repoRoot = resolve(selfDir, "../../..");
52
- const apiEntry = isDist ? resolve(selfDir, "api.js") : resolve(repoRoot, "apps/api/src/index.ts");
53
- const uiEntry = isDist ? resolve(selfDir, "ui/index.js") : resolve(repoRoot, "apps/ui/index.ts");
54
- const bunArgs = isDist ? [] : ["--hot"];
55
- const apiProcess = spawn("bun", [...bunArgs, apiEntry], {
56
- cwd: process.cwd(),
57
- env: {
58
- ...process.env,
59
- API_PORT: String(options2.apiPort)
60
- },
61
- stdio: "inherit"
62
- });
63
- attachSpawnError(apiProcess, "API");
64
- const uiProcess = spawn("bun", [...bunArgs, uiEntry], {
65
- cwd: isDist ? resolve(selfDir, "ui") : resolve(repoRoot, "apps/ui"),
66
- env: {
67
- ...process.env,
68
- UI_PORT: String(options2.uiPort),
69
- API_BASE: `http://localhost:${options2.apiPort}`
70
- },
71
- stdio: "inherit"
72
- });
73
- attachSpawnError(uiProcess, "UI");
74
- const url = new URL(`http://localhost:${options2.uiPort}/`);
75
- url.searchParams.set("path", options2.path);
76
- if (options2.open) {
77
- await openBrowser(url.toString());
78
- }
79
- console.log(`
80
- Vibeman running:`);
81
- console.log(` API: http://localhost:${options2.apiPort}`);
82
- console.log(` UI: ${url.toString()}`);
83
- console.log("Press Ctrl+C to stop.");
84
- const stop = () => {
85
- apiProcess.kill();
86
- uiProcess.kill();
87
- };
88
- process.on("SIGINT", () => {
89
- stop();
90
- process.exit(0);
91
- });
92
- process.on("SIGTERM", () => {
93
- stop();
94
- process.exit(0);
95
- });
96
- const exitCode = await Promise.race([waitForExit(apiProcess), waitForExit(uiProcess)]);
97
- stop();
98
- process.exit(exitCode ?? 1);
99
- }
100
- async function openBrowser(target) {
101
- const platform = process.platform;
102
- if (platform === "darwin") {
103
- spawn("open", [target], { stdio: "ignore" });
104
- return;
105
- }
106
- if (platform === "win32") {
107
- spawn("cmd", ["/c", "start", target], { stdio: "ignore" });
108
- return;
109
- }
110
- spawn("xdg-open", [target], { stdio: "ignore" });
111
- }
112
- function printHelp() {
113
- console.log(`vibeman CLI
114
-
115
- Usage:
116
- vibeman start [path] [--port <port>] [--no-open]
117
-
118
- Examples:
119
- vibeman start .
120
- vibeman start ./notes --port 7010
121
- `);
122
- }
123
- function waitForExit(child) {
124
- return new Promise((resolvePromise) => {
125
- child.once("exit", (code) => resolvePromise(code));
126
- });
127
- }
128
- function attachSpawnError(child, label) {
129
- child.once("error", (error) => {
130
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
131
- console.error(`${label} failed to start: bun is required on your PATH.`);
132
- process.exit(1);
133
- }
134
- });
135
- }