@kohryan/moodui 0.0.7 → 0.0.9

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.mjs CHANGED
@@ -3,8 +3,527 @@ import {
3
3
  } from "./chunk-5D6KNM5J.mjs";
4
4
 
5
5
  // src/cli.ts
6
- import fs from "fs/promises";
6
+ import fs6 from "fs/promises";
7
+ import path2 from "path";
8
+ import { fileURLToPath as fileURLToPath2 } from "url";
9
+ import http from "http";
10
+
11
+ // node_modules/open/index.js
12
+ import process7 from "process";
13
+ import { Buffer } from "buffer";
7
14
  import path from "path";
15
+ import { fileURLToPath } from "url";
16
+ import { promisify as promisify5 } from "util";
17
+ import childProcess from "child_process";
18
+ import fs5, { constants as fsConstants2 } from "fs/promises";
19
+
20
+ // node_modules/wsl-utils/index.js
21
+ import process3 from "process";
22
+ import fs4, { constants as fsConstants } from "fs/promises";
23
+
24
+ // node_modules/is-wsl/index.js
25
+ import process2 from "process";
26
+ import os from "os";
27
+ import fs3 from "fs";
28
+
29
+ // node_modules/is-inside-container/index.js
30
+ import fs2 from "fs";
31
+
32
+ // node_modules/is-docker/index.js
33
+ import fs from "fs";
34
+ var isDockerCached;
35
+ function hasDockerEnv() {
36
+ try {
37
+ fs.statSync("/.dockerenv");
38
+ return true;
39
+ } catch {
40
+ return false;
41
+ }
42
+ }
43
+ function hasDockerCGroup() {
44
+ try {
45
+ return fs.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
50
+ function isDocker() {
51
+ if (isDockerCached === void 0) {
52
+ isDockerCached = hasDockerEnv() || hasDockerCGroup();
53
+ }
54
+ return isDockerCached;
55
+ }
56
+
57
+ // node_modules/is-inside-container/index.js
58
+ var cachedResult;
59
+ var hasContainerEnv = () => {
60
+ try {
61
+ fs2.statSync("/run/.containerenv");
62
+ return true;
63
+ } catch {
64
+ return false;
65
+ }
66
+ };
67
+ function isInsideContainer() {
68
+ if (cachedResult === void 0) {
69
+ cachedResult = hasContainerEnv() || isDocker();
70
+ }
71
+ return cachedResult;
72
+ }
73
+
74
+ // node_modules/is-wsl/index.js
75
+ var isWsl = () => {
76
+ if (process2.platform !== "linux") {
77
+ return false;
78
+ }
79
+ if (os.release().toLowerCase().includes("microsoft")) {
80
+ if (isInsideContainer()) {
81
+ return false;
82
+ }
83
+ return true;
84
+ }
85
+ try {
86
+ if (fs3.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft")) {
87
+ return !isInsideContainer();
88
+ }
89
+ } catch {
90
+ }
91
+ if (fs3.existsSync("/proc/sys/fs/binfmt_misc/WSLInterop") || fs3.existsSync("/run/WSL")) {
92
+ return !isInsideContainer();
93
+ }
94
+ return false;
95
+ };
96
+ var is_wsl_default = process2.env.__IS_WSL_TEST__ ? isWsl : isWsl();
97
+
98
+ // node_modules/wsl-utils/index.js
99
+ var wslDrivesMountPoint = /* @__PURE__ */ (() => {
100
+ const defaultMountPoint = "/mnt/";
101
+ let mountPoint;
102
+ return async function() {
103
+ if (mountPoint) {
104
+ return mountPoint;
105
+ }
106
+ const configFilePath = "/etc/wsl.conf";
107
+ let isConfigFileExists = false;
108
+ try {
109
+ await fs4.access(configFilePath, fsConstants.F_OK);
110
+ isConfigFileExists = true;
111
+ } catch {
112
+ }
113
+ if (!isConfigFileExists) {
114
+ return defaultMountPoint;
115
+ }
116
+ const configContent = await fs4.readFile(configFilePath, { encoding: "utf8" });
117
+ const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
118
+ if (!configMountPoint) {
119
+ return defaultMountPoint;
120
+ }
121
+ mountPoint = configMountPoint.groups.mountPoint.trim();
122
+ mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
123
+ return mountPoint;
124
+ };
125
+ })();
126
+ var powerShellPathFromWsl = async () => {
127
+ const mountPoint = await wslDrivesMountPoint();
128
+ return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
129
+ };
130
+ var powerShellPath = async () => {
131
+ if (is_wsl_default) {
132
+ return powerShellPathFromWsl();
133
+ }
134
+ return `${process3.env.SYSTEMROOT || process3.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
135
+ };
136
+
137
+ // node_modules/define-lazy-prop/index.js
138
+ function defineLazyProperty(object, propertyName, valueGetter) {
139
+ const define = (value) => Object.defineProperty(object, propertyName, { value, enumerable: true, writable: true });
140
+ Object.defineProperty(object, propertyName, {
141
+ configurable: true,
142
+ enumerable: true,
143
+ get() {
144
+ const result = valueGetter();
145
+ define(result);
146
+ return result;
147
+ },
148
+ set(value) {
149
+ define(value);
150
+ }
151
+ });
152
+ return object;
153
+ }
154
+
155
+ // node_modules/default-browser/index.js
156
+ import { promisify as promisify4 } from "util";
157
+ import process6 from "process";
158
+ import { execFile as execFile4 } from "child_process";
159
+
160
+ // node_modules/default-browser-id/index.js
161
+ import { promisify } from "util";
162
+ import process4 from "process";
163
+ import { execFile } from "child_process";
164
+ var execFileAsync = promisify(execFile);
165
+ async function defaultBrowserId() {
166
+ if (process4.platform !== "darwin") {
167
+ throw new Error("macOS only");
168
+ }
169
+ const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
170
+ const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
171
+ const browserId = match?.groups.id ?? "com.apple.Safari";
172
+ if (browserId === "com.apple.safari") {
173
+ return "com.apple.Safari";
174
+ }
175
+ return browserId;
176
+ }
177
+
178
+ // node_modules/run-applescript/index.js
179
+ import process5 from "process";
180
+ import { promisify as promisify2 } from "util";
181
+ import { execFile as execFile2, execFileSync } from "child_process";
182
+ var execFileAsync2 = promisify2(execFile2);
183
+ async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
184
+ if (process5.platform !== "darwin") {
185
+ throw new Error("macOS only");
186
+ }
187
+ const outputArguments = humanReadableOutput ? [] : ["-ss"];
188
+ const execOptions = {};
189
+ if (signal) {
190
+ execOptions.signal = signal;
191
+ }
192
+ const { stdout } = await execFileAsync2("osascript", ["-e", script, outputArguments], execOptions);
193
+ return stdout.trim();
194
+ }
195
+
196
+ // node_modules/bundle-name/index.js
197
+ async function bundleName(bundleId) {
198
+ return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string
199
+ tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
200
+ }
201
+
202
+ // node_modules/default-browser/windows.js
203
+ import { promisify as promisify3 } from "util";
204
+ import { execFile as execFile3 } from "child_process";
205
+ var execFileAsync3 = promisify3(execFile3);
206
+ var windowsBrowserProgIds = {
207
+ MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
208
+ // The missing `L` is correct.
209
+ MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
210
+ MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" },
211
+ AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
212
+ ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
213
+ ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" },
214
+ ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" },
215
+ ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" },
216
+ BraveHTML: { name: "Brave", id: "com.brave.Browser" },
217
+ BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
218
+ BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" },
219
+ BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" },
220
+ FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
221
+ OperaStable: { name: "Opera", id: "com.operasoftware.Opera" },
222
+ VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" },
223
+ "IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" }
224
+ };
225
+ var _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
226
+ var UnknownBrowserError = class extends Error {
227
+ };
228
+ async function defaultBrowser(_execFileAsync = execFileAsync3) {
229
+ const { stdout } = await _execFileAsync("reg", [
230
+ "QUERY",
231
+ " HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
232
+ "/v",
233
+ "ProgId"
234
+ ]);
235
+ const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
236
+ if (!match) {
237
+ throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
238
+ }
239
+ const { id } = match.groups;
240
+ const dotIndex = id.lastIndexOf(".");
241
+ const hyphenIndex = id.lastIndexOf("-");
242
+ const baseIdByDot = dotIndex === -1 ? void 0 : id.slice(0, dotIndex);
243
+ const baseIdByHyphen = hyphenIndex === -1 ? void 0 : id.slice(0, hyphenIndex);
244
+ return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? { name: id, id };
245
+ }
246
+
247
+ // node_modules/default-browser/index.js
248
+ var execFileAsync4 = promisify4(execFile4);
249
+ var titleize = (string) => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
250
+ async function defaultBrowser2() {
251
+ if (process6.platform === "darwin") {
252
+ const id = await defaultBrowserId();
253
+ const name = await bundleName(id);
254
+ return { name, id };
255
+ }
256
+ if (process6.platform === "linux") {
257
+ const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
258
+ const id = stdout.trim();
259
+ const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
260
+ return { name, id };
261
+ }
262
+ if (process6.platform === "win32") {
263
+ return defaultBrowser();
264
+ }
265
+ throw new Error("Only macOS, Linux, and Windows are supported");
266
+ }
267
+
268
+ // node_modules/open/index.js
269
+ var execFile5 = promisify5(childProcess.execFile);
270
+ var __dirname = path.dirname(fileURLToPath(import.meta.url));
271
+ var localXdgOpenPath = path.join(__dirname, "xdg-open");
272
+ var { platform, arch } = process7;
273
+ async function getWindowsDefaultBrowserFromWsl() {
274
+ const powershellPath = await powerShellPath();
275
+ const rawCommand = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
276
+ const encodedCommand = Buffer.from(rawCommand, "utf16le").toString("base64");
277
+ const { stdout } = await execFile5(
278
+ powershellPath,
279
+ [
280
+ "-NoProfile",
281
+ "-NonInteractive",
282
+ "-ExecutionPolicy",
283
+ "Bypass",
284
+ "-EncodedCommand",
285
+ encodedCommand
286
+ ],
287
+ { encoding: "utf8" }
288
+ );
289
+ const progId = stdout.trim();
290
+ const browserMap = {
291
+ ChromeHTML: "com.google.chrome",
292
+ BraveHTML: "com.brave.Browser",
293
+ MSEdgeHTM: "com.microsoft.edge",
294
+ FirefoxURL: "org.mozilla.firefox"
295
+ };
296
+ return browserMap[progId] ? { id: browserMap[progId] } : {};
297
+ }
298
+ var pTryEach = async (array, mapper) => {
299
+ let latestError;
300
+ for (const item of array) {
301
+ try {
302
+ return await mapper(item);
303
+ } catch (error) {
304
+ latestError = error;
305
+ }
306
+ }
307
+ throw latestError;
308
+ };
309
+ var baseOpen = async (options) => {
310
+ options = {
311
+ wait: false,
312
+ background: false,
313
+ newInstance: false,
314
+ allowNonzeroExitCode: false,
315
+ ...options
316
+ };
317
+ if (Array.isArray(options.app)) {
318
+ return pTryEach(options.app, (singleApp) => baseOpen({
319
+ ...options,
320
+ app: singleApp
321
+ }));
322
+ }
323
+ let { name: app, arguments: appArguments = [] } = options.app ?? {};
324
+ appArguments = [...appArguments];
325
+ if (Array.isArray(app)) {
326
+ return pTryEach(app, (appName) => baseOpen({
327
+ ...options,
328
+ app: {
329
+ name: appName,
330
+ arguments: appArguments
331
+ }
332
+ }));
333
+ }
334
+ if (app === "browser" || app === "browserPrivate") {
335
+ const ids = {
336
+ "com.google.chrome": "chrome",
337
+ "google-chrome.desktop": "chrome",
338
+ "com.brave.Browser": "brave",
339
+ "org.mozilla.firefox": "firefox",
340
+ "firefox.desktop": "firefox",
341
+ "com.microsoft.msedge": "edge",
342
+ "com.microsoft.edge": "edge",
343
+ "com.microsoft.edgemac": "edge",
344
+ "microsoft-edge.desktop": "edge"
345
+ };
346
+ const flags = {
347
+ chrome: "--incognito",
348
+ brave: "--incognito",
349
+ firefox: "--private-window",
350
+ edge: "--inPrivate"
351
+ };
352
+ const browser = is_wsl_default ? await getWindowsDefaultBrowserFromWsl() : await defaultBrowser2();
353
+ if (browser.id in ids) {
354
+ const browserName = ids[browser.id];
355
+ if (app === "browserPrivate") {
356
+ appArguments.push(flags[browserName]);
357
+ }
358
+ return baseOpen({
359
+ ...options,
360
+ app: {
361
+ name: apps[browserName],
362
+ arguments: appArguments
363
+ }
364
+ });
365
+ }
366
+ throw new Error(`${browser.name} is not supported as a default browser`);
367
+ }
368
+ let command;
369
+ const cliArguments = [];
370
+ const childProcessOptions = {};
371
+ if (platform === "darwin") {
372
+ command = "open";
373
+ if (options.wait) {
374
+ cliArguments.push("--wait-apps");
375
+ }
376
+ if (options.background) {
377
+ cliArguments.push("--background");
378
+ }
379
+ if (options.newInstance) {
380
+ cliArguments.push("--new");
381
+ }
382
+ if (app) {
383
+ cliArguments.push("-a", app);
384
+ }
385
+ } else if (platform === "win32" || is_wsl_default && !isInsideContainer() && !app) {
386
+ command = await powerShellPath();
387
+ cliArguments.push(
388
+ "-NoProfile",
389
+ "-NonInteractive",
390
+ "-ExecutionPolicy",
391
+ "Bypass",
392
+ "-EncodedCommand"
393
+ );
394
+ if (!is_wsl_default) {
395
+ childProcessOptions.windowsVerbatimArguments = true;
396
+ }
397
+ const encodedArguments = ["Start"];
398
+ if (options.wait) {
399
+ encodedArguments.push("-Wait");
400
+ }
401
+ if (app) {
402
+ encodedArguments.push(`"\`"${app}\`""`);
403
+ if (options.target) {
404
+ appArguments.push(options.target);
405
+ }
406
+ } else if (options.target) {
407
+ encodedArguments.push(`"${options.target}"`);
408
+ }
409
+ if (appArguments.length > 0) {
410
+ appArguments = appArguments.map((argument) => `"\`"${argument}\`""`);
411
+ encodedArguments.push("-ArgumentList", appArguments.join(","));
412
+ }
413
+ options.target = Buffer.from(encodedArguments.join(" "), "utf16le").toString("base64");
414
+ } else {
415
+ if (app) {
416
+ command = app;
417
+ } else {
418
+ const isBundled = !__dirname || __dirname === "/";
419
+ let exeLocalXdgOpen = false;
420
+ try {
421
+ await fs5.access(localXdgOpenPath, fsConstants2.X_OK);
422
+ exeLocalXdgOpen = true;
423
+ } catch {
424
+ }
425
+ const useSystemXdgOpen = process7.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
426
+ command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
427
+ }
428
+ if (appArguments.length > 0) {
429
+ cliArguments.push(...appArguments);
430
+ }
431
+ if (!options.wait) {
432
+ childProcessOptions.stdio = "ignore";
433
+ childProcessOptions.detached = true;
434
+ }
435
+ }
436
+ if (platform === "darwin" && appArguments.length > 0) {
437
+ cliArguments.push("--args", ...appArguments);
438
+ }
439
+ if (options.target) {
440
+ cliArguments.push(options.target);
441
+ }
442
+ const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
443
+ if (options.wait) {
444
+ return new Promise((resolve, reject) => {
445
+ subprocess.once("error", reject);
446
+ subprocess.once("close", (exitCode) => {
447
+ if (!options.allowNonzeroExitCode && exitCode > 0) {
448
+ reject(new Error(`Exited with code ${exitCode}`));
449
+ return;
450
+ }
451
+ resolve(subprocess);
452
+ });
453
+ });
454
+ }
455
+ subprocess.unref();
456
+ return subprocess;
457
+ };
458
+ var open = (target, options) => {
459
+ if (typeof target !== "string") {
460
+ throw new TypeError("Expected a `target`");
461
+ }
462
+ return baseOpen({
463
+ ...options,
464
+ target
465
+ });
466
+ };
467
+ function detectArchBinary(binary) {
468
+ if (typeof binary === "string" || Array.isArray(binary)) {
469
+ return binary;
470
+ }
471
+ const { [arch]: archBinary } = binary;
472
+ if (!archBinary) {
473
+ throw new Error(`${arch} is not supported`);
474
+ }
475
+ return archBinary;
476
+ }
477
+ function detectPlatformBinary({ [platform]: platformBinary }, { wsl }) {
478
+ if (wsl && is_wsl_default) {
479
+ return detectArchBinary(wsl);
480
+ }
481
+ if (!platformBinary) {
482
+ throw new Error(`${platform} is not supported`);
483
+ }
484
+ return detectArchBinary(platformBinary);
485
+ }
486
+ var apps = {};
487
+ defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
488
+ darwin: "google chrome",
489
+ win32: "chrome",
490
+ linux: ["google-chrome", "google-chrome-stable", "chromium"]
491
+ }, {
492
+ wsl: {
493
+ ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
494
+ x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
495
+ }
496
+ }));
497
+ defineLazyProperty(apps, "brave", () => detectPlatformBinary({
498
+ darwin: "brave browser",
499
+ win32: "brave",
500
+ linux: ["brave-browser", "brave"]
501
+ }, {
502
+ wsl: {
503
+ ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
504
+ x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
505
+ }
506
+ }));
507
+ defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
508
+ darwin: "firefox",
509
+ win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
510
+ linux: "firefox"
511
+ }, {
512
+ wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
513
+ }));
514
+ defineLazyProperty(apps, "edge", () => detectPlatformBinary({
515
+ darwin: "microsoft edge",
516
+ win32: "msedge",
517
+ linux: ["microsoft-edge", "microsoft-edge-dev"]
518
+ }, {
519
+ wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
520
+ }));
521
+ defineLazyProperty(apps, "browser", () => "browser");
522
+ defineLazyProperty(apps, "browserPrivate", () => "browserPrivate");
523
+ var open_default = open;
524
+
525
+ // src/cli.ts
526
+ var __dirname2 = path2.dirname(fileURLToPath2(import.meta.url));
8
527
  async function main() {
9
528
  const argv = process.argv.slice(2);
10
529
  const command = argv[0] ?? "help";
@@ -12,6 +531,10 @@ async function main() {
12
531
  printHelp();
13
532
  return;
14
533
  }
534
+ if (command === "ui") {
535
+ await runUI();
536
+ return;
537
+ }
15
538
  if (command !== "generate") {
16
539
  console.error(`Unknown command: ${command}`);
17
540
  printHelp();
@@ -74,21 +597,69 @@ async function main() {
74
597
  temperature,
75
598
  maxAttempts
76
599
  });
77
- const resolvedOut = path.resolve(process.cwd(), outFile);
78
- await fs.mkdir(path.dirname(resolvedOut), { recursive: true });
79
- await fs.writeFile(resolvedOut, result.code, "utf8");
600
+ const resolvedOut = path2.resolve(process.cwd(), outFile);
601
+ await fs6.mkdir(path2.dirname(resolvedOut), { recursive: true });
602
+ await fs6.writeFile(resolvedOut, result.code, "utf8");
80
603
  console.log(`OK: wrote ${resolvedOut}`);
81
604
  }
605
+ async function runUI() {
606
+ let uiDir = path2.join(__dirname2, "ui");
607
+ try {
608
+ await fs6.access(uiDir);
609
+ } catch {
610
+ uiDir = path2.join(__dirname2, "..", "dist", "ui");
611
+ }
612
+ const PORT = 3e3;
613
+ console.log(`Starting MoodUI UI...`);
614
+ const server = http.createServer(async (req, res) => {
615
+ let filePath = path2.join(uiDir, req.url === "/" ? "index.html" : req.url);
616
+ const extname = String(path2.extname(filePath)).toLowerCase();
617
+ const mimeTypes = {
618
+ ".html": "text/html",
619
+ ".js": "text/javascript",
620
+ ".css": "text/css",
621
+ ".json": "application/json",
622
+ ".png": "image/png",
623
+ ".jpg": "image/jpg",
624
+ ".gif": "image/gif",
625
+ ".svg": "image/svg+xml",
626
+ ".ico": "image/x-icon"
627
+ };
628
+ const contentType = mimeTypes[extname] || "application/octet-stream";
629
+ try {
630
+ const content = await fs6.readFile(filePath);
631
+ res.writeHead(200, { "Content-Type": contentType });
632
+ res.end(content, "utf-8");
633
+ } catch (err) {
634
+ res.writeHead(404);
635
+ res.end("Not Found", "utf-8");
636
+ }
637
+ });
638
+ server.listen(PORT, () => {
639
+ const url = `http://localhost:${PORT}`;
640
+ console.log(`MoodUI UI running at ${url}`);
641
+ open_default(url);
642
+ });
643
+ process.on("SIGINT", () => {
644
+ server.close();
645
+ process.exit(0);
646
+ });
647
+ }
82
648
  function printHelp() {
83
649
  console.log(
84
650
  [
85
- "moodui generate [options] <prompt...>",
651
+ "moodui <command>",
652
+ "",
653
+ "Commands:",
654
+ " generate [options] <prompt...> Generate component via CLI",
655
+ " ui Launch Web UI for generating components",
656
+ " help, --help, -h Show this help message",
86
657
  "",
87
- "Options:",
658
+ "Generate Options:",
88
659
  " --provider gemini|ollama|openai-compatible default: gemini",
89
660
  " --model <name> required (default for gemini: gemini-3-flash-preview)",
90
- " --out <path> default: src/generated/MoodScreen.tsx",
91
- " --component <name> default: MoodScreen",
661
+ " --out <path> path lengkap ke file output (termasuk direktori), default: src/generated/MoodScreen.tsx",
662
+ " --component <name> nama component, default: MoodScreen",
92
663
  " --prompt <text> optional (or pass as positional args)",
93
664
  " --temperature <number>",
94
665
  " --maxAttempts <number>",
@@ -99,8 +670,18 @@ function printHelp() {
99
670
  " OPENAI_COMPATIBLE_BASE_URL",
100
671
  " OPENAI_COMPATIBLE_API_KEY",
101
672
  "",
102
- "Example:",
103
- ' GEMINI_API_KEY=... npx @kohryan/moodui generate --model gemini-3-flash-preview "Buat UI login sederhana"'
673
+ "Examples:",
674
+ " # Launch Web UI",
675
+ " npx @kohryan/moodui ui",
676
+ "",
677
+ " # Generate ke src/generated/MoodScreen.tsx (default)",
678
+ ' GEMINI_API_KEY=... npx @kohryan/moodui generate --model gemini-3-flash-preview "Buat UI login sederhana"',
679
+ "",
680
+ " # Generate ke src/components/LoginPage.tsx",
681
+ ' GEMINI_API_KEY=... npx @kohryan/moodui generate --model gemini-3-flash-preview --out src/components/LoginPage.tsx --component LoginPage "Buat UI login"',
682
+ "",
683
+ " # Generate ke src/pages/Home.tsx",
684
+ ' GEMINI_API_KEY=... npx @kohryan/moodui generate --model gemini-3-flash-preview --out src/pages/Home.tsx --component Home "Buat homepage"'
104
685
  ].join("\n")
105
686
  );
106
687
  }