@kohryan/moodui 0.0.8 → 0.0.10
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/chunk-WRMZ2MC6.mjs +572 -0
- package/dist/cli.d.mts +1 -2
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +600 -24
- package/dist/cli.mjs +583 -7
- package/dist/index.js +1 -0
- package/dist/index.mjs +2 -1
- package/dist/ui/assets/index-BKsInBa3.js +7 -0
- package/dist/ui/assets/index-CMk6XQXy.js +58 -0
- package/dist/ui/index.html +12 -0
- package/package.json +12 -7
- package/src/ui/index.html +12 -0
- package/src/ui/main.tsx +11 -0
- package/src/ui/vite.config.ts +17 -0
package/dist/cli.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
#!/usr/bin/env node
|
|
1
3
|
"use strict";
|
|
2
4
|
var __create = Object.create;
|
|
3
5
|
var __defProp = Object.defineProperty;
|
|
@@ -23,8 +25,525 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
25
|
));
|
|
24
26
|
|
|
25
27
|
// src/cli.ts
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
+
var import_promises3 = __toESM(require("fs/promises"));
|
|
29
|
+
var import_node_path2 = __toESM(require("path"));
|
|
30
|
+
var import_node_url2 = require("url");
|
|
31
|
+
var import_node_http = __toESM(require("http"));
|
|
32
|
+
|
|
33
|
+
// node_modules/open/index.js
|
|
34
|
+
var import_node_process6 = __toESM(require("process"), 1);
|
|
35
|
+
var import_node_buffer = require("buffer");
|
|
36
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
37
|
+
var import_node_url = require("url");
|
|
38
|
+
var import_node_util5 = require("util");
|
|
39
|
+
var import_node_child_process5 = __toESM(require("child_process"), 1);
|
|
40
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
41
|
+
|
|
42
|
+
// node_modules/wsl-utils/index.js
|
|
43
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
44
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
45
|
+
|
|
46
|
+
// node_modules/is-wsl/index.js
|
|
47
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
48
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
49
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
50
|
+
|
|
51
|
+
// node_modules/is-inside-container/index.js
|
|
52
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
53
|
+
|
|
54
|
+
// node_modules/is-docker/index.js
|
|
55
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
56
|
+
var isDockerCached;
|
|
57
|
+
function hasDockerEnv() {
|
|
58
|
+
try {
|
|
59
|
+
import_node_fs.default.statSync("/.dockerenv");
|
|
60
|
+
return true;
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function hasDockerCGroup() {
|
|
66
|
+
try {
|
|
67
|
+
return import_node_fs.default.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
68
|
+
} catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function isDocker() {
|
|
73
|
+
if (isDockerCached === void 0) {
|
|
74
|
+
isDockerCached = hasDockerEnv() || hasDockerCGroup();
|
|
75
|
+
}
|
|
76
|
+
return isDockerCached;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// node_modules/is-inside-container/index.js
|
|
80
|
+
var cachedResult;
|
|
81
|
+
var hasContainerEnv = () => {
|
|
82
|
+
try {
|
|
83
|
+
import_node_fs2.default.statSync("/run/.containerenv");
|
|
84
|
+
return true;
|
|
85
|
+
} catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
function isInsideContainer() {
|
|
90
|
+
if (cachedResult === void 0) {
|
|
91
|
+
cachedResult = hasContainerEnv() || isDocker();
|
|
92
|
+
}
|
|
93
|
+
return cachedResult;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// node_modules/is-wsl/index.js
|
|
97
|
+
var isWsl = () => {
|
|
98
|
+
if (import_node_process.default.platform !== "linux") {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (import_node_os.default.release().toLowerCase().includes("microsoft")) {
|
|
102
|
+
if (isInsideContainer()) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
if (import_node_fs3.default.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft")) {
|
|
109
|
+
return !isInsideContainer();
|
|
110
|
+
}
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
if (import_node_fs3.default.existsSync("/proc/sys/fs/binfmt_misc/WSLInterop") || import_node_fs3.default.existsSync("/run/WSL")) {
|
|
114
|
+
return !isInsideContainer();
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
};
|
|
118
|
+
var is_wsl_default = import_node_process.default.env.__IS_WSL_TEST__ ? isWsl : isWsl();
|
|
119
|
+
|
|
120
|
+
// node_modules/wsl-utils/index.js
|
|
121
|
+
var wslDrivesMountPoint = /* @__PURE__ */ (() => {
|
|
122
|
+
const defaultMountPoint = "/mnt/";
|
|
123
|
+
let mountPoint;
|
|
124
|
+
return async function() {
|
|
125
|
+
if (mountPoint) {
|
|
126
|
+
return mountPoint;
|
|
127
|
+
}
|
|
128
|
+
const configFilePath = "/etc/wsl.conf";
|
|
129
|
+
let isConfigFileExists = false;
|
|
130
|
+
try {
|
|
131
|
+
await import_promises.default.access(configFilePath, import_promises.constants.F_OK);
|
|
132
|
+
isConfigFileExists = true;
|
|
133
|
+
} catch {
|
|
134
|
+
}
|
|
135
|
+
if (!isConfigFileExists) {
|
|
136
|
+
return defaultMountPoint;
|
|
137
|
+
}
|
|
138
|
+
const configContent = await import_promises.default.readFile(configFilePath, { encoding: "utf8" });
|
|
139
|
+
const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
|
|
140
|
+
if (!configMountPoint) {
|
|
141
|
+
return defaultMountPoint;
|
|
142
|
+
}
|
|
143
|
+
mountPoint = configMountPoint.groups.mountPoint.trim();
|
|
144
|
+
mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
|
|
145
|
+
return mountPoint;
|
|
146
|
+
};
|
|
147
|
+
})();
|
|
148
|
+
var powerShellPathFromWsl = async () => {
|
|
149
|
+
const mountPoint = await wslDrivesMountPoint();
|
|
150
|
+
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
|
151
|
+
};
|
|
152
|
+
var powerShellPath = async () => {
|
|
153
|
+
if (is_wsl_default) {
|
|
154
|
+
return powerShellPathFromWsl();
|
|
155
|
+
}
|
|
156
|
+
return `${import_node_process2.default.env.SYSTEMROOT || import_node_process2.default.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// node_modules/define-lazy-prop/index.js
|
|
160
|
+
function defineLazyProperty(object, propertyName, valueGetter) {
|
|
161
|
+
const define = (value) => Object.defineProperty(object, propertyName, { value, enumerable: true, writable: true });
|
|
162
|
+
Object.defineProperty(object, propertyName, {
|
|
163
|
+
configurable: true,
|
|
164
|
+
enumerable: true,
|
|
165
|
+
get() {
|
|
166
|
+
const result = valueGetter();
|
|
167
|
+
define(result);
|
|
168
|
+
return result;
|
|
169
|
+
},
|
|
170
|
+
set(value) {
|
|
171
|
+
define(value);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return object;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// node_modules/default-browser/index.js
|
|
178
|
+
var import_node_util4 = require("util");
|
|
179
|
+
var import_node_process5 = __toESM(require("process"), 1);
|
|
180
|
+
var import_node_child_process4 = require("child_process");
|
|
181
|
+
|
|
182
|
+
// node_modules/default-browser-id/index.js
|
|
183
|
+
var import_node_util = require("util");
|
|
184
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
185
|
+
var import_node_child_process = require("child_process");
|
|
186
|
+
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
|
|
187
|
+
async function defaultBrowserId() {
|
|
188
|
+
if (import_node_process3.default.platform !== "darwin") {
|
|
189
|
+
throw new Error("macOS only");
|
|
190
|
+
}
|
|
191
|
+
const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
|
|
192
|
+
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
|
|
193
|
+
const browserId = match?.groups.id ?? "com.apple.Safari";
|
|
194
|
+
if (browserId === "com.apple.safari") {
|
|
195
|
+
return "com.apple.Safari";
|
|
196
|
+
}
|
|
197
|
+
return browserId;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// node_modules/run-applescript/index.js
|
|
201
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
202
|
+
var import_node_util2 = require("util");
|
|
203
|
+
var import_node_child_process2 = require("child_process");
|
|
204
|
+
var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
|
|
205
|
+
async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
|
|
206
|
+
if (import_node_process4.default.platform !== "darwin") {
|
|
207
|
+
throw new Error("macOS only");
|
|
208
|
+
}
|
|
209
|
+
const outputArguments = humanReadableOutput ? [] : ["-ss"];
|
|
210
|
+
const execOptions = {};
|
|
211
|
+
if (signal) {
|
|
212
|
+
execOptions.signal = signal;
|
|
213
|
+
}
|
|
214
|
+
const { stdout } = await execFileAsync2("osascript", ["-e", script, outputArguments], execOptions);
|
|
215
|
+
return stdout.trim();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// node_modules/bundle-name/index.js
|
|
219
|
+
async function bundleName(bundleId) {
|
|
220
|
+
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string
|
|
221
|
+
tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// node_modules/default-browser/windows.js
|
|
225
|
+
var import_node_util3 = require("util");
|
|
226
|
+
var import_node_child_process3 = require("child_process");
|
|
227
|
+
var execFileAsync3 = (0, import_node_util3.promisify)(import_node_child_process3.execFile);
|
|
228
|
+
var windowsBrowserProgIds = {
|
|
229
|
+
MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
|
|
230
|
+
// The missing `L` is correct.
|
|
231
|
+
MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
|
|
232
|
+
MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" },
|
|
233
|
+
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
|
|
234
|
+
ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
|
|
235
|
+
ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" },
|
|
236
|
+
ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" },
|
|
237
|
+
ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" },
|
|
238
|
+
BraveHTML: { name: "Brave", id: "com.brave.Browser" },
|
|
239
|
+
BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
|
|
240
|
+
BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" },
|
|
241
|
+
BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" },
|
|
242
|
+
FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
|
|
243
|
+
OperaStable: { name: "Opera", id: "com.operasoftware.Opera" },
|
|
244
|
+
VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" },
|
|
245
|
+
"IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" }
|
|
246
|
+
};
|
|
247
|
+
var _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
|
|
248
|
+
var UnknownBrowserError = class extends Error {
|
|
249
|
+
};
|
|
250
|
+
async function defaultBrowser(_execFileAsync = execFileAsync3) {
|
|
251
|
+
const { stdout } = await _execFileAsync("reg", [
|
|
252
|
+
"QUERY",
|
|
253
|
+
" HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
|
|
254
|
+
"/v",
|
|
255
|
+
"ProgId"
|
|
256
|
+
]);
|
|
257
|
+
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
258
|
+
if (!match) {
|
|
259
|
+
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
260
|
+
}
|
|
261
|
+
const { id } = match.groups;
|
|
262
|
+
const dotIndex = id.lastIndexOf(".");
|
|
263
|
+
const hyphenIndex = id.lastIndexOf("-");
|
|
264
|
+
const baseIdByDot = dotIndex === -1 ? void 0 : id.slice(0, dotIndex);
|
|
265
|
+
const baseIdByHyphen = hyphenIndex === -1 ? void 0 : id.slice(0, hyphenIndex);
|
|
266
|
+
return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? { name: id, id };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// node_modules/default-browser/index.js
|
|
270
|
+
var execFileAsync4 = (0, import_node_util4.promisify)(import_node_child_process4.execFile);
|
|
271
|
+
var titleize = (string) => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
|
|
272
|
+
async function defaultBrowser2() {
|
|
273
|
+
if (import_node_process5.default.platform === "darwin") {
|
|
274
|
+
const id = await defaultBrowserId();
|
|
275
|
+
const name = await bundleName(id);
|
|
276
|
+
return { name, id };
|
|
277
|
+
}
|
|
278
|
+
if (import_node_process5.default.platform === "linux") {
|
|
279
|
+
const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
|
|
280
|
+
const id = stdout.trim();
|
|
281
|
+
const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
|
|
282
|
+
return { name, id };
|
|
283
|
+
}
|
|
284
|
+
if (import_node_process5.default.platform === "win32") {
|
|
285
|
+
return defaultBrowser();
|
|
286
|
+
}
|
|
287
|
+
throw new Error("Only macOS, Linux, and Windows are supported");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// node_modules/open/index.js
|
|
291
|
+
var import_meta = {};
|
|
292
|
+
var execFile5 = (0, import_node_util5.promisify)(import_node_child_process5.default.execFile);
|
|
293
|
+
var __dirname = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
294
|
+
var localXdgOpenPath = import_node_path.default.join(__dirname, "xdg-open");
|
|
295
|
+
var { platform, arch } = import_node_process6.default;
|
|
296
|
+
async function getWindowsDefaultBrowserFromWsl() {
|
|
297
|
+
const powershellPath = await powerShellPath();
|
|
298
|
+
const rawCommand = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
299
|
+
const encodedCommand = import_node_buffer.Buffer.from(rawCommand, "utf16le").toString("base64");
|
|
300
|
+
const { stdout } = await execFile5(
|
|
301
|
+
powershellPath,
|
|
302
|
+
[
|
|
303
|
+
"-NoProfile",
|
|
304
|
+
"-NonInteractive",
|
|
305
|
+
"-ExecutionPolicy",
|
|
306
|
+
"Bypass",
|
|
307
|
+
"-EncodedCommand",
|
|
308
|
+
encodedCommand
|
|
309
|
+
],
|
|
310
|
+
{ encoding: "utf8" }
|
|
311
|
+
);
|
|
312
|
+
const progId = stdout.trim();
|
|
313
|
+
const browserMap = {
|
|
314
|
+
ChromeHTML: "com.google.chrome",
|
|
315
|
+
BraveHTML: "com.brave.Browser",
|
|
316
|
+
MSEdgeHTM: "com.microsoft.edge",
|
|
317
|
+
FirefoxURL: "org.mozilla.firefox"
|
|
318
|
+
};
|
|
319
|
+
return browserMap[progId] ? { id: browserMap[progId] } : {};
|
|
320
|
+
}
|
|
321
|
+
var pTryEach = async (array, mapper) => {
|
|
322
|
+
let latestError;
|
|
323
|
+
for (const item of array) {
|
|
324
|
+
try {
|
|
325
|
+
return await mapper(item);
|
|
326
|
+
} catch (error) {
|
|
327
|
+
latestError = error;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
throw latestError;
|
|
331
|
+
};
|
|
332
|
+
var baseOpen = async (options) => {
|
|
333
|
+
options = {
|
|
334
|
+
wait: false,
|
|
335
|
+
background: false,
|
|
336
|
+
newInstance: false,
|
|
337
|
+
allowNonzeroExitCode: false,
|
|
338
|
+
...options
|
|
339
|
+
};
|
|
340
|
+
if (Array.isArray(options.app)) {
|
|
341
|
+
return pTryEach(options.app, (singleApp) => baseOpen({
|
|
342
|
+
...options,
|
|
343
|
+
app: singleApp
|
|
344
|
+
}));
|
|
345
|
+
}
|
|
346
|
+
let { name: app, arguments: appArguments = [] } = options.app ?? {};
|
|
347
|
+
appArguments = [...appArguments];
|
|
348
|
+
if (Array.isArray(app)) {
|
|
349
|
+
return pTryEach(app, (appName) => baseOpen({
|
|
350
|
+
...options,
|
|
351
|
+
app: {
|
|
352
|
+
name: appName,
|
|
353
|
+
arguments: appArguments
|
|
354
|
+
}
|
|
355
|
+
}));
|
|
356
|
+
}
|
|
357
|
+
if (app === "browser" || app === "browserPrivate") {
|
|
358
|
+
const ids = {
|
|
359
|
+
"com.google.chrome": "chrome",
|
|
360
|
+
"google-chrome.desktop": "chrome",
|
|
361
|
+
"com.brave.Browser": "brave",
|
|
362
|
+
"org.mozilla.firefox": "firefox",
|
|
363
|
+
"firefox.desktop": "firefox",
|
|
364
|
+
"com.microsoft.msedge": "edge",
|
|
365
|
+
"com.microsoft.edge": "edge",
|
|
366
|
+
"com.microsoft.edgemac": "edge",
|
|
367
|
+
"microsoft-edge.desktop": "edge"
|
|
368
|
+
};
|
|
369
|
+
const flags = {
|
|
370
|
+
chrome: "--incognito",
|
|
371
|
+
brave: "--incognito",
|
|
372
|
+
firefox: "--private-window",
|
|
373
|
+
edge: "--inPrivate"
|
|
374
|
+
};
|
|
375
|
+
const browser = is_wsl_default ? await getWindowsDefaultBrowserFromWsl() : await defaultBrowser2();
|
|
376
|
+
if (browser.id in ids) {
|
|
377
|
+
const browserName = ids[browser.id];
|
|
378
|
+
if (app === "browserPrivate") {
|
|
379
|
+
appArguments.push(flags[browserName]);
|
|
380
|
+
}
|
|
381
|
+
return baseOpen({
|
|
382
|
+
...options,
|
|
383
|
+
app: {
|
|
384
|
+
name: apps[browserName],
|
|
385
|
+
arguments: appArguments
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
throw new Error(`${browser.name} is not supported as a default browser`);
|
|
390
|
+
}
|
|
391
|
+
let command;
|
|
392
|
+
const cliArguments = [];
|
|
393
|
+
const childProcessOptions = {};
|
|
394
|
+
if (platform === "darwin") {
|
|
395
|
+
command = "open";
|
|
396
|
+
if (options.wait) {
|
|
397
|
+
cliArguments.push("--wait-apps");
|
|
398
|
+
}
|
|
399
|
+
if (options.background) {
|
|
400
|
+
cliArguments.push("--background");
|
|
401
|
+
}
|
|
402
|
+
if (options.newInstance) {
|
|
403
|
+
cliArguments.push("--new");
|
|
404
|
+
}
|
|
405
|
+
if (app) {
|
|
406
|
+
cliArguments.push("-a", app);
|
|
407
|
+
}
|
|
408
|
+
} else if (platform === "win32" || is_wsl_default && !isInsideContainer() && !app) {
|
|
409
|
+
command = await powerShellPath();
|
|
410
|
+
cliArguments.push(
|
|
411
|
+
"-NoProfile",
|
|
412
|
+
"-NonInteractive",
|
|
413
|
+
"-ExecutionPolicy",
|
|
414
|
+
"Bypass",
|
|
415
|
+
"-EncodedCommand"
|
|
416
|
+
);
|
|
417
|
+
if (!is_wsl_default) {
|
|
418
|
+
childProcessOptions.windowsVerbatimArguments = true;
|
|
419
|
+
}
|
|
420
|
+
const encodedArguments = ["Start"];
|
|
421
|
+
if (options.wait) {
|
|
422
|
+
encodedArguments.push("-Wait");
|
|
423
|
+
}
|
|
424
|
+
if (app) {
|
|
425
|
+
encodedArguments.push(`"\`"${app}\`""`);
|
|
426
|
+
if (options.target) {
|
|
427
|
+
appArguments.push(options.target);
|
|
428
|
+
}
|
|
429
|
+
} else if (options.target) {
|
|
430
|
+
encodedArguments.push(`"${options.target}"`);
|
|
431
|
+
}
|
|
432
|
+
if (appArguments.length > 0) {
|
|
433
|
+
appArguments = appArguments.map((argument) => `"\`"${argument}\`""`);
|
|
434
|
+
encodedArguments.push("-ArgumentList", appArguments.join(","));
|
|
435
|
+
}
|
|
436
|
+
options.target = import_node_buffer.Buffer.from(encodedArguments.join(" "), "utf16le").toString("base64");
|
|
437
|
+
} else {
|
|
438
|
+
if (app) {
|
|
439
|
+
command = app;
|
|
440
|
+
} else {
|
|
441
|
+
const isBundled = !__dirname || __dirname === "/";
|
|
442
|
+
let exeLocalXdgOpen = false;
|
|
443
|
+
try {
|
|
444
|
+
await import_promises2.default.access(localXdgOpenPath, import_promises2.constants.X_OK);
|
|
445
|
+
exeLocalXdgOpen = true;
|
|
446
|
+
} catch {
|
|
447
|
+
}
|
|
448
|
+
const useSystemXdgOpen = import_node_process6.default.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
|
|
449
|
+
command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
|
|
450
|
+
}
|
|
451
|
+
if (appArguments.length > 0) {
|
|
452
|
+
cliArguments.push(...appArguments);
|
|
453
|
+
}
|
|
454
|
+
if (!options.wait) {
|
|
455
|
+
childProcessOptions.stdio = "ignore";
|
|
456
|
+
childProcessOptions.detached = true;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
if (platform === "darwin" && appArguments.length > 0) {
|
|
460
|
+
cliArguments.push("--args", ...appArguments);
|
|
461
|
+
}
|
|
462
|
+
if (options.target) {
|
|
463
|
+
cliArguments.push(options.target);
|
|
464
|
+
}
|
|
465
|
+
const subprocess = import_node_child_process5.default.spawn(command, cliArguments, childProcessOptions);
|
|
466
|
+
if (options.wait) {
|
|
467
|
+
return new Promise((resolve, reject) => {
|
|
468
|
+
subprocess.once("error", reject);
|
|
469
|
+
subprocess.once("close", (exitCode) => {
|
|
470
|
+
if (!options.allowNonzeroExitCode && exitCode > 0) {
|
|
471
|
+
reject(new Error(`Exited with code ${exitCode}`));
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
resolve(subprocess);
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
subprocess.unref();
|
|
479
|
+
return subprocess;
|
|
480
|
+
};
|
|
481
|
+
var open = (target, options) => {
|
|
482
|
+
if (typeof target !== "string") {
|
|
483
|
+
throw new TypeError("Expected a `target`");
|
|
484
|
+
}
|
|
485
|
+
return baseOpen({
|
|
486
|
+
...options,
|
|
487
|
+
target
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
function detectArchBinary(binary) {
|
|
491
|
+
if (typeof binary === "string" || Array.isArray(binary)) {
|
|
492
|
+
return binary;
|
|
493
|
+
}
|
|
494
|
+
const { [arch]: archBinary } = binary;
|
|
495
|
+
if (!archBinary) {
|
|
496
|
+
throw new Error(`${arch} is not supported`);
|
|
497
|
+
}
|
|
498
|
+
return archBinary;
|
|
499
|
+
}
|
|
500
|
+
function detectPlatformBinary({ [platform]: platformBinary }, { wsl }) {
|
|
501
|
+
if (wsl && is_wsl_default) {
|
|
502
|
+
return detectArchBinary(wsl);
|
|
503
|
+
}
|
|
504
|
+
if (!platformBinary) {
|
|
505
|
+
throw new Error(`${platform} is not supported`);
|
|
506
|
+
}
|
|
507
|
+
return detectArchBinary(platformBinary);
|
|
508
|
+
}
|
|
509
|
+
var apps = {};
|
|
510
|
+
defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
|
|
511
|
+
darwin: "google chrome",
|
|
512
|
+
win32: "chrome",
|
|
513
|
+
linux: ["google-chrome", "google-chrome-stable", "chromium"]
|
|
514
|
+
}, {
|
|
515
|
+
wsl: {
|
|
516
|
+
ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
|
|
517
|
+
x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
|
|
518
|
+
}
|
|
519
|
+
}));
|
|
520
|
+
defineLazyProperty(apps, "brave", () => detectPlatformBinary({
|
|
521
|
+
darwin: "brave browser",
|
|
522
|
+
win32: "brave",
|
|
523
|
+
linux: ["brave-browser", "brave"]
|
|
524
|
+
}, {
|
|
525
|
+
wsl: {
|
|
526
|
+
ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
|
|
527
|
+
x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
|
|
528
|
+
}
|
|
529
|
+
}));
|
|
530
|
+
defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
|
|
531
|
+
darwin: "firefox",
|
|
532
|
+
win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
|
|
533
|
+
linux: "firefox"
|
|
534
|
+
}, {
|
|
535
|
+
wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
|
|
536
|
+
}));
|
|
537
|
+
defineLazyProperty(apps, "edge", () => detectPlatformBinary({
|
|
538
|
+
darwin: "microsoft edge",
|
|
539
|
+
win32: "msedge",
|
|
540
|
+
linux: ["microsoft-edge", "microsoft-edge-dev"]
|
|
541
|
+
}, {
|
|
542
|
+
wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
|
|
543
|
+
}));
|
|
544
|
+
defineLazyProperty(apps, "browser", () => "browser");
|
|
545
|
+
defineLazyProperty(apps, "browserPrivate", () => "browserPrivate");
|
|
546
|
+
var open_default = open;
|
|
28
547
|
|
|
29
548
|
// src/validate.ts
|
|
30
549
|
function validateMoodUISpec(input) {
|
|
@@ -48,21 +567,21 @@ function assertMoodUISpec(input) {
|
|
|
48
567
|
}
|
|
49
568
|
return result.value;
|
|
50
569
|
}
|
|
51
|
-
function validateNode(input,
|
|
570
|
+
function validateNode(input, path3) {
|
|
52
571
|
const errors = [];
|
|
53
|
-
if (!isObject(input)) return { ok: false, errors: [`${
|
|
572
|
+
if (!isObject(input)) return { ok: false, errors: [`${path3} must be an object`] };
|
|
54
573
|
const type = input.type;
|
|
55
|
-
if (!isString(type)) return { ok: false, errors: [`${
|
|
574
|
+
if (!isString(type)) return { ok: false, errors: [`${path3}.type must be a string`] };
|
|
56
575
|
switch (type) {
|
|
57
576
|
case "box": {
|
|
58
577
|
const children = input.children;
|
|
59
578
|
if (children != null) {
|
|
60
579
|
if (!Array.isArray(children)) {
|
|
61
|
-
errors.push(`${
|
|
580
|
+
errors.push(`${path3}.children must be an array`);
|
|
62
581
|
} else {
|
|
63
582
|
for (let i = 0; i < children.length; i += 1) {
|
|
64
583
|
const child = children[i];
|
|
65
|
-
const childResult = validateNode(child, `${
|
|
584
|
+
const childResult = validateNode(child, `${path3}.children[${i}]`);
|
|
66
585
|
if (!childResult.ok) errors.push(...childResult.errors);
|
|
67
586
|
}
|
|
68
587
|
}
|
|
@@ -71,34 +590,34 @@ function validateNode(input, path2) {
|
|
|
71
590
|
}
|
|
72
591
|
case "text": {
|
|
73
592
|
const props = input.props;
|
|
74
|
-
if (!isObject(props)) errors.push(`${
|
|
75
|
-
else if (!isString(props.value)) errors.push(`${
|
|
593
|
+
if (!isObject(props)) errors.push(`${path3}.props must be an object`);
|
|
594
|
+
else if (!isString(props.value)) errors.push(`${path3}.props.value must be a string`);
|
|
76
595
|
break;
|
|
77
596
|
}
|
|
78
597
|
case "button": {
|
|
79
598
|
const props = input.props;
|
|
80
|
-
if (!isObject(props)) errors.push(`${
|
|
81
|
-
else if (!isString(props.label)) errors.push(`${
|
|
599
|
+
if (!isObject(props)) errors.push(`${path3}.props must be an object`);
|
|
600
|
+
else if (!isString(props.label)) errors.push(`${path3}.props.label must be a string`);
|
|
82
601
|
break;
|
|
83
602
|
}
|
|
84
603
|
case "input": {
|
|
85
604
|
const props = input.props;
|
|
86
|
-
if (props != null && !isObject(props)) errors.push(`${
|
|
605
|
+
if (props != null && !isObject(props)) errors.push(`${path3}.props must be an object if provided`);
|
|
87
606
|
break;
|
|
88
607
|
}
|
|
89
608
|
case "image": {
|
|
90
609
|
const props = input.props;
|
|
91
|
-
if (!isObject(props)) errors.push(`${
|
|
92
|
-
else if (!isString(props.src)) errors.push(`${
|
|
610
|
+
if (!isObject(props)) errors.push(`${path3}.props must be an object`);
|
|
611
|
+
else if (!isString(props.src)) errors.push(`${path3}.props.src must be a string`);
|
|
93
612
|
break;
|
|
94
613
|
}
|
|
95
614
|
case "spacer": {
|
|
96
615
|
const props = input.props;
|
|
97
|
-
if (props != null && !isObject(props)) errors.push(`${
|
|
616
|
+
if (props != null && !isObject(props)) errors.push(`${path3}.props must be an object if provided`);
|
|
98
617
|
break;
|
|
99
618
|
}
|
|
100
619
|
default:
|
|
101
|
-
errors.push(`${
|
|
620
|
+
errors.push(`${path3}.type must be one of: box | text | button | input | image | spacer`);
|
|
102
621
|
}
|
|
103
622
|
if (errors.length > 0) return { ok: false, errors };
|
|
104
623
|
return { ok: true, value: input };
|
|
@@ -280,11 +799,11 @@ function renderNode(node, ctx) {
|
|
|
280
799
|
function renderElement(tag, node, ctx, renderChildren, extraProps) {
|
|
281
800
|
const children = renderChildren();
|
|
282
801
|
const propParts = buildProps(tag, node, extraProps);
|
|
283
|
-
const
|
|
802
|
+
const open2 = `<${tag}${propParts.length ? " " + propParts.join(" ") : ""}>`;
|
|
284
803
|
const close = `</${tag}>`;
|
|
285
|
-
if (children.length === 0) return indent(ctx.indent) +
|
|
804
|
+
if (children.length === 0) return indent(ctx.indent) + open2 + close;
|
|
286
805
|
return [
|
|
287
|
-
indent(ctx.indent) +
|
|
806
|
+
indent(ctx.indent) + open2,
|
|
288
807
|
...children,
|
|
289
808
|
indent(ctx.indent) + close
|
|
290
809
|
].join("\n");
|
|
@@ -583,6 +1102,8 @@ async function generateReactFromPrompt(options) {
|
|
|
583
1102
|
}
|
|
584
1103
|
|
|
585
1104
|
// src/cli.ts
|
|
1105
|
+
var import_meta2 = {};
|
|
1106
|
+
var __dirname2 = import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url));
|
|
586
1107
|
async function main() {
|
|
587
1108
|
const argv = process.argv.slice(2);
|
|
588
1109
|
const command = argv[0] ?? "help";
|
|
@@ -590,6 +1111,10 @@ async function main() {
|
|
|
590
1111
|
printHelp();
|
|
591
1112
|
return;
|
|
592
1113
|
}
|
|
1114
|
+
if (command === "ui") {
|
|
1115
|
+
await runUI();
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
593
1118
|
if (command !== "generate") {
|
|
594
1119
|
console.error(`Unknown command: ${command}`);
|
|
595
1120
|
printHelp();
|
|
@@ -652,17 +1177,65 @@ async function main() {
|
|
|
652
1177
|
temperature,
|
|
653
1178
|
maxAttempts
|
|
654
1179
|
});
|
|
655
|
-
const resolvedOut =
|
|
656
|
-
await
|
|
657
|
-
await
|
|
1180
|
+
const resolvedOut = import_node_path2.default.resolve(process.cwd(), outFile);
|
|
1181
|
+
await import_promises3.default.mkdir(import_node_path2.default.dirname(resolvedOut), { recursive: true });
|
|
1182
|
+
await import_promises3.default.writeFile(resolvedOut, result.code, "utf8");
|
|
658
1183
|
console.log(`OK: wrote ${resolvedOut}`);
|
|
659
1184
|
}
|
|
1185
|
+
async function runUI() {
|
|
1186
|
+
let uiDir = import_node_path2.default.join(__dirname2, "ui");
|
|
1187
|
+
try {
|
|
1188
|
+
await import_promises3.default.access(uiDir);
|
|
1189
|
+
} catch {
|
|
1190
|
+
uiDir = import_node_path2.default.join(__dirname2, "..", "dist", "ui");
|
|
1191
|
+
}
|
|
1192
|
+
const PORT = 3e3;
|
|
1193
|
+
console.log(`Starting MoodUI UI...`);
|
|
1194
|
+
const server = import_node_http.default.createServer(async (req, res) => {
|
|
1195
|
+
let filePath = import_node_path2.default.join(uiDir, req.url === "/" ? "index.html" : req.url);
|
|
1196
|
+
const extname = String(import_node_path2.default.extname(filePath)).toLowerCase();
|
|
1197
|
+
const mimeTypes = {
|
|
1198
|
+
".html": "text/html",
|
|
1199
|
+
".js": "text/javascript",
|
|
1200
|
+
".css": "text/css",
|
|
1201
|
+
".json": "application/json",
|
|
1202
|
+
".png": "image/png",
|
|
1203
|
+
".jpg": "image/jpg",
|
|
1204
|
+
".gif": "image/gif",
|
|
1205
|
+
".svg": "image/svg+xml",
|
|
1206
|
+
".ico": "image/x-icon"
|
|
1207
|
+
};
|
|
1208
|
+
const contentType = mimeTypes[extname] || "application/octet-stream";
|
|
1209
|
+
try {
|
|
1210
|
+
const content = await import_promises3.default.readFile(filePath);
|
|
1211
|
+
res.writeHead(200, { "Content-Type": contentType });
|
|
1212
|
+
res.end(content, "utf-8");
|
|
1213
|
+
} catch (err) {
|
|
1214
|
+
res.writeHead(404);
|
|
1215
|
+
res.end("Not Found", "utf-8");
|
|
1216
|
+
}
|
|
1217
|
+
});
|
|
1218
|
+
server.listen(PORT, () => {
|
|
1219
|
+
const url = `http://localhost:${PORT}`;
|
|
1220
|
+
console.log(`MoodUI UI running at ${url}`);
|
|
1221
|
+
open_default(url);
|
|
1222
|
+
});
|
|
1223
|
+
process.on("SIGINT", () => {
|
|
1224
|
+
server.close();
|
|
1225
|
+
process.exit(0);
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
660
1228
|
function printHelp() {
|
|
661
1229
|
console.log(
|
|
662
1230
|
[
|
|
663
|
-
"moodui
|
|
1231
|
+
"moodui <command>",
|
|
664
1232
|
"",
|
|
665
|
-
"
|
|
1233
|
+
"Commands:",
|
|
1234
|
+
" generate [options] <prompt...> Generate component via CLI",
|
|
1235
|
+
" ui Launch Web UI for generating components",
|
|
1236
|
+
" help, --help, -h Show this help message",
|
|
1237
|
+
"",
|
|
1238
|
+
"Generate Options:",
|
|
666
1239
|
" --provider gemini|ollama|openai-compatible default: gemini",
|
|
667
1240
|
" --model <name> required (default for gemini: gemini-3-flash-preview)",
|
|
668
1241
|
" --out <path> path lengkap ke file output (termasuk direktori), default: src/generated/MoodScreen.tsx",
|
|
@@ -678,6 +1251,9 @@ function printHelp() {
|
|
|
678
1251
|
" OPENAI_COMPATIBLE_API_KEY",
|
|
679
1252
|
"",
|
|
680
1253
|
"Examples:",
|
|
1254
|
+
" # Launch Web UI",
|
|
1255
|
+
" npx @kohryan/moodui ui",
|
|
1256
|
+
"",
|
|
681
1257
|
" # Generate ke src/generated/MoodScreen.tsx (default)",
|
|
682
1258
|
' GEMINI_API_KEY=... npx @kohryan/moodui generate --model gemini-3-flash-preview "Buat UI login sederhana"',
|
|
683
1259
|
"",
|