@myop/cli 0.1.56 → 0.1.57
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/myop-cli.js +948 -922
- package/package.json +1 -1
package/dist/myop-cli.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var bt = Object.defineProperty;
|
|
3
3
|
var Ct = (o, t, e) => t in o ? bt(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
4
|
-
var
|
|
5
|
-
import
|
|
6
|
-
import { select as
|
|
7
|
-
import { Command as
|
|
8
|
-
import { execSync as
|
|
9
|
-
import
|
|
4
|
+
var Se = (o, t, e) => Ct(o, typeof t != "symbol" ? t + "" : t, e);
|
|
5
|
+
import Y from "ora";
|
|
6
|
+
import { select as it, Separator as He } from "@inquirer/prompts";
|
|
7
|
+
import { Command as Mt, Option as ge } from "commander";
|
|
8
|
+
import { execSync as X, spawn as Pt } from "child_process";
|
|
9
|
+
import _, { join as De } from "path";
|
|
10
10
|
import P, { readFileSync as Et } from "fs";
|
|
11
|
-
import
|
|
11
|
+
import Ve from "crypto";
|
|
12
12
|
import It from "http";
|
|
13
|
-
import { URL as
|
|
13
|
+
import { URL as rt, URLSearchParams as at } from "url";
|
|
14
14
|
import Ot from "open";
|
|
15
|
-
import
|
|
16
|
-
const kt = "0.1.
|
|
15
|
+
import lt from "os";
|
|
16
|
+
const kt = "0.1.57", Rt = `
|
|
17
17
|
Usage: myop [OPTIONS] [COMMAND]
|
|
18
18
|
|
|
19
19
|
Myop CLI - Remote UI Made Easy
|
|
@@ -57,25 +57,25 @@ Examples:
|
|
|
57
57
|
verbose: !1
|
|
58
58
|
},
|
|
59
59
|
myopConfig: null
|
|
60
|
-
},
|
|
60
|
+
}, ct = {
|
|
61
61
|
name: "📥 Install Myop generated dependencies",
|
|
62
62
|
value: "myopInstall",
|
|
63
63
|
description: "Fetch and generates Myop dependencies. flows including components, refs and props.",
|
|
64
64
|
action: async () => {
|
|
65
65
|
console.info("installing... ");
|
|
66
66
|
for (const o of v.myopConfig.flows) {
|
|
67
|
-
const t =
|
|
67
|
+
const t = _.join(v.executionPath, "/node_modules/@myop/flow-types/");
|
|
68
68
|
console.info(`Generate flow at ${t}`), console.info(`Generated flow at ${t}`);
|
|
69
69
|
}
|
|
70
70
|
process.exit();
|
|
71
71
|
}
|
|
72
72
|
}, Nt = (o) => {
|
|
73
|
-
const t =
|
|
73
|
+
const t = _.join(v.executionPath, o);
|
|
74
74
|
console.info(`reading config file from: ${t}`);
|
|
75
75
|
const e = P.readFileSync(t, "utf8"), n = JSON.parse(e);
|
|
76
76
|
return console.info("config file loaded, ", n), n;
|
|
77
|
-
},
|
|
78
|
-
const e =
|
|
77
|
+
}, Ye = (o, t) => {
|
|
78
|
+
const e = _.join(v.executionPath, o);
|
|
79
79
|
console.info(`writing config file to: ${e}`);
|
|
80
80
|
try {
|
|
81
81
|
const n = JSON.stringify(t, null, 2);
|
|
@@ -84,21 +84,21 @@ Examples:
|
|
|
84
84
|
throw console.info(`error ${n} while writing to ${e}, JSON: ${t}`), console.log(`
|
|
85
85
|
⚠️ Failed write config file to ${e}, for more info use verbose flag`), n;
|
|
86
86
|
}
|
|
87
|
-
},
|
|
87
|
+
}, dt = {
|
|
88
88
|
name: "🌟 Add flow definition to your project",
|
|
89
89
|
value: "addFlow",
|
|
90
90
|
description: "Adds flow to yours myop.config.json",
|
|
91
91
|
_action: (o) => {
|
|
92
|
-
v.myopConfig.flows.includes(o) || v.myopConfig.flows.push(o),
|
|
92
|
+
v.myopConfig.flows.includes(o) || v.myopConfig.flows.push(o), Ye(v.options.configPath, v.myopConfig);
|
|
93
93
|
},
|
|
94
94
|
action: async () => {
|
|
95
95
|
}
|
|
96
|
-
},
|
|
96
|
+
}, pt = {
|
|
97
97
|
name: "🚫 Remove flow definition from your project",
|
|
98
98
|
value: "removeFlow",
|
|
99
99
|
description: "Removes flow to yours myop.config.json",
|
|
100
100
|
_action: (o) => {
|
|
101
|
-
v.myopConfig.flows = v.myopConfig.flows.filter((t) => t !== o),
|
|
101
|
+
v.myopConfig.flows = v.myopConfig.flows.filter((t) => t !== o), Ye(v.options.configPath, v.myopConfig);
|
|
102
102
|
},
|
|
103
103
|
action: () => {
|
|
104
104
|
}
|
|
@@ -246,7 +246,7 @@ function zt(o) {
|
|
|
246
246
|
return;
|
|
247
247
|
}
|
|
248
248
|
console.log(" ✓ Removed node_modules"), console.log(` ⏳ Running npm install...
|
|
249
|
-
`), o("npm install", { maxBuffer: 10 * 1024 * 1024 }, (i,
|
|
249
|
+
`), o("npm install", { maxBuffer: 10 * 1024 * 1024 }, (i, a, p) => {
|
|
250
250
|
if (i) {
|
|
251
251
|
console.error("❌ npm install failed:", i.message), p && console.error(p), t(!1);
|
|
252
252
|
return;
|
|
@@ -257,101 +257,101 @@ function zt(o) {
|
|
|
257
257
|
});
|
|
258
258
|
});
|
|
259
259
|
}
|
|
260
|
-
async function
|
|
260
|
+
async function mt(o, t, e, n, s = {}) {
|
|
261
261
|
const {
|
|
262
262
|
hasTriedPlatformFix: i = !1,
|
|
263
|
-
hasTriedInstall:
|
|
263
|
+
hasTriedInstall: a = !1,
|
|
264
264
|
onRetry: p
|
|
265
265
|
} = s, m = ((o == null ? void 0 : o.message) || "") + (t || "") + (e || "");
|
|
266
266
|
return !i && Ht(m) ? (Jt(), await zt(n) && p ? (console.log(`🔄 Retrying build...
|
|
267
|
-
`), p(), { handled: !0, hasTriedPlatformFix: !0, hasTriedInstall:
|
|
268
|
-
n("npm install", (
|
|
269
|
-
if (
|
|
270
|
-
console.error("❌ Failed to install dependencies:",
|
|
267
|
+
`), p(), { handled: !0, hasTriedPlatformFix: !0, hasTriedInstall: a }) : { handled: !0, hasTriedPlatformFix: !0, hasTriedInstall: a }) : !a && Bt(m) ? (console.log("📦 Missing dependencies detected, running npm install..."), new Promise((r) => {
|
|
268
|
+
n("npm install", (c, y, S) => {
|
|
269
|
+
if (c) {
|
|
270
|
+
console.error("❌ Failed to install dependencies:", c.message), S && console.error(S), r({ handled: !0, hasTriedPlatformFix: i, hasTriedInstall: !0 });
|
|
271
271
|
return;
|
|
272
272
|
}
|
|
273
|
-
console.log("✅ Dependencies installed"), p && p(),
|
|
273
|
+
console.log("✅ Dependencies installed"), p && p(), r({ handled: !0, hasTriedPlatformFix: i, hasTriedInstall: !0 });
|
|
274
274
|
});
|
|
275
|
-
})) : { handled: !1, hasTriedPlatformFix: i, hasTriedInstall:
|
|
275
|
+
})) : { handled: !1, hasTriedPlatformFix: i, hasTriedInstall: a };
|
|
276
276
|
}
|
|
277
|
-
async function
|
|
277
|
+
async function Me() {
|
|
278
278
|
const o = await import("fs"), t = await import("path"), { exec: e } = await import("child_process"), n = await import("http"), { createHash: s } = await import("node:crypto");
|
|
279
279
|
let i;
|
|
280
280
|
if (import.meta.url.startsWith("file://")) {
|
|
281
|
-
const
|
|
281
|
+
const l = new URL(import.meta.url).pathname, f = process.platform === "win32" && l.startsWith("/") ? l.slice(1) : l;
|
|
282
282
|
i = t.default.dirname(f);
|
|
283
283
|
} else
|
|
284
284
|
i = t.default.dirname(import.meta.url);
|
|
285
|
-
const
|
|
286
|
-
let
|
|
285
|
+
const a = t.default.join(i, "commands", "dev", "management-website"), p = o.default.readFileSync(t.default.join(a, "styles.css"), "utf-8"), m = o.default.readFileSync(t.default.join(a, "app.js"), "utf-8"), r = 9292, c = 9293;
|
|
286
|
+
let y = "./dist", S = !1, $ = !1, h = !1, u = null;
|
|
287
287
|
const E = () => {
|
|
288
288
|
try {
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
291
|
-
return
|
|
289
|
+
const d = o.default.readdirSync(".").filter((l) => !l.endsWith(".html") || l.startsWith(".") ? !1 : o.default.statSync(l).isFile());
|
|
290
|
+
if (d.length === 1)
|
|
291
|
+
return d[0];
|
|
292
292
|
} catch {
|
|
293
293
|
}
|
|
294
294
|
return null;
|
|
295
|
-
},
|
|
295
|
+
}, k = () => {
|
|
296
296
|
try {
|
|
297
|
-
const
|
|
298
|
-
return !!(
|
|
297
|
+
const d = JSON.parse(o.default.readFileSync("package.json", "utf-8"));
|
|
298
|
+
return !!(d.scripts && d.scripts.build);
|
|
299
299
|
} catch {
|
|
300
300
|
return !1;
|
|
301
301
|
}
|
|
302
|
-
},
|
|
303
|
-
const
|
|
302
|
+
}, C = (d) => {
|
|
303
|
+
const l = process.platform;
|
|
304
304
|
let f;
|
|
305
|
-
|
|
305
|
+
l === "darwin" ? f = `open "${d}"` : l === "win32" ? f = `start "" "${d}"` : f = `xdg-open "${d}"`, e(f, (g) => {
|
|
306
306
|
});
|
|
307
|
-
},
|
|
308
|
-
let
|
|
307
|
+
}, b = /* @__PURE__ */ new Map(), A = v.program.getOptionValue("config") || "./myop.config.json";
|
|
308
|
+
let M, N, R = !1;
|
|
309
309
|
u = E();
|
|
310
|
-
const
|
|
310
|
+
const U = k();
|
|
311
311
|
try {
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
} catch (
|
|
315
|
-
u && !
|
|
312
|
+
const d = o.default.readFileSync(A, "utf-8"), l = JSON.parse(d);
|
|
313
|
+
M = l.componentId || "DEV", N = l.componentName || l.name || null, R = l.HMR === !0, u && !U && (h = !0, R = !0, console.log(`📄 Single HTML file mode: ${u}`)), R && console.log("🔥 HMR enabled");
|
|
314
|
+
} catch (d) {
|
|
315
|
+
u && !U ? (h = !0, M = "DEV", N = t.default.basename(u, ".html"), R = !0, console.log(`📄 Single HTML file mode: ${u}`), console.log("🔥 HMR enabled")) : (console.error("❌ Error reading myop.config.json:", d.message), process.exit(1));
|
|
316
316
|
}
|
|
317
317
|
const D = async () => {
|
|
318
|
-
if (
|
|
319
|
-
return
|
|
318
|
+
if (M !== "DEV" && M !== "NEW")
|
|
319
|
+
return M;
|
|
320
320
|
try {
|
|
321
|
-
const
|
|
321
|
+
const l = ((await new Promise((w, x) => {
|
|
322
322
|
const I = {
|
|
323
323
|
hostname: "localhost",
|
|
324
|
-
port:
|
|
324
|
+
port: c,
|
|
325
325
|
path: "/_list",
|
|
326
326
|
method: "GET",
|
|
327
327
|
timeout: 1e3
|
|
328
|
-
},
|
|
329
|
-
let
|
|
330
|
-
|
|
328
|
+
}, j = n.default.request(I, (B) => {
|
|
329
|
+
let K = "";
|
|
330
|
+
B.on("data", (ne) => K += ne), B.on("end", () => {
|
|
331
331
|
try {
|
|
332
|
-
|
|
332
|
+
w(JSON.parse(K));
|
|
333
333
|
} catch {
|
|
334
|
-
|
|
334
|
+
w({ components: [] });
|
|
335
335
|
}
|
|
336
336
|
});
|
|
337
337
|
});
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}),
|
|
341
|
-
})).components || []).map(([
|
|
342
|
-
if (
|
|
338
|
+
j.on("error", () => w({ components: [] })), j.on("timeout", () => {
|
|
339
|
+
j.destroy(), w({ components: [] });
|
|
340
|
+
}), j.end();
|
|
341
|
+
})).components || []).map(([w]) => w).filter((w) => w === "DEV" || w === "NEW" || /^DEV\d+$/.test(w) || /^NEW\d+$/.test(w));
|
|
342
|
+
if (l.length === 0)
|
|
343
343
|
return "DEV1";
|
|
344
|
-
const f =
|
|
345
|
-
if (
|
|
346
|
-
const
|
|
347
|
-
return
|
|
348
|
-
}).filter((
|
|
344
|
+
const f = l.map((w) => {
|
|
345
|
+
if (w === "DEV" || w === "NEW") return 1;
|
|
346
|
+
const x = w.match(/^DEV(\d+)$/), I = w.match(/^NEW(\d+)$/);
|
|
347
|
+
return x ? parseInt(x[1], 10) : I ? parseInt(I[1], 10) : 0;
|
|
348
|
+
}).filter((w) => w > 0);
|
|
349
349
|
return `DEV${Math.max(...f, 0) + 1}`;
|
|
350
350
|
} catch {
|
|
351
351
|
return "DEV1";
|
|
352
352
|
}
|
|
353
|
-
}, F = process.cwd(),
|
|
354
|
-
const
|
|
353
|
+
}, F = process.cwd(), T = (d) => {
|
|
354
|
+
const l = t.default.extname(d).toLowerCase();
|
|
355
355
|
return {
|
|
356
356
|
".html": "text/html",
|
|
357
357
|
".js": "text/javascript",
|
|
@@ -362,336 +362,336 @@ async function Ce() {
|
|
|
362
362
|
".gif": "image/gif",
|
|
363
363
|
".svg": "image/svg+xml",
|
|
364
364
|
".ico": "image/x-icon"
|
|
365
|
-
}[
|
|
366
|
-
},
|
|
367
|
-
if (
|
|
368
|
-
const
|
|
369
|
-
|
|
365
|
+
}[l] || "application/octet-stream";
|
|
366
|
+
}, O = /* @__PURE__ */ new Map(), z = [], ee = 50, W = [], oe = /* @__PURE__ */ new Map(), Q = /* @__PURE__ */ new Map(), Oe = (d, l, f) => {
|
|
367
|
+
if (d.url.startsWith("/_hmr/")) {
|
|
368
|
+
const g = d.url.split("/_hmr/")[1], w = d.headers["sec-websocket-key"], x = s("sha1").update(w + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
|
|
369
|
+
l.write(
|
|
370
370
|
`HTTP/1.1 101 Switching Protocols\r
|
|
371
371
|
Upgrade: websocket\r
|
|
372
372
|
Connection: Upgrade\r
|
|
373
|
-
Sec-WebSocket-Accept: ${
|
|
373
|
+
Sec-WebSocket-Accept: ${x}\r
|
|
374
374
|
\r
|
|
375
375
|
`
|
|
376
|
-
),
|
|
377
|
-
const I =
|
|
378
|
-
I && (I.delete(
|
|
379
|
-
}),
|
|
380
|
-
const I =
|
|
381
|
-
I && I.delete(
|
|
376
|
+
), Q.has(g) || Q.set(g, /* @__PURE__ */ new Set()), Q.get(g).add(l), console.log(`🔌 HMR client connected: ${g}`), l.on("close", () => {
|
|
377
|
+
const I = Q.get(g);
|
|
378
|
+
I && (I.delete(l), I.size === 0 && Q.delete(g)), console.log(`🔌 HMR client disconnected: ${g}`);
|
|
379
|
+
}), l.on("error", () => {
|
|
380
|
+
const I = Q.get(g);
|
|
381
|
+
I && I.delete(l);
|
|
382
382
|
});
|
|
383
383
|
}
|
|
384
|
-
},
|
|
385
|
-
if (
|
|
384
|
+
}, ke = n.default.createServer((d, l) => {
|
|
385
|
+
if (l.setHeader("Content-Type", "application/json"), d.method === "POST" && d.url === "/_register") {
|
|
386
386
|
let f = "";
|
|
387
|
-
|
|
387
|
+
d.on("data", (g) => f += g), d.on("end", () => {
|
|
388
388
|
try {
|
|
389
|
-
const { componentId:
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
console.log(`✅ Registered: ${
|
|
393
|
-
const
|
|
394
|
-
id:
|
|
395
|
-
path:
|
|
396
|
-
name:
|
|
389
|
+
const { componentId: g, distPath: w, componentName: x, htmlFile: I } = JSON.parse(f);
|
|
390
|
+
O.set(g, { path: w, name: x || null, htmlFile: I || null });
|
|
391
|
+
const j = x ? ` (${x})` : "";
|
|
392
|
+
console.log(`✅ Registered: ${g}${j} -> ${w}${I ? "/" + I : ""}`), l.writeHead(200), l.end(JSON.stringify({ success: !0, registered: Array.from(O.keys()) }));
|
|
393
|
+
const B = Array.from(O.entries()).map(([K, ne]) => ({
|
|
394
|
+
id: K,
|
|
395
|
+
path: ne.path,
|
|
396
|
+
name: ne.name
|
|
397
397
|
}));
|
|
398
|
-
|
|
398
|
+
W.forEach((K) => {
|
|
399
399
|
try {
|
|
400
|
-
|
|
400
|
+
K.write(`data: ${JSON.stringify({
|
|
401
401
|
type: "components",
|
|
402
|
-
components:
|
|
402
|
+
components: B
|
|
403
403
|
})}
|
|
404
404
|
|
|
405
405
|
`);
|
|
406
406
|
} catch {
|
|
407
407
|
}
|
|
408
408
|
});
|
|
409
|
-
} catch (
|
|
410
|
-
|
|
409
|
+
} catch (g) {
|
|
410
|
+
l.writeHead(400), l.end(JSON.stringify({ error: g.message }));
|
|
411
411
|
}
|
|
412
412
|
});
|
|
413
|
-
} else if (
|
|
413
|
+
} else if (d.method === "POST" && d.url === "/_unregister") {
|
|
414
414
|
let f = "";
|
|
415
|
-
|
|
415
|
+
d.on("data", (g) => f += g), d.on("end", () => {
|
|
416
416
|
try {
|
|
417
|
-
const { componentId:
|
|
418
|
-
|
|
419
|
-
const
|
|
420
|
-
id:
|
|
417
|
+
const { componentId: g } = JSON.parse(f);
|
|
418
|
+
O.delete(g), console.log(`❌ Unregistered: ${g}`), l.writeHead(200), l.end(JSON.stringify({ success: !0 }));
|
|
419
|
+
const w = Array.from(O.entries()).map(([x, I]) => ({
|
|
420
|
+
id: x,
|
|
421
421
|
path: I.path,
|
|
422
422
|
name: I.name
|
|
423
423
|
}));
|
|
424
|
-
|
|
424
|
+
W.forEach((x) => {
|
|
425
425
|
try {
|
|
426
|
-
|
|
426
|
+
x.write(`data: ${JSON.stringify({
|
|
427
427
|
type: "components",
|
|
428
|
-
components:
|
|
428
|
+
components: w
|
|
429
429
|
})}
|
|
430
430
|
|
|
431
431
|
`);
|
|
432
432
|
} catch {
|
|
433
433
|
}
|
|
434
434
|
});
|
|
435
|
-
} catch (
|
|
436
|
-
|
|
435
|
+
} catch (g) {
|
|
436
|
+
l.writeHead(400), l.end(JSON.stringify({ error: g.message }));
|
|
437
437
|
}
|
|
438
438
|
});
|
|
439
|
-
} else if (
|
|
440
|
-
|
|
441
|
-
else if (
|
|
439
|
+
} else if (d.method === "GET" && d.url === "/_list")
|
|
440
|
+
l.writeHead(200), l.end(JSON.stringify({ components: Array.from(O.entries()) }));
|
|
441
|
+
else if (d.method === "POST" && d.url === "/_hmr_notify") {
|
|
442
442
|
let f = "";
|
|
443
|
-
|
|
443
|
+
d.on("data", (g) => f += g), d.on("end", () => {
|
|
444
444
|
try {
|
|
445
|
-
const { componentId:
|
|
446
|
-
if (
|
|
447
|
-
console.log(`🔥 Notifying ${
|
|
448
|
-
const I = JSON.stringify({ type: "update", html:
|
|
449
|
-
|
|
445
|
+
const { componentId: g, html: w } = JSON.parse(f), x = Q.get(g);
|
|
446
|
+
if (x && x.size > 0) {
|
|
447
|
+
console.log(`🔥 Notifying ${x.size} HMR client(s) for: ${g}`);
|
|
448
|
+
const I = JSON.stringify({ type: "update", html: w }), j = Xe(I);
|
|
449
|
+
x.forEach((B) => {
|
|
450
450
|
try {
|
|
451
|
-
|
|
451
|
+
B.write(j);
|
|
452
452
|
} catch {
|
|
453
|
-
|
|
453
|
+
x.delete(B);
|
|
454
454
|
}
|
|
455
|
-
}),
|
|
455
|
+
}), l.writeHead(200), l.end(JSON.stringify({ success: !0, notified: x.size }));
|
|
456
456
|
} else
|
|
457
|
-
|
|
458
|
-
} catch (
|
|
459
|
-
|
|
457
|
+
l.writeHead(200), l.end(JSON.stringify({ success: !0, notified: 0 }));
|
|
458
|
+
} catch (g) {
|
|
459
|
+
l.writeHead(400), l.end(JSON.stringify({ error: g.message }));
|
|
460
460
|
}
|
|
461
461
|
});
|
|
462
462
|
} else
|
|
463
|
-
|
|
464
|
-
}),
|
|
465
|
-
if (
|
|
466
|
-
|
|
463
|
+
l.writeHead(404), l.end(JSON.stringify({ error: "Not found" }));
|
|
464
|
+
}), he = n.default.createServer((d, l) => {
|
|
465
|
+
if (d.url.includes("..")) {
|
|
466
|
+
l.writeHead(403, { "Content-Type": "text/plain" }), l.end("Forbidden");
|
|
467
467
|
return;
|
|
468
468
|
}
|
|
469
|
-
const f = new URL(
|
|
470
|
-
if (
|
|
471
|
-
const
|
|
472
|
-
if (!
|
|
473
|
-
|
|
469
|
+
const f = new URL(d.url, `http://localhost:${r}`), g = f.pathname, w = g.split("/").filter((V) => V);
|
|
470
|
+
if (g.startsWith("/consume")) {
|
|
471
|
+
const V = f.searchParams.get("id");
|
|
472
|
+
if (!V) {
|
|
473
|
+
l.writeHead(400, { "Content-Type": "application/json" }), l.end(JSON.stringify({ error: "Component ID required. Use /consume?id=<componentId>" }));
|
|
474
474
|
return;
|
|
475
475
|
}
|
|
476
|
-
const
|
|
477
|
-
let
|
|
478
|
-
if (
|
|
479
|
-
const
|
|
476
|
+
const G = O.get(V), Z = G ? G.path : null, pe = (se) => {
|
|
477
|
+
let H = "Unknown", q = "Unknown";
|
|
478
|
+
if (d.headers.referer || d.headers.referrer) {
|
|
479
|
+
const J = d.headers.referer || d.headers.referrer;
|
|
480
480
|
try {
|
|
481
|
-
const
|
|
482
|
-
|
|
481
|
+
const re = new URL(J);
|
|
482
|
+
H = re.origin, q = re.hostname || re.origin;
|
|
483
483
|
} catch {
|
|
484
|
-
|
|
484
|
+
H = J, q = J;
|
|
485
485
|
}
|
|
486
|
-
} else if (
|
|
486
|
+
} else if (d.headers.origin)
|
|
487
487
|
try {
|
|
488
|
-
const
|
|
489
|
-
|
|
488
|
+
const J = new URL(d.headers.origin);
|
|
489
|
+
H = J.origin, q = J.hostname || J.origin;
|
|
490
490
|
} catch {
|
|
491
|
-
|
|
491
|
+
H = d.headers.origin, q = d.headers.origin;
|
|
492
492
|
}
|
|
493
|
-
else if (
|
|
494
|
-
const
|
|
495
|
-
|
|
493
|
+
else if (d.socket.remoteAddress) {
|
|
494
|
+
const J = d.socket.remoteAddress;
|
|
495
|
+
J === "::1" || J === "::ffff:127.0.0.1" ? (H = "localhost", q = "localhost (direct)") : (H = J, q = J.replace("::ffff:", ""));
|
|
496
496
|
}
|
|
497
|
-
const
|
|
497
|
+
const je = d.headers.referer || d.headers.referrer || H, ve = {
|
|
498
498
|
type: "request",
|
|
499
|
-
componentId:
|
|
499
|
+
componentId: V,
|
|
500
500
|
timestamp: Date.now(),
|
|
501
|
-
servedLocally:
|
|
502
|
-
referrer:
|
|
503
|
-
origin:
|
|
504
|
-
originLabel:
|
|
501
|
+
servedLocally: se,
|
|
502
|
+
referrer: je,
|
|
503
|
+
origin: H,
|
|
504
|
+
originLabel: q
|
|
505
505
|
};
|
|
506
|
-
|
|
507
|
-
url:
|
|
508
|
-
label:
|
|
506
|
+
oe.has(H) || (oe.set(H, {
|
|
507
|
+
url: H,
|
|
508
|
+
label: q,
|
|
509
509
|
firstSeen: Date.now(),
|
|
510
510
|
requestCount: 0
|
|
511
|
-
}),
|
|
511
|
+
}), W.forEach((J) => {
|
|
512
512
|
try {
|
|
513
|
-
|
|
513
|
+
J.write(`data: ${JSON.stringify({
|
|
514
514
|
type: "origins",
|
|
515
|
-
origins: Array.from(
|
|
515
|
+
origins: Array.from(oe.values())
|
|
516
516
|
})}
|
|
517
517
|
|
|
518
518
|
`);
|
|
519
519
|
} catch {
|
|
520
520
|
}
|
|
521
521
|
}));
|
|
522
|
-
const
|
|
523
|
-
|
|
522
|
+
const Ae = oe.get(H);
|
|
523
|
+
Ae.requestCount++, W.forEach((J) => {
|
|
524
524
|
try {
|
|
525
|
-
|
|
525
|
+
J.write(`data: ${JSON.stringify({
|
|
526
526
|
type: "origins",
|
|
527
|
-
origins: Array.from(
|
|
527
|
+
origins: Array.from(oe.values())
|
|
528
528
|
})}
|
|
529
529
|
|
|
530
530
|
`);
|
|
531
531
|
} catch {
|
|
532
532
|
}
|
|
533
|
-
}),
|
|
533
|
+
}), z.push(ve), z.length > ee && z.shift(), W.forEach((J) => {
|
|
534
534
|
try {
|
|
535
|
-
|
|
535
|
+
J.write(`data: ${JSON.stringify(ve)}
|
|
536
536
|
|
|
537
537
|
`);
|
|
538
538
|
} catch {
|
|
539
539
|
}
|
|
540
540
|
});
|
|
541
541
|
};
|
|
542
|
-
if (
|
|
543
|
-
const
|
|
544
|
-
o.default.readFile(
|
|
545
|
-
if (
|
|
546
|
-
console.log(`❌ File not found: ${
|
|
542
|
+
if (Z) {
|
|
543
|
+
const se = G.htmlFile ? t.default.join(Z, G.htmlFile) : t.default.join(Z, "index.html");
|
|
544
|
+
o.default.readFile(se, "utf-8", (H, q) => {
|
|
545
|
+
if (H) {
|
|
546
|
+
console.log(`❌ File not found: ${se}`), l.writeHead(404, { "Content-Type": "application/json" }), l.end(JSON.stringify({ error: "index.html not found" }));
|
|
547
547
|
return;
|
|
548
548
|
}
|
|
549
|
-
const
|
|
549
|
+
const je = Ne(q, V), ve = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, Ae = {
|
|
550
550
|
item: {
|
|
551
|
-
name:
|
|
552
|
-
id:
|
|
551
|
+
name: V,
|
|
552
|
+
id: V,
|
|
553
553
|
consume_variant: [
|
|
554
554
|
{
|
|
555
|
-
id:
|
|
555
|
+
id: ve,
|
|
556
556
|
name: "dev version",
|
|
557
557
|
loader: {
|
|
558
558
|
type: "HTMLLoader",
|
|
559
559
|
shadowRootMode: "localFrame",
|
|
560
|
-
HTML:
|
|
560
|
+
HTML: je
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
563
|
]
|
|
564
564
|
}
|
|
565
565
|
};
|
|
566
|
-
console.log(`✅ Serving consume JSON for: ${
|
|
566
|
+
console.log(`✅ Serving consume JSON for: ${V}`), pe(!0), l.writeHead(200, {
|
|
567
567
|
"Content-Type": "application/json",
|
|
568
568
|
"Access-Control-Allow-Origin": "*"
|
|
569
|
-
}),
|
|
569
|
+
}), l.end(JSON.stringify(Ae, null, 2));
|
|
570
570
|
});
|
|
571
571
|
} else {
|
|
572
|
-
console.log(`📡 Proxying consume request to cloud.myop.dev for: ${
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
572
|
+
console.log(`📡 Proxying consume request to cloud.myop.dev for: ${V}`);
|
|
573
|
+
const se = `https://cloud.myop.dev/consume${f.search}`;
|
|
574
|
+
pe(!1), fetch(se).then((H) => H.text()).then((H) => {
|
|
575
|
+
l.writeHead(200, {
|
|
576
576
|
"Content-Type": "application/json",
|
|
577
577
|
"Access-Control-Allow-Origin": "*"
|
|
578
|
-
}),
|
|
579
|
-
}).catch((
|
|
580
|
-
console.error(`❌ Proxy error: ${
|
|
578
|
+
}), l.end(H);
|
|
579
|
+
}).catch((H) => {
|
|
580
|
+
console.error(`❌ Proxy error: ${H.message}`), l.writeHead(502, { "Content-Type": "application/json" }), l.end(JSON.stringify({ error: "Failed to fetch from cloud.myop.dev" }));
|
|
581
581
|
});
|
|
582
582
|
}
|
|
583
583
|
return;
|
|
584
584
|
}
|
|
585
|
-
if (
|
|
586
|
-
|
|
585
|
+
if (g === "/events") {
|
|
586
|
+
l.writeHead(200, {
|
|
587
587
|
"Content-Type": "text/event-stream",
|
|
588
588
|
"Cache-Control": "no-cache",
|
|
589
589
|
Connection: "keep-alive",
|
|
590
590
|
"Access-Control-Allow-Origin": "*"
|
|
591
|
-
}),
|
|
592
|
-
const
|
|
593
|
-
id:
|
|
594
|
-
path:
|
|
595
|
-
name:
|
|
591
|
+
}), W.push(l);
|
|
592
|
+
const V = Array.from(O.entries()).map(([G, Z]) => ({
|
|
593
|
+
id: G,
|
|
594
|
+
path: Z.path,
|
|
595
|
+
name: Z.name
|
|
596
596
|
}));
|
|
597
|
-
|
|
597
|
+
l.write(`data: ${JSON.stringify({
|
|
598
598
|
type: "components",
|
|
599
|
-
components:
|
|
599
|
+
components: V
|
|
600
600
|
})}
|
|
601
601
|
|
|
602
|
-
`),
|
|
602
|
+
`), l.write(`data: ${JSON.stringify({
|
|
603
603
|
type: "origins",
|
|
604
|
-
origins: Array.from(
|
|
604
|
+
origins: Array.from(oe.values())
|
|
605
605
|
})}
|
|
606
606
|
|
|
607
|
-
`),
|
|
607
|
+
`), l.write(`data: ${JSON.stringify({
|
|
608
608
|
type: "requestLog",
|
|
609
|
-
log:
|
|
609
|
+
log: z
|
|
610
610
|
})}
|
|
611
611
|
|
|
612
|
-
`),
|
|
613
|
-
const
|
|
614
|
-
|
|
612
|
+
`), d.on("close", () => {
|
|
613
|
+
const G = W.indexOf(l);
|
|
614
|
+
G !== -1 && W.splice(G, 1);
|
|
615
615
|
});
|
|
616
616
|
return;
|
|
617
617
|
}
|
|
618
|
-
if (
|
|
619
|
-
|
|
618
|
+
if (w.length === 0) {
|
|
619
|
+
l.writeHead(200, { "Content-Type": "text/html" }), l.end(Ut(r, c, p, m));
|
|
620
620
|
return;
|
|
621
621
|
}
|
|
622
|
-
if (
|
|
623
|
-
|
|
622
|
+
if (w[0] !== "view") {
|
|
623
|
+
l.writeHead(404, { "Content-Type": "text/plain" }), l.end("Not found. Use /view/<componentId>/ to access components.");
|
|
624
624
|
return;
|
|
625
625
|
}
|
|
626
|
-
if (
|
|
627
|
-
|
|
626
|
+
if (w.length < 2) {
|
|
627
|
+
l.writeHead(400, { "Content-Type": "text/plain" }), l.end("Component ID required. Use /view/<componentId>/");
|
|
628
628
|
return;
|
|
629
629
|
}
|
|
630
|
-
const
|
|
630
|
+
const x = w[1], I = O.get(x);
|
|
631
631
|
if (!I) {
|
|
632
|
-
|
|
632
|
+
l.writeHead(404, { "Content-Type": "text/plain" }), l.end(`Component not found: ${x}`);
|
|
633
633
|
return;
|
|
634
634
|
}
|
|
635
|
-
const
|
|
636
|
-
console.log(`📥 Request: ${
|
|
637
|
-
if (
|
|
638
|
-
console.log(`❌ File not found: ${
|
|
635
|
+
const j = I.path, B = w.slice(2), K = I.htmlFile || "index.html", ne = B.length === 0 ? K : B.join("/"), de = t.default.join(j, ne);
|
|
636
|
+
console.log(`📥 Request: ${d.url} -> ${de}`), o.default.readFile(de, (V, G) => {
|
|
637
|
+
if (V) {
|
|
638
|
+
console.log(`❌ File not found: ${de}`), l.writeHead(404, { "Content-Type": "text/plain" }), l.end("Not Found");
|
|
639
639
|
return;
|
|
640
640
|
}
|
|
641
|
-
const
|
|
642
|
-
console.log(`✅ Serving: ${
|
|
643
|
-
let
|
|
644
|
-
if (
|
|
645
|
-
const
|
|
646
|
-
|
|
641
|
+
const Z = T(de);
|
|
642
|
+
console.log(`✅ Serving: ${de} (${Z})`);
|
|
643
|
+
let pe = G;
|
|
644
|
+
if (Z === "text/html" && R) {
|
|
645
|
+
const se = G.toString("utf-8");
|
|
646
|
+
pe = Ne(se, x);
|
|
647
647
|
}
|
|
648
|
-
|
|
649
|
-
"Content-Type":
|
|
648
|
+
l.writeHead(200, {
|
|
649
|
+
"Content-Type": Z,
|
|
650
650
|
"Access-Control-Allow-Origin": "*"
|
|
651
|
-
}),
|
|
651
|
+
}), l.end(pe);
|
|
652
652
|
});
|
|
653
|
-
}),
|
|
654
|
-
const f =
|
|
655
|
-
componentId:
|
|
653
|
+
}), Re = () => new Promise((d, l) => {
|
|
654
|
+
const f = h ? t.default.resolve(F) : t.default.resolve(F, y), g = JSON.stringify({
|
|
655
|
+
componentId: M,
|
|
656
656
|
distPath: f,
|
|
657
657
|
componentName: N,
|
|
658
|
-
htmlFile:
|
|
659
|
-
}),
|
|
658
|
+
htmlFile: h ? u : null
|
|
659
|
+
}), w = {
|
|
660
660
|
hostname: "localhost",
|
|
661
|
-
port:
|
|
661
|
+
port: c,
|
|
662
662
|
path: "/_register",
|
|
663
663
|
method: "POST",
|
|
664
664
|
headers: {
|
|
665
665
|
"Content-Type": "application/json",
|
|
666
|
-
"Content-Length": Buffer.byteLength(
|
|
666
|
+
"Content-Length": Buffer.byteLength(g)
|
|
667
667
|
}
|
|
668
|
-
},
|
|
669
|
-
let
|
|
670
|
-
I.on("data", (
|
|
671
|
-
I.statusCode === 200 ?
|
|
668
|
+
}, x = n.default.request(w, (I) => {
|
|
669
|
+
let j = "";
|
|
670
|
+
I.on("data", (B) => j += B), I.on("end", () => {
|
|
671
|
+
I.statusCode === 200 ? d(JSON.parse(j)) : l(new Error(`Registration failed: ${I.statusCode}`));
|
|
672
672
|
});
|
|
673
673
|
});
|
|
674
|
-
|
|
675
|
-
}), vt = () => new Promise((
|
|
676
|
-
const f = JSON.stringify({ componentId:
|
|
674
|
+
x.on("error", l), x.write(g), x.end();
|
|
675
|
+
}), vt = () => new Promise((d, l) => {
|
|
676
|
+
const f = JSON.stringify({ componentId: M }), g = {
|
|
677
677
|
hostname: "localhost",
|
|
678
|
-
port:
|
|
678
|
+
port: c,
|
|
679
679
|
path: "/_unregister",
|
|
680
680
|
method: "POST",
|
|
681
681
|
headers: {
|
|
682
682
|
"Content-Type": "application/json",
|
|
683
683
|
"Content-Length": Buffer.byteLength(f)
|
|
684
684
|
}
|
|
685
|
-
},
|
|
686
|
-
|
|
685
|
+
}, w = n.default.request(g, (x) => {
|
|
686
|
+
d();
|
|
687
687
|
});
|
|
688
|
-
|
|
689
|
-
}), St = (
|
|
688
|
+
w.on("error", () => d()), w.write(f), w.end();
|
|
689
|
+
}), St = (d) => `
|
|
690
690
|
<!-- MYOP HMR -->
|
|
691
691
|
<script>
|
|
692
692
|
(function() {
|
|
693
|
-
const componentId = '${
|
|
694
|
-
const wsUrl = 'ws://localhost:${
|
|
693
|
+
const componentId = '${d}';
|
|
694
|
+
const wsUrl = 'ws://localhost:${c}/_hmr/' + componentId;
|
|
695
695
|
let ws;
|
|
696
696
|
let reconnectAttempts = 0;
|
|
697
697
|
const maxReconnectAttempts = 10;
|
|
@@ -791,64 +791,64 @@ Sec-WebSocket-Accept: ${S}\r
|
|
|
791
791
|
connect();
|
|
792
792
|
})();
|
|
793
793
|
<\/script>
|
|
794
|
-
`,
|
|
795
|
-
if (!
|
|
796
|
-
const f = St(
|
|
797
|
-
return
|
|
798
|
-
},
|
|
799
|
-
const
|
|
800
|
-
let
|
|
801
|
-
return f < 126 ?
|
|
794
|
+
`, Ne = (d, l) => {
|
|
795
|
+
if (!R) return d;
|
|
796
|
+
const f = St(l);
|
|
797
|
+
return d.includes("</body>") ? d.replace("</body>", `${f}</body>`) : d.includes("</html>") ? d.replace("</html>", `${f}</html>`) : d + f;
|
|
798
|
+
}, Xe = (d) => {
|
|
799
|
+
const l = Buffer.from(d), f = l.length;
|
|
800
|
+
let g;
|
|
801
|
+
return f < 126 ? g = Buffer.concat([
|
|
802
802
|
Buffer.from([129, f]),
|
|
803
803
|
// FIN + text frame, length
|
|
804
|
-
|
|
805
|
-
]) : f < 65536 ?
|
|
804
|
+
l
|
|
805
|
+
]) : f < 65536 ? g = Buffer.concat([
|
|
806
806
|
Buffer.from([129, 126]),
|
|
807
807
|
// FIN + text frame, extended length
|
|
808
808
|
Buffer.from([f >> 8, f & 255]),
|
|
809
809
|
// 16-bit length
|
|
810
|
-
|
|
811
|
-
]) :
|
|
810
|
+
l
|
|
811
|
+
]) : g = Buffer.concat([
|
|
812
812
|
Buffer.from([129, 127]),
|
|
813
813
|
// FIN + text frame, extended length
|
|
814
814
|
Buffer.from([0, 0, 0, 0, f >> 24, f >> 16 & 255, f >> 8 & 255, f & 255]),
|
|
815
815
|
// 64-bit length
|
|
816
|
-
|
|
817
|
-
]),
|
|
818
|
-
},
|
|
819
|
-
if (!
|
|
820
|
-
const
|
|
821
|
-
let
|
|
816
|
+
l
|
|
817
|
+
]), g;
|
|
818
|
+
}, et = () => {
|
|
819
|
+
if (!R) return;
|
|
820
|
+
const d = h ? u : t.default.join(y, "index.html");
|
|
821
|
+
let l;
|
|
822
822
|
try {
|
|
823
|
-
const f = o.default.readFileSync(
|
|
824
|
-
|
|
823
|
+
const f = o.default.readFileSync(d, "utf-8");
|
|
824
|
+
l = Ne(f, M);
|
|
825
825
|
} catch (f) {
|
|
826
826
|
console.error("❌ Failed to read HTML for HMR:", f.message);
|
|
827
827
|
return;
|
|
828
828
|
}
|
|
829
|
-
if (
|
|
830
|
-
const f =
|
|
829
|
+
if (Fe) {
|
|
830
|
+
const f = Q.get(M);
|
|
831
831
|
if (!f || f.size === 0)
|
|
832
832
|
return;
|
|
833
833
|
console.log(`🔥 Notifying ${f.size} HMR client(s)`);
|
|
834
|
-
const
|
|
834
|
+
const g = JSON.stringify({
|
|
835
835
|
type: "update",
|
|
836
|
-
html:
|
|
837
|
-
}),
|
|
838
|
-
f.forEach((
|
|
836
|
+
html: l
|
|
837
|
+
}), w = Xe(g);
|
|
838
|
+
f.forEach((x) => {
|
|
839
839
|
try {
|
|
840
|
-
|
|
840
|
+
x.write(w);
|
|
841
841
|
} catch {
|
|
842
|
-
f.delete(
|
|
842
|
+
f.delete(x);
|
|
843
843
|
}
|
|
844
844
|
});
|
|
845
845
|
} else {
|
|
846
846
|
const f = JSON.stringify({
|
|
847
|
-
componentId:
|
|
848
|
-
html:
|
|
849
|
-
}),
|
|
847
|
+
componentId: M,
|
|
848
|
+
html: l
|
|
849
|
+
}), g = {
|
|
850
850
|
hostname: "localhost",
|
|
851
|
-
port:
|
|
851
|
+
port: c,
|
|
852
852
|
path: "/_hmr_notify",
|
|
853
853
|
method: "POST",
|
|
854
854
|
headers: {
|
|
@@ -856,196 +856,196 @@ Sec-WebSocket-Accept: ${S}\r
|
|
|
856
856
|
"Content-Length": Buffer.byteLength(f)
|
|
857
857
|
},
|
|
858
858
|
timeout: 5e3
|
|
859
|
-
},
|
|
859
|
+
}, w = n.default.request(g, (x) => {
|
|
860
860
|
let I = "";
|
|
861
|
-
|
|
861
|
+
x.on("data", (j) => I += j), x.on("end", () => {
|
|
862
862
|
try {
|
|
863
|
-
const
|
|
864
|
-
|
|
863
|
+
const j = JSON.parse(I);
|
|
864
|
+
j.notified > 0 && console.log(`🔥 Notified ${j.notified} HMR client(s) via server`);
|
|
865
865
|
} catch {
|
|
866
866
|
}
|
|
867
867
|
});
|
|
868
868
|
});
|
|
869
|
-
|
|
870
|
-
}),
|
|
871
|
-
|
|
872
|
-
}),
|
|
869
|
+
w.on("error", () => {
|
|
870
|
+
}), w.on("timeout", () => {
|
|
871
|
+
w.destroy();
|
|
872
|
+
}), w.write(f), w.end();
|
|
873
873
|
}
|
|
874
874
|
};
|
|
875
|
-
let
|
|
876
|
-
const
|
|
877
|
-
if (
|
|
875
|
+
let _e = { hasTriedPlatformFix: !1, hasTriedInstall: !1 };
|
|
876
|
+
const ye = (d) => {
|
|
877
|
+
if (S) {
|
|
878
878
|
$ = !0;
|
|
879
879
|
return;
|
|
880
880
|
}
|
|
881
|
-
|
|
882
|
-
🔨 Building...`), e("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (
|
|
883
|
-
if (
|
|
884
|
-
const
|
|
885
|
-
...
|
|
886
|
-
onRetry: () =>
|
|
881
|
+
S = !0, console.log(`
|
|
882
|
+
🔨 Building...`), e("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (l, f, g) => {
|
|
883
|
+
if (S = !1, l) {
|
|
884
|
+
const w = await mt(l, f, g, e, {
|
|
885
|
+
..._e,
|
|
886
|
+
onRetry: () => ye(d)
|
|
887
887
|
});
|
|
888
|
-
|
|
888
|
+
_e = { ..._e, ...w }, w.handled || (console.error("❌ Build failed:", l.message), g && console.error(g));
|
|
889
889
|
} else
|
|
890
|
-
console.log("✅ Build completed"), f && console.log(f),
|
|
891
|
-
$ && ($ = !1,
|
|
890
|
+
console.log("✅ Build completed"), f && console.log(f), et(), d && d();
|
|
891
|
+
$ && ($ = !1, ye());
|
|
892
892
|
});
|
|
893
|
-
},
|
|
894
|
-
o.default.readdir(
|
|
895
|
-
|
|
896
|
-
const
|
|
897
|
-
if (
|
|
898
|
-
|
|
899
|
-
else if (
|
|
900
|
-
const
|
|
901
|
-
if (
|
|
893
|
+
}, tt = /* @__PURE__ */ new Set(), Te = (d) => {
|
|
894
|
+
o.default.readdir(d, { withFileTypes: !0 }, (l, f) => {
|
|
895
|
+
l || (f.forEach((g) => {
|
|
896
|
+
const w = t.default.join(d, g.name);
|
|
897
|
+
if (g.isDirectory())
|
|
898
|
+
g.name !== "node_modules" && g.name !== "dist" && !g.name.startsWith(".") && Te(w);
|
|
899
|
+
else if (g.isFile()) {
|
|
900
|
+
const x = t.default.extname(g.name);
|
|
901
|
+
if (x === ".js" || x === ".css" || x === ".html")
|
|
902
902
|
try {
|
|
903
|
-
const I = o.default.readFileSync(
|
|
904
|
-
|
|
903
|
+
const I = o.default.readFileSync(w, "utf-8");
|
|
904
|
+
b.set(w, I);
|
|
905
905
|
} catch {
|
|
906
906
|
}
|
|
907
907
|
}
|
|
908
|
-
}),
|
|
909
|
-
if (!
|
|
910
|
-
const
|
|
911
|
-
if (
|
|
912
|
-
const I = t.default.join(
|
|
908
|
+
}), tt.has(d) || (tt.add(d), o.default.watch(d, (g, w) => {
|
|
909
|
+
if (!w) return;
|
|
910
|
+
const x = t.default.extname(w);
|
|
911
|
+
if (x !== ".js" && x !== ".css" && x !== ".html") return;
|
|
912
|
+
const I = t.default.join(d, w);
|
|
913
913
|
setTimeout(() => {
|
|
914
914
|
try {
|
|
915
|
-
const
|
|
916
|
-
|
|
915
|
+
const j = o.default.readFileSync(I, "utf-8"), B = b.get(I);
|
|
916
|
+
j !== B && (b.set(I, j), console.log(`📝 File changed: ${I}`), h ? et() : ye());
|
|
917
917
|
} catch {
|
|
918
918
|
}
|
|
919
919
|
}, 50);
|
|
920
920
|
})));
|
|
921
921
|
});
|
|
922
|
-
},
|
|
922
|
+
}, ot = (d) => {
|
|
923
923
|
console.log(`
|
|
924
|
-
🔨 Component: ${
|
|
925
|
-
`),
|
|
924
|
+
🔨 Component: ${M}`), h ? (console.log("📄 No build needed (single HTML file mode)"), Te(F), console.log(`👀 Watching ${u} for changes...`), console.log(`Press Ctrl+C to stop
|
|
925
|
+
`), d && d()) : (ye(d), Te(F), console.log("👀 Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
|
|
926
926
|
`));
|
|
927
|
-
}, xt = () => new Promise((
|
|
928
|
-
const
|
|
927
|
+
}, xt = () => new Promise((d) => {
|
|
928
|
+
const l = {
|
|
929
929
|
hostname: "localhost",
|
|
930
|
-
port:
|
|
930
|
+
port: c,
|
|
931
931
|
path: "/_list",
|
|
932
932
|
method: "GET",
|
|
933
933
|
timeout: 1e3
|
|
934
|
-
}, f = n.default.request(
|
|
935
|
-
let
|
|
936
|
-
|
|
934
|
+
}, f = n.default.request(l, (g) => {
|
|
935
|
+
let w = "";
|
|
936
|
+
g.on("data", (x) => w += x), g.on("end", () => {
|
|
937
937
|
try {
|
|
938
|
-
(JSON.parse(
|
|
939
|
-
console.log(`🔄 Re-registered component: ${
|
|
938
|
+
(JSON.parse(w).components || []).map((j) => j[0]).includes(M) || Re().then(() => {
|
|
939
|
+
console.log(`🔄 Re-registered component: ${M}`);
|
|
940
940
|
}).catch(() => {
|
|
941
941
|
});
|
|
942
942
|
} catch {
|
|
943
943
|
}
|
|
944
|
-
|
|
944
|
+
d(!0);
|
|
945
945
|
});
|
|
946
946
|
});
|
|
947
|
-
f.on("error", () =>
|
|
948
|
-
f.destroy(),
|
|
947
|
+
f.on("error", () => d(!1)), f.on("timeout", () => {
|
|
948
|
+
f.destroy(), d(!1);
|
|
949
949
|
}), f.end();
|
|
950
|
-
}), $t = () => new Promise((
|
|
951
|
-
const
|
|
952
|
-
if (
|
|
953
|
-
let
|
|
954
|
-
f.on("data", (
|
|
950
|
+
}), $t = () => new Promise((d) => {
|
|
951
|
+
const l = n.default.createServer((f, g) => {
|
|
952
|
+
if (g.setHeader("Content-Type", "application/json"), f.method === "POST" && f.url === "/_register") {
|
|
953
|
+
let w = "";
|
|
954
|
+
f.on("data", (x) => w += x), f.on("end", () => {
|
|
955
955
|
try {
|
|
956
|
-
const { componentId:
|
|
957
|
-
|
|
958
|
-
const
|
|
959
|
-
console.log(`✅ Registered: ${
|
|
960
|
-
} catch (
|
|
961
|
-
|
|
956
|
+
const { componentId: x, distPath: I, componentName: j, htmlFile: B } = JSON.parse(w);
|
|
957
|
+
O.set(x, { path: I, name: j || null, htmlFile: B || null });
|
|
958
|
+
const K = j ? ` (${j})` : "";
|
|
959
|
+
console.log(`✅ Registered: ${x}${K} -> ${I}${B ? "/" + B : ""}`), g.writeHead(200), g.end(JSON.stringify({ success: !0, registered: Array.from(O.keys()) }));
|
|
960
|
+
} catch (x) {
|
|
961
|
+
g.writeHead(400), g.end(JSON.stringify({ error: x.message }));
|
|
962
962
|
}
|
|
963
963
|
});
|
|
964
964
|
} else if (f.method === "POST" && f.url === "/_unregister") {
|
|
965
|
-
let
|
|
966
|
-
f.on("data", (
|
|
965
|
+
let w = "";
|
|
966
|
+
f.on("data", (x) => w += x), f.on("end", () => {
|
|
967
967
|
try {
|
|
968
|
-
const { componentId:
|
|
969
|
-
|
|
970
|
-
} catch (
|
|
971
|
-
|
|
968
|
+
const { componentId: x } = JSON.parse(w);
|
|
969
|
+
O.delete(x), console.log(`❌ Unregistered: ${x}`), g.writeHead(200), g.end(JSON.stringify({ success: !0 }));
|
|
970
|
+
} catch (x) {
|
|
971
|
+
g.writeHead(400), g.end(JSON.stringify({ error: x.message }));
|
|
972
972
|
}
|
|
973
973
|
});
|
|
974
|
-
} else f.method === "GET" && f.url === "/_list" ? (
|
|
974
|
+
} else f.method === "GET" && f.url === "/_list" ? (g.writeHead(200), g.end(JSON.stringify({ components: Array.from(O.entries()) }))) : (g.writeHead(404), g.end(JSON.stringify({ error: "Not found" })));
|
|
975
975
|
});
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
}),
|
|
976
|
+
l.on("error", () => {
|
|
977
|
+
d(!1);
|
|
978
|
+
}), l.listen(c, () => {
|
|
979
979
|
console.log(`
|
|
980
|
-
🔄 Taking over as server...`), console.log(`📡 Management server on port ${
|
|
981
|
-
|
|
982
|
-
}),
|
|
983
|
-
console.log(`📡 Main server running at http://localhost:${
|
|
984
|
-
const f =
|
|
985
|
-
|
|
980
|
+
🔄 Taking over as server...`), console.log(`📡 Management server on port ${c}`), he.on("error", () => {
|
|
981
|
+
l.close(), d(!1);
|
|
982
|
+
}), he.listen(r, () => {
|
|
983
|
+
console.log(`📡 Main server running at http://localhost:${r}`);
|
|
984
|
+
const f = h ? t.default.resolve(F) : t.default.resolve(F, y);
|
|
985
|
+
O.set(M, {
|
|
986
986
|
path: f,
|
|
987
987
|
name: N,
|
|
988
|
-
htmlFile:
|
|
988
|
+
htmlFile: h ? u : null
|
|
989
989
|
});
|
|
990
|
-
const
|
|
991
|
-
console.log(`✅ Registered component: ${
|
|
990
|
+
const g = N ? ` (${N})` : "";
|
|
991
|
+
console.log(`✅ Registered component: ${M}${g}`), console.log(`📡 Access at: http://localhost:${r}/view/${M}/`), d(!0);
|
|
992
992
|
});
|
|
993
993
|
});
|
|
994
994
|
});
|
|
995
|
-
let
|
|
996
|
-
const
|
|
997
|
-
|
|
998
|
-
await xt() || (clearInterval(
|
|
999
|
-
⚠️ Server appears to be down, attempting to take over...`), await $t() ? (console.log("✅ Successfully took over as server"),
|
|
995
|
+
let we;
|
|
996
|
+
const nt = () => {
|
|
997
|
+
we = setInterval(async () => {
|
|
998
|
+
await xt() || (clearInterval(we), console.log(`
|
|
999
|
+
⚠️ Server appears to be down, attempting to take over...`), await $t() ? (console.log("✅ Successfully took over as server"), Fe = !0) : (console.log("ℹ️ Another instance took over, re-registering..."), setTimeout(async () => {
|
|
1000
1000
|
try {
|
|
1001
|
-
await
|
|
1001
|
+
await Re(), console.log(`✅ Re-registered component: ${M}`), nt();
|
|
1002
1002
|
} catch (f) {
|
|
1003
1003
|
console.error("❌ Failed to re-register:", f.message);
|
|
1004
1004
|
}
|
|
1005
1005
|
}, 2e3)));
|
|
1006
1006
|
}, 3e3);
|
|
1007
|
-
},
|
|
1007
|
+
}, st = async () => {
|
|
1008
1008
|
console.log(`
|
|
1009
1009
|
|
|
1010
|
-
🛑 Shutting down...`),
|
|
1010
|
+
🛑 Shutting down...`), we && clearInterval(we), await vt(), process.exit(0);
|
|
1011
1011
|
};
|
|
1012
|
-
process.on("SIGINT",
|
|
1013
|
-
let
|
|
1014
|
-
|
|
1015
|
-
if (
|
|
1012
|
+
process.on("SIGINT", st), process.on("SIGTERM", st);
|
|
1013
|
+
let Fe = !1;
|
|
1014
|
+
ke.on("error", async (d) => {
|
|
1015
|
+
if (d.code === "EADDRINUSE") {
|
|
1016
1016
|
console.log(`
|
|
1017
1017
|
🔗 Connecting to existing dev server...`);
|
|
1018
1018
|
try {
|
|
1019
|
-
|
|
1020
|
-
const
|
|
1021
|
-
console.log(`✅ Registered component: ${
|
|
1022
|
-
process.env.MYOP_NO_BROWSER ||
|
|
1023
|
-
}),
|
|
1024
|
-
} catch (
|
|
1025
|
-
console.error("❌ Failed to register component:",
|
|
1019
|
+
M = await D();
|
|
1020
|
+
const l = await Re();
|
|
1021
|
+
console.log(`✅ Registered component: ${M}`), console.log(`📡 Access at: http://localhost:${r}/view/${M}/`), console.log(`📋 All registered components: ${l.registered.join(", ")}`), ot(() => {
|
|
1022
|
+
process.env.MYOP_NO_BROWSER || C(`http://localhost:${r}/view/${M}/`);
|
|
1023
|
+
}), nt();
|
|
1024
|
+
} catch (l) {
|
|
1025
|
+
console.error("❌ Failed to register component:", l.message), process.exit(1);
|
|
1026
1026
|
}
|
|
1027
1027
|
} else
|
|
1028
|
-
console.error("❌ Management server error:",
|
|
1029
|
-
}),
|
|
1030
|
-
|
|
1031
|
-
🚀 Starting shared dev server...`), console.log(`📡 Management server on port ${
|
|
1032
|
-
console.error("❌ Main server error:",
|
|
1033
|
-
}),
|
|
1034
|
-
console.log(`📡 Main server running at http://localhost:${
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
path:
|
|
1028
|
+
console.error("❌ Management server error:", d.message), process.exit(1);
|
|
1029
|
+
}), ke.on("upgrade", Oe), ke.listen(c, async () => {
|
|
1030
|
+
Fe = !0, console.log(`
|
|
1031
|
+
🚀 Starting shared dev server...`), console.log(`📡 Management server on port ${c}`), he.on("error", (d) => {
|
|
1032
|
+
console.error("❌ Main server error:", d.message), process.exit(1);
|
|
1033
|
+
}), he.listen(r, async () => {
|
|
1034
|
+
console.log(`📡 Main server running at http://localhost:${r}`), (M === "DEV" || M === "NEW") && (M = "DEV1");
|
|
1035
|
+
const d = h ? t.default.resolve(F) : t.default.resolve(F, y);
|
|
1036
|
+
O.set(M, {
|
|
1037
|
+
path: d,
|
|
1038
1038
|
name: N,
|
|
1039
|
-
htmlFile:
|
|
1039
|
+
htmlFile: h ? u : null
|
|
1040
1040
|
});
|
|
1041
|
-
const
|
|
1042
|
-
console.log(`✅ Registered component: ${
|
|
1043
|
-
process.env.MYOP_NO_BROWSER ||
|
|
1041
|
+
const l = N ? ` (${N})` : "";
|
|
1042
|
+
console.log(`✅ Registered component: ${M}${l}`), console.log(`📡 Access at: http://localhost:${r}/view/${M}/`), ot(() => {
|
|
1043
|
+
process.env.MYOP_NO_BROWSER || C(`http://localhost:${r}/view/${M}/`);
|
|
1044
1044
|
});
|
|
1045
1045
|
});
|
|
1046
1046
|
});
|
|
1047
1047
|
}
|
|
1048
|
-
const
|
|
1048
|
+
const L = class L {
|
|
1049
1049
|
constructor(t) {
|
|
1050
1050
|
this.components = t.map(
|
|
1051
1051
|
(e) => typeof e == "string" ? { name: e, path: "", id: "" } : e
|
|
@@ -1054,7 +1054,7 @@ const A = class A {
|
|
|
1054
1054
|
this.logs.set(e.name, []), this.scrollPos.set(e.name, 0), this.statuses.set(e.name, "Initializing..."), this.statusKeys.set(e.name, "initializing");
|
|
1055
1055
|
this.cols = process.stdout.columns || 120, this.rows = process.stdout.rows || 30, process.stdout.on("resize", () => {
|
|
1056
1056
|
this.cols = process.stdout.columns || 120, this.rows = process.stdout.rows || 30, this.needsFullRedraw = !0, this.calculateLayout(), this.render();
|
|
1057
|
-
}), this.setupKeyboardInput(), process.stdout.write(
|
|
1057
|
+
}), this.setupKeyboardInput(), process.stdout.write(L.ESC.hideCursor), this.calculateLayout(), this.render(), this.uptimeInterval = setInterval(() => this.updateHeader(), 1e3);
|
|
1058
1058
|
}
|
|
1059
1059
|
setupKeyboardInput() {
|
|
1060
1060
|
process.stdin.isTTY && (process.stdin.setRawMode(!0), process.stdin.resume(), process.stdin.setEncoding("utf8"), process.stdin.on("data", (t) => {
|
|
@@ -1095,15 +1095,15 @@ const A = class A {
|
|
|
1095
1095
|
const t = this.components.length, e = 38;
|
|
1096
1096
|
let n;
|
|
1097
1097
|
this.cols >= e * 3 + 4 ? n = Math.min(t, 3) : this.cols >= e * 2 + 2 ? n = Math.min(t, 2) : n = 1;
|
|
1098
|
-
const s = Math.ceil(t / n), i = Math.floor(this.cols / n),
|
|
1099
|
-
this.visibleLogLines = Math.max(2,
|
|
1100
|
-
for (let
|
|
1101
|
-
const
|
|
1102
|
-
this.panelPositions.set(
|
|
1103
|
-
row:
|
|
1098
|
+
const s = Math.ceil(t / n), i = Math.floor(this.cols / n), a = 2, m = this.rows - a - 2, r = Math.floor(m / s);
|
|
1099
|
+
this.visibleLogLines = Math.max(2, r - 4), this.layout = { panelsPerRow: n, panelWidth: i, numRows: s, panelHeight: r }, this.panelPositions.clear();
|
|
1100
|
+
for (let c = 0; c < t; c++) {
|
|
1101
|
+
const y = this.components[c], S = Math.floor(c / n), $ = c % n;
|
|
1102
|
+
this.panelPositions.set(y.name, {
|
|
1103
|
+
row: a + 1 + S * r,
|
|
1104
1104
|
col: $ * i + 1,
|
|
1105
1105
|
width: i,
|
|
1106
|
-
height:
|
|
1106
|
+
height: r
|
|
1107
1107
|
});
|
|
1108
1108
|
}
|
|
1109
1109
|
}
|
|
@@ -1122,8 +1122,8 @@ const A = class A {
|
|
|
1122
1122
|
s.includes("initializing") || s.includes("⏳") ? n = "initializing" : s.includes("starting") ? n = "starting" : s.includes("building") || s.includes("🔨") ? n = "building" : s.includes("ready") || s.includes("✅") ? n = "ready" : s.includes("changed") || s.includes("📝") ? n = "changed" : s.includes("hmr") ? n = "hmr_update" : s.includes("🔥") ? n = "hmr" : s.includes("error") || s.includes("❌") ? n = "error" : s.includes("warning") || s.includes("⚠") ? n = "warning" : (s.includes("stopped") || s.includes("exited")) && (n = "stopped"), this.statuses.set(t, e), this.statusKeys.set(t, n), this.queueUpdate(t);
|
|
1123
1123
|
}
|
|
1124
1124
|
scroll(t, e) {
|
|
1125
|
-
const n = this.logs.get(t) || [], s = this.scrollPos.get(t) || 0, i = Math.max(0, n.length - this.visibleLogLines),
|
|
1126
|
-
|
|
1125
|
+
const n = this.logs.get(t) || [], s = this.scrollPos.get(t) || 0, i = Math.max(0, n.length - this.visibleLogLines), a = Math.max(0, Math.min(i, s + e));
|
|
1126
|
+
a !== s && (this.scrollPos.set(t, a), this.queueUpdate(t));
|
|
1127
1127
|
}
|
|
1128
1128
|
queueUpdate(t) {
|
|
1129
1129
|
this.pendingUpdates.add(t), this.renderQueued || (this.renderQueued = !0, setImmediate(() => {
|
|
@@ -1144,44 +1144,44 @@ const A = class A {
|
|
|
1144
1144
|
return `${e}:${n.toString().padStart(2, "0")}`;
|
|
1145
1145
|
}
|
|
1146
1146
|
updateHeader() {
|
|
1147
|
-
const t =
|
|
1147
|
+
const t = L.C, e = Array.from(this.statusKeys.values()).filter((i) => i === "ready").length, n = this.components.length;
|
|
1148
1148
|
let s = `${t.dim}📡${t.reset} http://localhost:9292 ${t.gray}|${t.reset} `;
|
|
1149
|
-
s += `${t.green}${e}${t.reset}/${n} ready ${t.gray}|${t.reset} `, s += `⏱ ${this.getUptime()} ${t.gray}|${t.reset} `, s += `Press ${t.yellow}Ctrl+C${t.reset} to stop`, s +=
|
|
1149
|
+
s += `${t.green}${e}${t.reset}/${n} ready ${t.gray}|${t.reset} `, s += `⏱ ${this.getUptime()} ${t.gray}|${t.reset} `, s += `Press ${t.yellow}Ctrl+C${t.reset} to stop`, s += L.ESC.clearLine.slice(0, -1), process.stdout.write(L.ESC.moveTo(2, 1) + s);
|
|
1150
1150
|
}
|
|
1151
1151
|
renderPanel(t) {
|
|
1152
|
-
const e =
|
|
1152
|
+
const e = L.C, n = L.STATUS, s = this.panelPositions.get(t);
|
|
1153
1153
|
if (!s) return;
|
|
1154
|
-
const i = this.components.findIndex((D) => D.name === t),
|
|
1155
|
-
let
|
|
1156
|
-
|
|
1157
|
-
const
|
|
1158
|
-
|
|
1159
|
-
const
|
|
1160
|
-
let
|
|
1161
|
-
|
|
1162
|
-
const
|
|
1163
|
-
let
|
|
1164
|
-
N && (
|
|
1165
|
-
const
|
|
1154
|
+
const i = this.components.findIndex((D) => D.name === t), a = this.components[i], p = i === this.selectedPanel, m = this.statusKeys.get(t) || "initializing", r = n[m], c = e[r.color], y = this.logs.get(t) || [], S = this.scrollPos.get(t) || 0, $ = s.width - 1, h = p ? e.cyan : e.gray, u = [], E = a.name.substring(0, $ - 20);
|
|
1155
|
+
let k = `${h}┌─${e.reset} ${c}${r.icon}${e.reset} `;
|
|
1156
|
+
k += `${e.bold}${E}${e.reset} ${e.gray}─${e.reset} ${c}${r.label}${e.reset} `;
|
|
1157
|
+
const C = 5 + E.length + r.label.length + 3;
|
|
1158
|
+
k += `${h}${"─".repeat(Math.max(0, $ - C))}┐${e.reset}`, u.push(L.ESC.moveTo(s.row, s.col) + k);
|
|
1159
|
+
const b = (a.path || "").substring(0, $ - 6);
|
|
1160
|
+
let A = `${h}│${e.reset} ${e.dim}${b}${e.reset}`;
|
|
1161
|
+
A += " ".repeat(Math.max(0, $ - b.length - 3)), A += `${h}│${e.reset}`, u.push(L.ESC.moveTo(s.row + 1, s.col) + A);
|
|
1162
|
+
const M = y.length, N = M > this.visibleLogLines ? `${S + 1}-${Math.min(S + this.visibleLogLines, M)}/${M}` : "";
|
|
1163
|
+
let R = `${h}├${"─".repeat($ - N.length - 4)}${e.reset}`;
|
|
1164
|
+
N && (R += `${e.dim}${N}${e.reset}`), R += `${h}${"─".repeat(2)}┤${e.reset}`, u.push(L.ESC.moveTo(s.row + 2, s.col) + R);
|
|
1165
|
+
const U = y.slice(S, S + this.visibleLogLines);
|
|
1166
1166
|
for (let D = 0; D < this.visibleLogLines; D++) {
|
|
1167
|
-
const F =
|
|
1168
|
-
let
|
|
1167
|
+
const F = U[D];
|
|
1168
|
+
let T = `${h}│${e.reset}`;
|
|
1169
1169
|
if (F) {
|
|
1170
|
-
let
|
|
1171
|
-
F.type === "success" ?
|
|
1172
|
-
const
|
|
1173
|
-
|
|
1174
|
-
const
|
|
1175
|
-
|
|
1170
|
+
let O = e.white;
|
|
1171
|
+
F.type === "success" ? O = e.green : F.type === "error" ? O = e.red : F.type === "warning" ? O = e.yellow : F.type === "hmr" ? O = e.magenta : F.type === "change" && (O = e.blue);
|
|
1172
|
+
const z = F.message.substring(0, $ - 12);
|
|
1173
|
+
T += `${e.dim}${F.timestamp}${e.reset} ${O}${z}${e.reset}`;
|
|
1174
|
+
const ee = $ - F.timestamp.length - z.length - 2;
|
|
1175
|
+
T += " ".repeat(Math.max(0, ee));
|
|
1176
1176
|
} else
|
|
1177
|
-
|
|
1178
|
-
|
|
1177
|
+
T += " ".repeat($ - 2);
|
|
1178
|
+
T += `${h}│${e.reset}`, u.push(L.ESC.moveTo(s.row + 3 + D, s.col) + T);
|
|
1179
1179
|
}
|
|
1180
|
-
u.push(
|
|
1180
|
+
u.push(L.ESC.moveTo(s.row + 3 + this.visibleLogLines, s.col) + `${h}└${"─".repeat($ - 2)}┘${e.reset}`), process.stdout.write(u.join(""));
|
|
1181
1181
|
}
|
|
1182
1182
|
fullRender() {
|
|
1183
|
-
const t =
|
|
1184
|
-
process.stdout.write(
|
|
1183
|
+
const t = L.C;
|
|
1184
|
+
process.stdout.write(L.ESC.clearScreen + L.ESC.moveTo(1, 1));
|
|
1185
1185
|
const e = " MYOP MONOREPO DEV ", n = Math.floor((this.cols - e.length) / 2);
|
|
1186
1186
|
process.stdout.write(`${t.cyan}${"━".repeat(n)}${t.bold}${t.bgCyan}${t.black}${e}${t.reset}${t.cyan}${"━".repeat(this.cols - n - e.length)}${t.reset}`), this.updateHeader();
|
|
1187
1187
|
for (const s of this.components)
|
|
@@ -1189,26 +1189,26 @@ const A = class A {
|
|
|
1189
1189
|
this.renderFooter();
|
|
1190
1190
|
}
|
|
1191
1191
|
renderFooter() {
|
|
1192
|
-
const t =
|
|
1192
|
+
const t = L.C, e = this.rows - 1;
|
|
1193
1193
|
let n = `${t.gray}`;
|
|
1194
|
-
n += `${t.green}●${t.gray} Ready `, n += `${t.yellow}⟳${t.gray} Building `, n += `${t.magenta}⚡${t.gray} HMR `, n += `${t.red}✖${t.gray} Error `, n += `${t.dim}| ←→: select panel ↑↓: scroll PgUp/PgDn: page g/G: top/bottom${t.reset}`, process.stdout.write(
|
|
1194
|
+
n += `${t.green}●${t.gray} Ready `, n += `${t.yellow}⟳${t.gray} Building `, n += `${t.magenta}⚡${t.gray} HMR `, n += `${t.red}✖${t.gray} Error `, n += `${t.dim}| ←→: select panel ↑↓: scroll PgUp/PgDn: page g/G: top/bottom${t.reset}`, process.stdout.write(L.ESC.moveTo(e, 1) + n);
|
|
1195
1195
|
}
|
|
1196
1196
|
render() {
|
|
1197
1197
|
this.needsFullRedraw = !0, this.queueUpdate("__full__");
|
|
1198
1198
|
}
|
|
1199
1199
|
clear() {
|
|
1200
|
-
this.uptimeInterval && clearInterval(this.uptimeInterval), process.stdin.isTTY && process.stdin.setRawMode(!1), process.stdout.write(
|
|
1200
|
+
this.uptimeInterval && clearInterval(this.uptimeInterval), process.stdin.isTTY && process.stdin.setRawMode(!1), process.stdout.write(L.ESC.clearScreen + L.ESC.moveTo(1, 1) + L.ESC.showCursor);
|
|
1201
1201
|
}
|
|
1202
1202
|
};
|
|
1203
1203
|
// ANSI escape codes
|
|
1204
|
-
|
|
1204
|
+
Se(L, "ESC", {
|
|
1205
1205
|
moveTo: (t, e) => `\x1B[${t};${e}H`,
|
|
1206
1206
|
hideCursor: "\x1B[?25l",
|
|
1207
1207
|
showCursor: "\x1B[?25h",
|
|
1208
1208
|
clearScreen: "\x1B[2J",
|
|
1209
1209
|
clearLine: "\x1B[2K"
|
|
1210
1210
|
}), // Colors
|
|
1211
|
-
|
|
1211
|
+
Se(L, "C", {
|
|
1212
1212
|
reset: "\x1B[0m",
|
|
1213
1213
|
bold: "\x1B[1m",
|
|
1214
1214
|
dim: "\x1B[2m",
|
|
@@ -1223,7 +1223,7 @@ ve(A, "C", {
|
|
|
1223
1223
|
bgCyan: "\x1B[46m",
|
|
1224
1224
|
black: "\x1B[30m"
|
|
1225
1225
|
}), // Status configs
|
|
1226
|
-
|
|
1226
|
+
Se(L, "STATUS", {
|
|
1227
1227
|
initializing: { icon: "◔", color: "yellow", label: "Initializing" },
|
|
1228
1228
|
starting: { icon: "◑", color: "yellow", label: "Starting" },
|
|
1229
1229
|
building: { icon: "⟳", color: "yellow", label: "Building" },
|
|
@@ -1236,57 +1236,57 @@ ve(A, "STATUS", {
|
|
|
1236
1236
|
warning: { icon: "⚠", color: "yellow", label: "Warning" },
|
|
1237
1237
|
stopped: { icon: "■", color: "gray", label: "Stopped" }
|
|
1238
1238
|
});
|
|
1239
|
-
let
|
|
1239
|
+
let Be = L;
|
|
1240
1240
|
async function Wt(o) {
|
|
1241
|
-
const { spawn: t, exec: e } = await import("child_process"), n = await import("path"), s = o.map((
|
|
1242
|
-
name:
|
|
1243
|
-
path:
|
|
1244
|
-
id:
|
|
1245
|
-
})), i = new
|
|
1246
|
-
const
|
|
1247
|
-
let
|
|
1248
|
-
|
|
1241
|
+
const { spawn: t, exec: e } = await import("child_process"), n = await import("path"), s = o.map((c) => ({
|
|
1242
|
+
name: c.name,
|
|
1243
|
+
path: c.path,
|
|
1244
|
+
id: c.componentId || ""
|
|
1245
|
+
})), i = new Be(s), a = [], p = (c) => {
|
|
1246
|
+
const y = process.platform;
|
|
1247
|
+
let S;
|
|
1248
|
+
y === "darwin" ? S = `open "${c}"` : y === "win32" ? S = `start "" "${c}"` : S = `xdg-open "${c}"`, e(S, () => {
|
|
1249
1249
|
});
|
|
1250
1250
|
}, m = () => {
|
|
1251
1251
|
i.clear(), console.log(`
|
|
1252
|
-
🛑 Shutting down all components...`),
|
|
1252
|
+
🛑 Shutting down all components...`), a.forEach((c) => {
|
|
1253
1253
|
try {
|
|
1254
|
-
|
|
1254
|
+
c.kill("SIGTERM");
|
|
1255
1255
|
} catch {
|
|
1256
1256
|
}
|
|
1257
1257
|
}), setTimeout(() => process.exit(0), 500);
|
|
1258
1258
|
};
|
|
1259
1259
|
process.on("SIGINT", m), process.on("SIGTERM", m);
|
|
1260
|
-
const
|
|
1261
|
-
for (let
|
|
1262
|
-
const
|
|
1263
|
-
i.setStatus(
|
|
1264
|
-
const $ = t("node", [
|
|
1265
|
-
cwd: n.default.resolve(
|
|
1260
|
+
const r = process.argv[1];
|
|
1261
|
+
for (let c = 0; c < o.length; c++) {
|
|
1262
|
+
const y = o[c], S = y.name;
|
|
1263
|
+
i.setStatus(S, "⏳ Starting..."), i.log(S, `Starting in ${y.path}`);
|
|
1264
|
+
const $ = t("node", [r, "dev"], {
|
|
1265
|
+
cwd: n.default.resolve(y.path),
|
|
1266
1266
|
env: { ...process.env, FORCE_COLOR: "1", MYOP_NO_BROWSER: "1" },
|
|
1267
1267
|
stdio: ["ignore", "pipe", "pipe"]
|
|
1268
1268
|
});
|
|
1269
|
-
|
|
1270
|
-
let
|
|
1269
|
+
a.push($);
|
|
1270
|
+
let h = "";
|
|
1271
1271
|
$.stdout.on("data", (u) => {
|
|
1272
|
-
|
|
1273
|
-
const E =
|
|
1272
|
+
h += u.toString();
|
|
1273
|
+
const E = h.split(`
|
|
1274
1274
|
`);
|
|
1275
|
-
|
|
1276
|
-
for (const
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1275
|
+
h = E.pop() || "";
|
|
1276
|
+
for (const k of E) {
|
|
1277
|
+
const C = k.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "").trim();
|
|
1278
|
+
C && (C.includes("Registered component") || C.includes("Registered:") ? i.setStatus(S, "✅ Ready") : C.includes("Building...") || C.includes("Running initial build") ? i.setStatus(S, "🔨 Building...") : C.includes("Build completed") || C.includes("Build succeeded") ? i.setStatus(S, "✅ Ready") : C.includes("Build failed") ? i.setStatus(S, "❌ Build Error") : C.includes("File changed") ? (i.setStatus(S, "📝 Changed"), setTimeout(() => i.setStatus(S, "✅ Ready"), 1500)) : C.includes("Notifying") && C.includes("HMR") ? (i.setStatus(S, "🔥 HMR Update"), setTimeout(() => i.setStatus(S, "✅ Ready"), 1e3)) : C.includes("HMR client connected") && (i.setStatus(S, "🔥 HMR Connected"), setTimeout(() => i.setStatus(S, "✅ Ready"), 1e3)), !C.includes("Watching") && !C.includes("Press Ctrl+C") && !C.includes("Starting shared") && !C.includes("Management server") && !C.includes("Main server") && !C.includes("Access at:") && !C.includes("No build needed") && i.log(S, C));
|
|
1279
1279
|
}
|
|
1280
1280
|
}), $.stderr.on("data", (u) => {
|
|
1281
1281
|
const E = u.toString().split(`
|
|
1282
1282
|
`);
|
|
1283
|
-
for (const
|
|
1284
|
-
const
|
|
1285
|
-
|
|
1283
|
+
for (const k of E) {
|
|
1284
|
+
const C = k.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "").trim();
|
|
1285
|
+
C && (i.log(S, `⚠️ ${C}`), i.setStatus(S, "⚠️ Warning"));
|
|
1286
1286
|
}
|
|
1287
1287
|
}), $.on("exit", (u) => {
|
|
1288
|
-
u !== 0 && u !== null && (i.setStatus(
|
|
1289
|
-
}),
|
|
1288
|
+
u !== 0 && u !== null && (i.setStatus(S, `❌ Exited (${u})`), i.log(S, `Process exited with code ${u}`));
|
|
1289
|
+
}), c < o.length - 1 && await new Promise((u) => setTimeout(u, 500));
|
|
1290
1290
|
}
|
|
1291
1291
|
i.render(), setTimeout(() => {
|
|
1292
1292
|
p("http://localhost:9292");
|
|
@@ -1294,10 +1294,10 @@ async function Wt(o) {
|
|
|
1294
1294
|
}
|
|
1295
1295
|
const Vt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1296
1296
|
__proto__: null,
|
|
1297
|
-
devCommand:
|
|
1297
|
+
devCommand: Me,
|
|
1298
1298
|
monorepoDevCommand: Wt
|
|
1299
1299
|
}, Symbol.toStringTag, { value: "Module" })), Yt = "https://cloud.myop.dev";
|
|
1300
|
-
async function
|
|
1300
|
+
async function ut(o, t) {
|
|
1301
1301
|
const e = await fetch(o, {
|
|
1302
1302
|
headers: { Authorization: `Bearer ${t}` }
|
|
1303
1303
|
});
|
|
@@ -1307,14 +1307,14 @@ async function mt(o, t) {
|
|
|
1307
1307
|
}
|
|
1308
1308
|
return e.json();
|
|
1309
1309
|
}
|
|
1310
|
-
function
|
|
1311
|
-
const n =
|
|
1312
|
-
if (!n.startsWith(s +
|
|
1310
|
+
function me(o, t, e) {
|
|
1311
|
+
const n = _.resolve(_.join(o, t)), s = _.resolve(o);
|
|
1312
|
+
if (!n.startsWith(s + _.sep))
|
|
1313
1313
|
throw new Error(`Invalid path: "${t}" escapes output directory`);
|
|
1314
|
-
P.mkdirSync(
|
|
1314
|
+
P.mkdirSync(_.dirname(n), { recursive: !0 }), P.writeFileSync(n, JSON.stringify(e, null, 2));
|
|
1315
1315
|
}
|
|
1316
|
-
async function
|
|
1317
|
-
return
|
|
1316
|
+
async function be(o, t, e, n) {
|
|
1317
|
+
return ut(
|
|
1318
1318
|
`${o}/export?componentId=${encodeURIComponent(e)}&env=${encodeURIComponent(n)}`,
|
|
1319
1319
|
t
|
|
1320
1320
|
);
|
|
@@ -1322,20 +1322,20 @@ async function $e(o, t, e, n) {
|
|
|
1322
1322
|
async function Gt(o, t, e, n) {
|
|
1323
1323
|
let s = 0;
|
|
1324
1324
|
const i = /* @__PURE__ */ new Set();
|
|
1325
|
-
for (const
|
|
1326
|
-
const { componentId: p, environment: m } =
|
|
1325
|
+
for (const a of n) {
|
|
1326
|
+
const { componentId: p, environment: m } = a;
|
|
1327
1327
|
if (!(!p || !m)) {
|
|
1328
1328
|
try {
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1331
|
-
} catch (
|
|
1332
|
-
console.warn(` Warning: ${p}/${m}: ${
|
|
1329
|
+
const r = await be(o, t, p, m);
|
|
1330
|
+
me(e, `components/${p}/${m}.json`, r), s++;
|
|
1331
|
+
} catch (r) {
|
|
1332
|
+
console.warn(` Warning: ${p}/${m}: ${r.message}`);
|
|
1333
1333
|
}
|
|
1334
1334
|
if (!i.has(p)) {
|
|
1335
1335
|
i.add(p);
|
|
1336
1336
|
try {
|
|
1337
|
-
const
|
|
1338
|
-
|
|
1337
|
+
const r = await be(o, t, p, "preview");
|
|
1338
|
+
me(e, `components/${p}/preview.json`, r), s++;
|
|
1339
1339
|
} catch {
|
|
1340
1340
|
}
|
|
1341
1341
|
}
|
|
@@ -1344,20 +1344,20 @@ async function Gt(o, t, e, n) {
|
|
|
1344
1344
|
return s;
|
|
1345
1345
|
}
|
|
1346
1346
|
async function Kt(o, t, e) {
|
|
1347
|
-
const n = await
|
|
1348
|
-
|
|
1347
|
+
const n = await ut(`${o}/export`, t);
|
|
1348
|
+
me(e, "manifest.json", n);
|
|
1349
1349
|
let s = 0, i = 0;
|
|
1350
|
-
for (const
|
|
1351
|
-
for (const p of
|
|
1350
|
+
for (const a of n.components || []) {
|
|
1351
|
+
for (const p of a.environments || [])
|
|
1352
1352
|
try {
|
|
1353
|
-
const m = await
|
|
1354
|
-
|
|
1353
|
+
const m = await be(o, t, a.id, p);
|
|
1354
|
+
me(e, `components/${a.id}/${p}.json`, m), s++;
|
|
1355
1355
|
} catch (m) {
|
|
1356
|
-
console.warn(` Warning: ${
|
|
1356
|
+
console.warn(` Warning: ${a.id}/${p}: ${m.message}`), i++;
|
|
1357
1357
|
}
|
|
1358
1358
|
try {
|
|
1359
|
-
const p = await
|
|
1360
|
-
|
|
1359
|
+
const p = await be(o, t, a.id, "preview");
|
|
1360
|
+
me(e, `components/${a.id}/preview.json`, p), s++;
|
|
1361
1361
|
} catch {
|
|
1362
1362
|
}
|
|
1363
1363
|
}
|
|
@@ -1377,55 +1377,55 @@ function Qt() {
|
|
|
1377
1377
|
}
|
|
1378
1378
|
else o.component && o.env && (s = [{ componentId: o.component, environment: o.env }]);
|
|
1379
1379
|
if (s) {
|
|
1380
|
-
const
|
|
1380
|
+
const a = Y(`Incremental export: ${s.length} component(s)...`).start();
|
|
1381
1381
|
try {
|
|
1382
1382
|
const p = await Gt(e, t, n, s);
|
|
1383
|
-
|
|
1383
|
+
a.succeed(`Incremental export done. ${p} file(s) written to ${n}/`);
|
|
1384
1384
|
} catch (p) {
|
|
1385
|
-
|
|
1385
|
+
a.fail(`Export failed: ${p.message}`), process.exit(1);
|
|
1386
1386
|
}
|
|
1387
1387
|
} else {
|
|
1388
|
-
const
|
|
1388
|
+
const a = Y(`Full export from ${e}...`).start();
|
|
1389
1389
|
try {
|
|
1390
|
-
const { manifest: p, fileCount: m, errorCount:
|
|
1391
|
-
|
|
1392
|
-
`Full export done. ${m} file(s) from ${
|
|
1393
|
-
),
|
|
1390
|
+
const { manifest: p, fileCount: m, errorCount: r } = await Kt(e, t, n), c = ((i = p.components) == null ? void 0 : i.length) || 0;
|
|
1391
|
+
a.succeed(
|
|
1392
|
+
`Full export done. ${m} file(s) from ${c} component(s) written to ${n}/`
|
|
1393
|
+
), r > 0 && console.warn(` ${r} file(s) failed.`);
|
|
1394
1394
|
} catch (p) {
|
|
1395
|
-
|
|
1395
|
+
a.fail(`Export failed: ${p.message}`), process.exit(1);
|
|
1396
1396
|
}
|
|
1397
1397
|
}
|
|
1398
1398
|
process.exit(0);
|
|
1399
1399
|
});
|
|
1400
1400
|
}
|
|
1401
|
-
const
|
|
1401
|
+
const Je = _.join(lt.homedir(), ".myop"), fe = _.join(Je, "credentials.json");
|
|
1402
1402
|
function Zt() {
|
|
1403
|
-
P.existsSync(
|
|
1403
|
+
P.existsSync(Je) || P.mkdirSync(Je, { recursive: !0, mode: 448 });
|
|
1404
1404
|
}
|
|
1405
|
-
function
|
|
1405
|
+
function Ge() {
|
|
1406
1406
|
try {
|
|
1407
|
-
if (!P.existsSync(
|
|
1407
|
+
if (!P.existsSync(fe))
|
|
1408
1408
|
return null;
|
|
1409
|
-
const o = P.readFileSync(
|
|
1409
|
+
const o = P.readFileSync(fe, "utf8");
|
|
1410
1410
|
return JSON.parse(o);
|
|
1411
1411
|
} catch (o) {
|
|
1412
1412
|
return console.info("Failed to read credentials:", o.message), null;
|
|
1413
1413
|
}
|
|
1414
1414
|
}
|
|
1415
|
-
function
|
|
1415
|
+
function ft(o) {
|
|
1416
1416
|
Zt();
|
|
1417
1417
|
const t = {
|
|
1418
1418
|
...o,
|
|
1419
1419
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1420
1420
|
};
|
|
1421
|
-
P.writeFileSync(
|
|
1421
|
+
P.writeFileSync(fe, JSON.stringify(t, null, 2), {
|
|
1422
1422
|
mode: 384
|
|
1423
1423
|
// Read/write for owner only
|
|
1424
1424
|
});
|
|
1425
1425
|
}
|
|
1426
|
-
function
|
|
1426
|
+
function gt() {
|
|
1427
1427
|
try {
|
|
1428
|
-
return P.existsSync(
|
|
1428
|
+
return P.existsSync(fe) && P.unlinkSync(fe), !0;
|
|
1429
1429
|
} catch (o) {
|
|
1430
1430
|
return console.error("Failed to clear credentials:", o.message), !1;
|
|
1431
1431
|
}
|
|
@@ -1437,26 +1437,26 @@ function qt(o) {
|
|
|
1437
1437
|
return Date.now() > e - t;
|
|
1438
1438
|
}
|
|
1439
1439
|
function Pe() {
|
|
1440
|
-
const o =
|
|
1440
|
+
const o = Ge();
|
|
1441
1441
|
return o ? {
|
|
1442
1442
|
email: o.userEmail,
|
|
1443
1443
|
userId: o.userId
|
|
1444
1444
|
} : null;
|
|
1445
1445
|
}
|
|
1446
|
-
const
|
|
1446
|
+
const ce = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", $e = 19284, Ke = `http://localhost:${$e}/callback`, Xt = "myop-cli";
|
|
1447
1447
|
function eo() {
|
|
1448
|
-
return
|
|
1448
|
+
return Ve.randomBytes(32).toString("base64url");
|
|
1449
1449
|
}
|
|
1450
1450
|
function to(o) {
|
|
1451
|
-
return
|
|
1451
|
+
return Ve.createHash("sha256").update(o).digest("base64url");
|
|
1452
1452
|
}
|
|
1453
1453
|
async function oo() {
|
|
1454
|
-
const o = await fetch(`${
|
|
1454
|
+
const o = await fetch(`${ce}/oauth/register`, {
|
|
1455
1455
|
method: "POST",
|
|
1456
1456
|
headers: { "Content-Type": "application/json" },
|
|
1457
1457
|
body: JSON.stringify({
|
|
1458
1458
|
client_name: Xt,
|
|
1459
|
-
redirect_uris: [
|
|
1459
|
+
redirect_uris: [Ke],
|
|
1460
1460
|
grant_types: ["authorization_code", "refresh_token"],
|
|
1461
1461
|
response_types: ["code"]
|
|
1462
1462
|
})
|
|
@@ -1467,7 +1467,7 @@ async function oo() {
|
|
|
1467
1467
|
}
|
|
1468
1468
|
return o.json();
|
|
1469
1469
|
}
|
|
1470
|
-
function
|
|
1470
|
+
function xe(o, t, e, n = null) {
|
|
1471
1471
|
const s = {
|
|
1472
1472
|
success: `<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#4ade80" stroke-width="2">
|
|
1473
1473
|
<circle cx="12" cy="12" r="10"/>
|
|
@@ -1485,7 +1485,7 @@ function Se(o, t, e, n = null) {
|
|
|
1485
1485
|
success: { accent: "#4ade80", glow: "rgba(74, 222, 128, 0.1)" },
|
|
1486
1486
|
error: { accent: "#f87171", glow: "rgba(248, 113, 113, 0.1)" },
|
|
1487
1487
|
warning: { accent: "#fbbf24", glow: "rgba(251, 191, 36, 0.1)" }
|
|
1488
|
-
}, { accent:
|
|
1488
|
+
}, { accent: a, glow: p } = i[o] || i.error;
|
|
1489
1489
|
return `<!DOCTYPE html>
|
|
1490
1490
|
<html lang="en">
|
|
1491
1491
|
<head>
|
|
@@ -1546,7 +1546,7 @@ function Se(o, t, e, n = null) {
|
|
|
1546
1546
|
h1 {
|
|
1547
1547
|
font-size: 20px;
|
|
1548
1548
|
font-weight: 500;
|
|
1549
|
-
color: ${
|
|
1549
|
+
color: ${a};
|
|
1550
1550
|
margin-bottom: 12px;
|
|
1551
1551
|
letter-spacing: -0.5px;
|
|
1552
1552
|
}
|
|
@@ -1579,7 +1579,7 @@ function Se(o, t, e, n = null) {
|
|
|
1579
1579
|
align-items: center;
|
|
1580
1580
|
gap: 8px;
|
|
1581
1581
|
background: ${p};
|
|
1582
|
-
border: 1px solid ${
|
|
1582
|
+
border: 1px solid ${a}33;
|
|
1583
1583
|
border-radius: 4px;
|
|
1584
1584
|
padding: 10px 16px;
|
|
1585
1585
|
font-size: 12px;
|
|
@@ -1636,20 +1636,20 @@ function Se(o, t, e, n = null) {
|
|
|
1636
1636
|
function no(o) {
|
|
1637
1637
|
return new Promise((t, e) => {
|
|
1638
1638
|
const n = It.createServer((s, i) => {
|
|
1639
|
-
const
|
|
1640
|
-
if (
|
|
1641
|
-
const p =
|
|
1642
|
-
if (
|
|
1643
|
-
i.writeHead(200, { "Content-Type": "text/html" }), i.end(
|
|
1639
|
+
const a = new rt(s.url, `http://localhost:${$e}`);
|
|
1640
|
+
if (a.pathname === "/callback") {
|
|
1641
|
+
const p = a.searchParams.get("code"), m = a.searchParams.get("state"), r = a.searchParams.get("error");
|
|
1642
|
+
if (r) {
|
|
1643
|
+
i.writeHead(200, { "Content-Type": "text/html" }), i.end(xe(
|
|
1644
1644
|
"error",
|
|
1645
1645
|
"Authentication Failed",
|
|
1646
1646
|
"Unable to complete the authentication process.",
|
|
1647
|
-
|
|
1648
|
-
)), n.close(), e(new Error(`OAuth error: ${
|
|
1647
|
+
r
|
|
1648
|
+
)), n.close(), e(new Error(`OAuth error: ${r}`));
|
|
1649
1649
|
return;
|
|
1650
1650
|
}
|
|
1651
1651
|
if (m !== o) {
|
|
1652
|
-
i.writeHead(400, { "Content-Type": "text/html" }), i.end(
|
|
1652
|
+
i.writeHead(400, { "Content-Type": "text/html" }), i.end(xe(
|
|
1653
1653
|
"warning",
|
|
1654
1654
|
"Security Error",
|
|
1655
1655
|
"State mismatch detected. This could indicate a CSRF attack. Please try authenticating again.",
|
|
@@ -1658,7 +1658,7 @@ function no(o) {
|
|
|
1658
1658
|
return;
|
|
1659
1659
|
}
|
|
1660
1660
|
if (!p) {
|
|
1661
|
-
i.writeHead(400, { "Content-Type": "text/html" }), i.end(
|
|
1661
|
+
i.writeHead(400, { "Content-Type": "text/html" }), i.end(xe(
|
|
1662
1662
|
"error",
|
|
1663
1663
|
"Missing Authorization Code",
|
|
1664
1664
|
"No authorization code was received from the server.",
|
|
@@ -1666,7 +1666,7 @@ function no(o) {
|
|
|
1666
1666
|
)), n.close(), e(new Error("No authorization code"));
|
|
1667
1667
|
return;
|
|
1668
1668
|
}
|
|
1669
|
-
i.writeHead(200, { "Content-Type": "text/html" }), i.end(
|
|
1669
|
+
i.writeHead(200, { "Content-Type": "text/html" }), i.end(xe(
|
|
1670
1670
|
"success",
|
|
1671
1671
|
"Authentication Successful",
|
|
1672
1672
|
"You have been authenticated successfully. Return to the terminal to continue."
|
|
@@ -1674,22 +1674,22 @@ function no(o) {
|
|
|
1674
1674
|
} else
|
|
1675
1675
|
i.writeHead(404), i.end("Not found");
|
|
1676
1676
|
});
|
|
1677
|
-
n.listen(
|
|
1678
|
-
console.info(`OAuth callback server listening on port ${
|
|
1677
|
+
n.listen($e, () => {
|
|
1678
|
+
console.info(`OAuth callback server listening on port ${$e}`);
|
|
1679
1679
|
}), setTimeout(() => {
|
|
1680
1680
|
n.close(), e(new Error("Authentication timed out"));
|
|
1681
1681
|
}, 5 * 60 * 1e3);
|
|
1682
1682
|
});
|
|
1683
1683
|
}
|
|
1684
1684
|
async function so(o, t, e) {
|
|
1685
|
-
const n = await fetch(`${
|
|
1685
|
+
const n = await fetch(`${ce}/oauth/token`, {
|
|
1686
1686
|
method: "POST",
|
|
1687
1687
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1688
|
-
body: new
|
|
1688
|
+
body: new at({
|
|
1689
1689
|
grant_type: "authorization_code",
|
|
1690
1690
|
code: o,
|
|
1691
1691
|
client_id: t,
|
|
1692
|
-
redirect_uri:
|
|
1692
|
+
redirect_uri: Ke,
|
|
1693
1693
|
code_verifier: e
|
|
1694
1694
|
})
|
|
1695
1695
|
});
|
|
@@ -1700,10 +1700,10 @@ async function so(o, t, e) {
|
|
|
1700
1700
|
return n.json();
|
|
1701
1701
|
}
|
|
1702
1702
|
async function io(o, t) {
|
|
1703
|
-
const e = await fetch(`${
|
|
1703
|
+
const e = await fetch(`${ce}/oauth/token`, {
|
|
1704
1704
|
method: "POST",
|
|
1705
1705
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1706
|
-
body: new
|
|
1706
|
+
body: new at({
|
|
1707
1707
|
grant_type: "refresh_token",
|
|
1708
1708
|
refresh_token: o,
|
|
1709
1709
|
client_id: t
|
|
@@ -1716,8 +1716,8 @@ async function io(o, t) {
|
|
|
1716
1716
|
return e.json();
|
|
1717
1717
|
}
|
|
1718
1718
|
async function ro(o) {
|
|
1719
|
-
var s, i,
|
|
1720
|
-
const t = await fetch(`${
|
|
1719
|
+
var s, i, a;
|
|
1720
|
+
const t = await fetch(`${ce}/mcp`, {
|
|
1721
1721
|
method: "POST",
|
|
1722
1722
|
headers: {
|
|
1723
1723
|
"Content-Type": "application/json",
|
|
@@ -1738,60 +1738,60 @@ async function ro(o) {
|
|
|
1738
1738
|
const e = await t.json();
|
|
1739
1739
|
if (e.error)
|
|
1740
1740
|
throw new Error(e.error.message);
|
|
1741
|
-
const n = (
|
|
1741
|
+
const n = (a = (i = (s = e.result) == null ? void 0 : s.content) == null ? void 0 : i[0]) == null ? void 0 : a.text;
|
|
1742
1742
|
if (n)
|
|
1743
1743
|
return JSON.parse(n);
|
|
1744
1744
|
throw new Error("Invalid response from whoami");
|
|
1745
1745
|
}
|
|
1746
|
-
async function
|
|
1747
|
-
const o =
|
|
1746
|
+
async function ue() {
|
|
1747
|
+
const o = Y("Starting authentication...").start();
|
|
1748
1748
|
try {
|
|
1749
1749
|
o.text = "Registering OAuth client...";
|
|
1750
|
-
const e = (await oo()).client_id, n = eo(), s = to(n), i =
|
|
1750
|
+
const e = (await oo()).client_id, n = eo(), s = to(n), i = Ve.randomBytes(16).toString("hex");
|
|
1751
1751
|
o.text = "Waiting for authorization...";
|
|
1752
|
-
const
|
|
1753
|
-
p.searchParams.set("response_type", "code"), p.searchParams.set("client_id", e), p.searchParams.set("redirect_uri",
|
|
1752
|
+
const a = no(i), p = new rt(`${ce}/oauth/authorize`);
|
|
1753
|
+
p.searchParams.set("response_type", "code"), p.searchParams.set("client_id", e), p.searchParams.set("redirect_uri", Ke), p.searchParams.set("code_challenge", s), p.searchParams.set("code_challenge_method", "S256"), p.searchParams.set("state", i), o.stop(), console.log(`
|
|
1754
1754
|
🌐 Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${p.toString()}
|
|
1755
1755
|
`), await Ot(p.toString());
|
|
1756
|
-
const m = await
|
|
1756
|
+
const m = await a;
|
|
1757
1757
|
o.start("Exchanging authorization code...");
|
|
1758
|
-
const
|
|
1758
|
+
const r = await so(m, e, n);
|
|
1759
1759
|
o.text = "Getting user info...";
|
|
1760
|
-
const
|
|
1761
|
-
accessToken:
|
|
1762
|
-
refreshToken:
|
|
1763
|
-
expiresAt: new Date(Date.now() +
|
|
1760
|
+
const c = await ro(r.access_token), y = {
|
|
1761
|
+
accessToken: r.access_token,
|
|
1762
|
+
refreshToken: r.refresh_token,
|
|
1763
|
+
expiresAt: new Date(Date.now() + r.expires_in * 1e3).toISOString(),
|
|
1764
1764
|
clientId: e,
|
|
1765
|
-
userId:
|
|
1766
|
-
userEmail:
|
|
1765
|
+
userId: c.userId,
|
|
1766
|
+
userEmail: c.email
|
|
1767
1767
|
};
|
|
1768
|
-
return
|
|
1768
|
+
return ft(y), o.succeed(`Authenticated as ${c.email}`), y;
|
|
1769
1769
|
} catch (t) {
|
|
1770
1770
|
throw o.fail(`Authentication failed: ${t.message}`), t;
|
|
1771
1771
|
}
|
|
1772
1772
|
}
|
|
1773
|
-
async function
|
|
1774
|
-
const o =
|
|
1773
|
+
async function ht() {
|
|
1774
|
+
const o = Ge();
|
|
1775
1775
|
if (!o) {
|
|
1776
1776
|
console.log("Not currently logged in.");
|
|
1777
1777
|
return;
|
|
1778
1778
|
}
|
|
1779
|
-
|
|
1779
|
+
gt(), console.log(`✅ Logged out (was: ${o.userEmail})`);
|
|
1780
1780
|
}
|
|
1781
1781
|
function ao(o) {
|
|
1782
1782
|
var e, n;
|
|
1783
1783
|
const t = (o == null ? void 0 : o.message) || "";
|
|
1784
1784
|
return t.includes("ECONNREFUSED") || t.includes("ENOTFOUND") || t.includes("ETIMEDOUT") || t.includes("fetch failed") || t.includes("network") || (o == null ? void 0 : o.code) === "ECONNREFUSED" || ((e = o == null ? void 0 : o.cause) == null ? void 0 : e.code) === "ECONNREFUSED" || ((n = o == null ? void 0 : o.cause) == null ? void 0 : n.code) === "ENOTFOUND";
|
|
1785
1785
|
}
|
|
1786
|
-
async function
|
|
1787
|
-
let o =
|
|
1786
|
+
async function Qe() {
|
|
1787
|
+
let o = Ge();
|
|
1788
1788
|
if (!o)
|
|
1789
1789
|
return console.log(`Not logged in. Starting authentication...
|
|
1790
|
-
`), await
|
|
1790
|
+
`), await ue();
|
|
1791
1791
|
if (!qt(o))
|
|
1792
1792
|
return o;
|
|
1793
1793
|
if (o.refreshToken) {
|
|
1794
|
-
const t =
|
|
1794
|
+
const t = Y("Refreshing access token...").start();
|
|
1795
1795
|
try {
|
|
1796
1796
|
const e = await io(
|
|
1797
1797
|
o.refreshToken,
|
|
@@ -1802,37 +1802,37 @@ async function Ke() {
|
|
|
1802
1802
|
accessToken: e.access_token,
|
|
1803
1803
|
refreshToken: e.refresh_token,
|
|
1804
1804
|
expiresAt: new Date(Date.now() + e.expires_in * 1e3).toISOString()
|
|
1805
|
-
},
|
|
1805
|
+
}, ft(o), t.succeed("Token refreshed"), o;
|
|
1806
1806
|
} catch (e) {
|
|
1807
1807
|
if (ao(e))
|
|
1808
1808
|
throw t.fail("Network error during token refresh"), e;
|
|
1809
|
-
return t.warn("Token refresh failed, please log in again"),
|
|
1809
|
+
return t.warn("Token refresh failed, please log in again"), gt(), await ue();
|
|
1810
1810
|
}
|
|
1811
1811
|
}
|
|
1812
1812
|
return console.log(`Session expired. Please log in again.
|
|
1813
|
-
`), await
|
|
1813
|
+
`), await ue();
|
|
1814
1814
|
}
|
|
1815
|
-
function
|
|
1816
|
-
return
|
|
1815
|
+
function Ee() {
|
|
1816
|
+
return ce;
|
|
1817
1817
|
}
|
|
1818
|
-
const
|
|
1818
|
+
const te = "@myop/cli", Le = process.platform === "win32";
|
|
1819
1819
|
function lo() {
|
|
1820
1820
|
try {
|
|
1821
|
-
return
|
|
1821
|
+
return X("npm config get registry", { encoding: "utf-8" }).trim() || "https://registry.npmjs.org/";
|
|
1822
1822
|
} catch {
|
|
1823
1823
|
return "https://registry.npmjs.org/";
|
|
1824
1824
|
}
|
|
1825
1825
|
}
|
|
1826
1826
|
function co() {
|
|
1827
1827
|
try {
|
|
1828
|
-
return
|
|
1828
|
+
return X("npm config get prefix", { encoding: "utf-8" }).trim();
|
|
1829
1829
|
} catch {
|
|
1830
1830
|
return null;
|
|
1831
1831
|
}
|
|
1832
1832
|
}
|
|
1833
1833
|
async function po() {
|
|
1834
1834
|
try {
|
|
1835
|
-
const o = lo().replace(/\/$/, ""), t = await fetch(`${o}/${
|
|
1835
|
+
const o = lo().replace(/\/$/, ""), t = await fetch(`${o}/${te}/latest`);
|
|
1836
1836
|
return t.ok ? (await t.json()).version : null;
|
|
1837
1837
|
} catch {
|
|
1838
1838
|
return null;
|
|
@@ -1841,14 +1841,14 @@ async function po() {
|
|
|
1841
1841
|
function mo(o, t) {
|
|
1842
1842
|
const e = o.split(".").map(Number), n = t.split(".").map(Number);
|
|
1843
1843
|
for (let s = 0; s < Math.max(e.length, n.length); s++) {
|
|
1844
|
-
const i = e[s] || 0,
|
|
1845
|
-
if (i >
|
|
1846
|
-
if (i <
|
|
1844
|
+
const i = e[s] || 0, a = n[s] || 0;
|
|
1845
|
+
if (i > a) return 1;
|
|
1846
|
+
if (i < a) return -1;
|
|
1847
1847
|
}
|
|
1848
1848
|
return 0;
|
|
1849
1849
|
}
|
|
1850
1850
|
async function uo(o) {
|
|
1851
|
-
const t =
|
|
1851
|
+
const t = Y({
|
|
1852
1852
|
text: "Checking for updates...",
|
|
1853
1853
|
color: "cyan"
|
|
1854
1854
|
}).start(), e = await po();
|
|
@@ -1859,7 +1859,7 @@ async function uo(o) {
|
|
|
1859
1859
|
`);
|
|
1860
1860
|
let n;
|
|
1861
1861
|
try {
|
|
1862
|
-
n = await
|
|
1862
|
+
n = await it({
|
|
1863
1863
|
message: "Would you like to update now?",
|
|
1864
1864
|
choices: [
|
|
1865
1865
|
{ name: "Yes, update now", value: !0 },
|
|
@@ -1873,51 +1873,51 @@ async function uo(o) {
|
|
|
1873
1873
|
`), process.exit(0)), s;
|
|
1874
1874
|
}
|
|
1875
1875
|
if (n) {
|
|
1876
|
-
const s =
|
|
1877
|
-
text: `Updating ${
|
|
1876
|
+
const s = Y({
|
|
1877
|
+
text: `Updating ${te} to v${e}...`,
|
|
1878
1878
|
color: "green"
|
|
1879
|
-
}).start(), i = `npm install -g ${
|
|
1879
|
+
}).start(), i = `npm install -g ${te}@latest`, a = co();
|
|
1880
1880
|
try {
|
|
1881
|
-
|
|
1881
|
+
X(i, { stdio: "pipe" }), s.succeed(`Updated to v${e}`);
|
|
1882
1882
|
} catch {
|
|
1883
1883
|
s.stop(), console.log(`
|
|
1884
1884
|
🔐 Elevated permissions required.
|
|
1885
1885
|
`);
|
|
1886
1886
|
try {
|
|
1887
|
-
if (
|
|
1888
|
-
const
|
|
1889
|
-
|
|
1887
|
+
if (Le) {
|
|
1888
|
+
const c = `Start-Process -FilePath 'cmd' -ArgumentList '/c npm ${a ? `install -g ${te}@latest --prefix \\"${a}\\"` : `install -g ${te}@latest`}' -Verb RunAs -Wait`;
|
|
1889
|
+
X(`powershell -Command "${c}"`, { stdio: "inherit" });
|
|
1890
1890
|
} else {
|
|
1891
|
-
const
|
|
1892
|
-
|
|
1891
|
+
const r = a ? `sudo npm install -g ${te}@latest --prefix "${a}"` : `sudo ${i}`;
|
|
1892
|
+
X(r, { stdio: "inherit" });
|
|
1893
1893
|
}
|
|
1894
1894
|
console.log(`
|
|
1895
1895
|
✅ Updated to v${e}`);
|
|
1896
1896
|
} catch {
|
|
1897
1897
|
console.log(`
|
|
1898
1898
|
❌ Update failed`);
|
|
1899
|
-
const
|
|
1899
|
+
const c = Le ? `npm install -g ${te}@latest (run as Administrator)` : `sudo npm install -g ${te}@latest`;
|
|
1900
1900
|
console.log(`
|
|
1901
|
-
Please run manually: ${
|
|
1901
|
+
Please run manually: ${c}
|
|
1902
1902
|
`), process.exit(1);
|
|
1903
1903
|
}
|
|
1904
1904
|
}
|
|
1905
1905
|
let p = null;
|
|
1906
1906
|
try {
|
|
1907
1907
|
let m;
|
|
1908
|
-
|
|
1909
|
-
const
|
|
1910
|
-
p = JSON.parse(
|
|
1908
|
+
a ? m = Le ? De(a, "node_modules") : De(a, "lib", "node_modules") : m = X("npm root -g", { encoding: "utf-8" }).trim();
|
|
1909
|
+
const r = De(m, te, "package.json"), c = Et(r, "utf-8");
|
|
1910
|
+
p = JSON.parse(c).version;
|
|
1911
1911
|
} catch {
|
|
1912
1912
|
}
|
|
1913
1913
|
if (p === e)
|
|
1914
1914
|
return console.log(`
|
|
1915
1915
|
🔄 Restarting...
|
|
1916
|
-
`),
|
|
1916
|
+
`), Pt(process.argv[0], process.argv.slice(1), {
|
|
1917
1917
|
stdio: "inherit",
|
|
1918
1918
|
shell: !0
|
|
1919
|
-
}).on("close", (
|
|
1920
|
-
process.exit(
|
|
1919
|
+
}).on("close", (r) => {
|
|
1920
|
+
process.exit(r || 0);
|
|
1921
1921
|
}), !0;
|
|
1922
1922
|
console.log(`
|
|
1923
1923
|
Please run myop again to use the new version.
|
|
@@ -1925,15 +1925,15 @@ Please run myop again to use the new version.
|
|
|
1925
1925
|
}
|
|
1926
1926
|
return !1;
|
|
1927
1927
|
}
|
|
1928
|
-
const
|
|
1928
|
+
const ze = _.join(lt.homedir(), ".myop"), We = _.join(ze, "preferences.json");
|
|
1929
1929
|
function fo() {
|
|
1930
|
-
P.existsSync(
|
|
1930
|
+
P.existsSync(ze) || P.mkdirSync(ze, { recursive: !0, mode: 448 });
|
|
1931
1931
|
}
|
|
1932
|
-
function
|
|
1932
|
+
function yt() {
|
|
1933
1933
|
try {
|
|
1934
|
-
if (!P.existsSync(
|
|
1934
|
+
if (!P.existsSync(We))
|
|
1935
1935
|
return {};
|
|
1936
|
-
const o = P.readFileSync(
|
|
1936
|
+
const o = P.readFileSync(We, "utf8");
|
|
1937
1937
|
return JSON.parse(o);
|
|
1938
1938
|
} catch {
|
|
1939
1939
|
return {};
|
|
@@ -1941,19 +1941,19 @@ function ht() {
|
|
|
1941
1941
|
}
|
|
1942
1942
|
function go(o) {
|
|
1943
1943
|
fo();
|
|
1944
|
-
const e = { ...
|
|
1945
|
-
P.writeFileSync(
|
|
1944
|
+
const e = { ...yt(), ...o };
|
|
1945
|
+
P.writeFileSync(We, JSON.stringify(e, null, 2), {
|
|
1946
1946
|
mode: 384
|
|
1947
1947
|
});
|
|
1948
1948
|
}
|
|
1949
1949
|
function ho() {
|
|
1950
|
-
return
|
|
1950
|
+
return yt().defaultOrganization || null;
|
|
1951
1951
|
}
|
|
1952
|
-
function
|
|
1952
|
+
function Ue({ id: o, name: t }) {
|
|
1953
1953
|
go({ defaultOrganization: { id: o, name: t } });
|
|
1954
1954
|
}
|
|
1955
1955
|
async function yo(o, t, e, n = {}) {
|
|
1956
|
-
var p, m,
|
|
1956
|
+
var p, m, r;
|
|
1957
1957
|
const s = await fetch(`${o}/mcp`, {
|
|
1958
1958
|
method: "POST",
|
|
1959
1959
|
headers: {
|
|
@@ -1975,18 +1975,18 @@ async function yo(o, t, e, n = {}) {
|
|
|
1975
1975
|
const i = await s.json();
|
|
1976
1976
|
if (i.error)
|
|
1977
1977
|
throw new Error(i.error.message || "MCP error");
|
|
1978
|
-
const
|
|
1979
|
-
if (!
|
|
1978
|
+
const a = (r = (m = (p = i.result) == null ? void 0 : p.content) == null ? void 0 : m[0]) == null ? void 0 : r.text;
|
|
1979
|
+
if (!a)
|
|
1980
1980
|
throw new Error(`No content returned from ${e}`);
|
|
1981
|
-
return JSON.parse(
|
|
1981
|
+
return JSON.parse(a);
|
|
1982
1982
|
}
|
|
1983
1983
|
const wo = (o) => new Promise((t) => setTimeout(t, o));
|
|
1984
|
-
function
|
|
1984
|
+
function ae(o) {
|
|
1985
1985
|
var e, n;
|
|
1986
1986
|
const t = (o == null ? void 0 : o.message) || "";
|
|
1987
1987
|
return t.includes("ECONNREFUSED") || t.includes("ENOTFOUND") || t.includes("ETIMEDOUT") || t.includes("fetch failed") || t.includes("network") || (o == null ? void 0 : o.code) === "ECONNREFUSED" || ((e = o == null ? void 0 : o.cause) == null ? void 0 : e.code) === "ECONNREFUSED" || ((n = o == null ? void 0 : o.cause) == null ? void 0 : n.code) === "ENOTFOUND";
|
|
1988
1988
|
}
|
|
1989
|
-
function
|
|
1989
|
+
function le(o) {
|
|
1990
1990
|
console.error(`
|
|
1991
1991
|
This usually happens in sandboxed environments (Claude Web, containers)`), console.error(` where outbound HTTP is restricted.
|
|
1992
1992
|
`), console.error(" [MYOP_MCP_FALLBACK] Use Myop MCP tools instead:"), console.error(o === "push" ? " - Use the upload_component MCP tool with htmlContent parameter" : o === "pull" ? " - Use the get_component MCP tool" : " - Use list_organizations + list_components MCP tools"), console.error(" - Do NOT use presigned URL / curl flow — same network restrictions apply"), console.error("");
|
|
@@ -1994,18 +1994,18 @@ function ae(o) {
|
|
|
1994
1994
|
const vo = () => {
|
|
1995
1995
|
let o = new URL(import.meta.url).pathname;
|
|
1996
1996
|
process.platform === "win32" && o.startsWith("/") && (o = o.slice(1));
|
|
1997
|
-
const t =
|
|
1998
|
-
return
|
|
1997
|
+
const t = _.dirname(o);
|
|
1998
|
+
return _.join(t, "skills");
|
|
1999
1999
|
}, So = (o) => {
|
|
2000
2000
|
try {
|
|
2001
|
-
const t =
|
|
2001
|
+
const t = _.join(o, "package.json");
|
|
2002
2002
|
if (!P.existsSync(t)) return [];
|
|
2003
2003
|
const e = JSON.parse(P.readFileSync(t, "utf-8"));
|
|
2004
2004
|
return Object.keys({ ...e.dependencies, ...e.devDependencies });
|
|
2005
2005
|
} catch {
|
|
2006
2006
|
return [];
|
|
2007
2007
|
}
|
|
2008
|
-
},
|
|
2008
|
+
}, Ze = async (o) => {
|
|
2009
2009
|
const t = vo();
|
|
2010
2010
|
if (!P.existsSync(t))
|
|
2011
2011
|
return console.info("Skills source directory not found, skipping skills installation"), { success: !1 };
|
|
@@ -2015,31 +2015,31 @@ const vo = () => {
|
|
|
2015
2015
|
{ deps: ["@myop/vue", "vue"], skill: "myop-vue-host" },
|
|
2016
2016
|
{ deps: ["@myop/angular", "@angular/core"], skill: "myop-angular-host" },
|
|
2017
2017
|
{ deps: ["@myop/react-native", "react-native"], skill: "myop-react-native-host" }
|
|
2018
|
-
], i = s.filter(({ deps:
|
|
2019
|
-
i.length > 0 ? n.push(...i) : n.push(...s.map((
|
|
2020
|
-
const p = n.map((
|
|
2021
|
-
return
|
|
2018
|
+
], i = s.filter(({ deps: r }) => r.some((c) => e.includes(c))).map(({ skill: r }) => r), a = s.flatMap(({ deps: r }) => r.filter((c) => e.includes(c)));
|
|
2019
|
+
i.length > 0 ? n.push(...i) : n.push(...s.map((r) => r.skill));
|
|
2020
|
+
const p = n.map((r) => `--skill ${r}`).join(" "), m = `npx -y skills add "${t}" ${p} --agent '*' --copy -y`;
|
|
2021
|
+
return X(m, { cwd: o, stdio: "pipe" }), { success: !0, detected: a, skillNames: n };
|
|
2022
2022
|
} catch (e) {
|
|
2023
2023
|
return console.info("Failed to install skills:", e.message), { success: !1 };
|
|
2024
2024
|
}
|
|
2025
|
-
},
|
|
2025
|
+
}, qe = (o = ".", t = 3, e = 0) => {
|
|
2026
2026
|
const n = [];
|
|
2027
2027
|
if (e > t) return n;
|
|
2028
2028
|
try {
|
|
2029
2029
|
const s = P.readdirSync(o, { withFileTypes: !0 });
|
|
2030
2030
|
for (const i of s) {
|
|
2031
|
-
const
|
|
2031
|
+
const a = _.join(o, i.name);
|
|
2032
2032
|
if (i.isDirectory()) {
|
|
2033
2033
|
if (i.name === "node_modules" || i.name === ".git" || i.name === "dist" || i.name.startsWith("."))
|
|
2034
2034
|
continue;
|
|
2035
|
-
n.push(...
|
|
2035
|
+
n.push(...qe(a, t, e + 1));
|
|
2036
2036
|
} else if (i.name === "myop.config.json")
|
|
2037
2037
|
try {
|
|
2038
|
-
const p = P.readFileSync(
|
|
2038
|
+
const p = P.readFileSync(a, "utf-8"), m = JSON.parse(p);
|
|
2039
2039
|
n.push({
|
|
2040
2040
|
path: o,
|
|
2041
|
-
configPath:
|
|
2042
|
-
name: m.name || m.componentName ||
|
|
2041
|
+
configPath: a,
|
|
2042
|
+
name: m.name || m.componentName || _.basename(o),
|
|
2043
2043
|
componentId: m.componentId || null,
|
|
2044
2044
|
config: m
|
|
2045
2045
|
});
|
|
@@ -2051,7 +2051,7 @@ const vo = () => {
|
|
|
2051
2051
|
return n;
|
|
2052
2052
|
};
|
|
2053
2053
|
v.executionPath = process.cwd();
|
|
2054
|
-
const
|
|
2054
|
+
const Ie = (o = !1) => {
|
|
2055
2055
|
const t = v.program.getOptionValue("verbose");
|
|
2056
2056
|
t || (console.info = () => {
|
|
2057
2057
|
}), console.info("📝 verbose mode on"), v.options = {
|
|
@@ -2069,7 +2069,7 @@ const Ee = (o = !1) => {
|
|
|
2069
2069
|
author: "@myop-cli",
|
|
2070
2070
|
flows: []
|
|
2071
2071
|
};
|
|
2072
|
-
return
|
|
2072
|
+
return Ye(v.options.configPath, n), v.myopConfig = n, { configFound: !0 };
|
|
2073
2073
|
} catch {
|
|
2074
2074
|
return console.info("Error details :", e), { configFound: !1, error: e };
|
|
2075
2075
|
}
|
|
@@ -2078,36 +2078,36 @@ const Ee = (o = !1) => {
|
|
|
2078
2078
|
}
|
|
2079
2079
|
};
|
|
2080
2080
|
[
|
|
2081
|
-
new
|
|
2081
|
+
new He(),
|
|
2082
2082
|
...Lt
|
|
2083
2083
|
];
|
|
2084
|
-
const xo = "0.1.
|
|
2085
|
-
v.program = new
|
|
2084
|
+
const xo = "0.1.57";
|
|
2085
|
+
v.program = new Mt();
|
|
2086
2086
|
v.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(xo);
|
|
2087
|
-
v.program.addOption(new
|
|
2088
|
-
v.program.addOption(new
|
|
2089
|
-
v.program.addOption(new
|
|
2090
|
-
v.program.addOption(new
|
|
2091
|
-
v.program.addOption(new
|
|
2087
|
+
v.program.addOption(new ge("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
|
|
2088
|
+
v.program.addOption(new ge("-h, --help", "Show helpful information"));
|
|
2089
|
+
v.program.addOption(new ge("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
|
|
2090
|
+
v.program.addOption(new ge("--ci", "CI mode: print status info (version, config, auth) as JSON and exit without prompts"));
|
|
2091
|
+
v.program.addOption(new ge("-m, --monorepo", "Monorepo mode: scan for all myop.config.json files in nested directories"));
|
|
2092
2092
|
v.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((o, t) => {
|
|
2093
|
-
|
|
2093
|
+
Ie(!0), console.info("adding ", o, t, v.options.configPath), o === "flow" && dt._action(t), process.exit();
|
|
2094
2094
|
});
|
|
2095
2095
|
v.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((o, t) => {
|
|
2096
|
-
|
|
2096
|
+
Ie(), console.info("removing ", o, t, v.options.configPath), o === "flow" && pt._action(t), process.exit();
|
|
2097
2097
|
});
|
|
2098
2098
|
v.program.command("install").description("Install Myop assets").action(async () => {
|
|
2099
|
-
|
|
2099
|
+
Ie(), await ct.action();
|
|
2100
2100
|
});
|
|
2101
2101
|
v.program.command("login").description("Authenticate with Myop platform").action(async () => {
|
|
2102
2102
|
try {
|
|
2103
|
-
await
|
|
2103
|
+
await ue();
|
|
2104
2104
|
} catch (o) {
|
|
2105
2105
|
console.error("Login failed:", o.message), process.exit(1);
|
|
2106
2106
|
}
|
|
2107
2107
|
process.exit(0);
|
|
2108
2108
|
});
|
|
2109
2109
|
v.program.command("logout").description("Clear stored credentials").action(async () => {
|
|
2110
|
-
await
|
|
2110
|
+
await ht(), process.exit(0);
|
|
2111
2111
|
});
|
|
2112
2112
|
v.program.command("whoami").description("Show current authenticated user").action(async () => {
|
|
2113
2113
|
const o = Pe();
|
|
@@ -2125,7 +2125,7 @@ v.program.command("sync").description('[deprecated] Use "myop push" instead').op
|
|
|
2125
2125
|
process.exit(0);
|
|
2126
2126
|
});
|
|
2127
2127
|
v.program.command("push").description("Upload component to Myop platform").argument("[componentId]", "Component ID to push to (overrides myop.config.json)").action(async (o) => {
|
|
2128
|
-
var
|
|
2128
|
+
var S, $, h;
|
|
2129
2129
|
const t = v.program.getOptionValue("config") || "./myop.config.json";
|
|
2130
2130
|
let e = {};
|
|
2131
2131
|
if (P.existsSync(t))
|
|
@@ -2135,7 +2135,7 @@ v.program.command("push").description("Upload component to Myop platform").argum
|
|
|
2135
2135
|
console.error(`⚠️ Failed to parse ${t}:`, u.message);
|
|
2136
2136
|
}
|
|
2137
2137
|
o && (e.componentId = o);
|
|
2138
|
-
const n = e.name || e.componentName ||
|
|
2138
|
+
const n = e.name || e.componentName || _.basename(process.cwd());
|
|
2139
2139
|
console.log(`
|
|
2140
2140
|
📋 Component: ${n}`);
|
|
2141
2141
|
let s = null, i = !1;
|
|
@@ -2155,51 +2155,51 @@ v.program.command("push").description("Upload component to Myop platform").argum
|
|
|
2155
2155
|
else if (i) {
|
|
2156
2156
|
const { exec: u } = await import("child_process");
|
|
2157
2157
|
let E = { hasTriedPlatformFix: !1, hasTriedInstall: !1 };
|
|
2158
|
-
const
|
|
2159
|
-
const
|
|
2160
|
-
u("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (N,
|
|
2158
|
+
const k = (b = !1) => new Promise((A) => {
|
|
2159
|
+
const M = Y(b ? "Retrying build..." : "Building project...").start();
|
|
2160
|
+
u("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (N, R, U) => {
|
|
2161
2161
|
if (!N) {
|
|
2162
|
-
|
|
2162
|
+
M.succeed("Build completed"), A(!0);
|
|
2163
2163
|
return;
|
|
2164
2164
|
}
|
|
2165
|
-
if (
|
|
2166
|
-
const D = await
|
|
2165
|
+
if (M.fail("Build failed"), !E.hasTriedPlatformFix && !E.hasTriedInstall) {
|
|
2166
|
+
const D = await mt(N, R, U, u, E);
|
|
2167
2167
|
if (E = { ...E, ...D }, D.handled) {
|
|
2168
|
-
const F = await
|
|
2169
|
-
|
|
2168
|
+
const F = await k(!0);
|
|
2169
|
+
A(F);
|
|
2170
2170
|
return;
|
|
2171
2171
|
}
|
|
2172
2172
|
}
|
|
2173
|
-
console.error(N.message),
|
|
2173
|
+
console.error(N.message), A(!1);
|
|
2174
2174
|
});
|
|
2175
2175
|
});
|
|
2176
|
-
await
|
|
2176
|
+
await k() || process.exit(1);
|
|
2177
2177
|
}
|
|
2178
|
-
let
|
|
2178
|
+
let a;
|
|
2179
2179
|
if (s)
|
|
2180
|
-
|
|
2180
|
+
a = s;
|
|
2181
2181
|
else if (P.existsSync("./dist/index.html"))
|
|
2182
|
-
|
|
2182
|
+
a = "./dist/index.html";
|
|
2183
2183
|
else {
|
|
2184
2184
|
const u = P.readdirSync(".").filter(
|
|
2185
2185
|
(E) => E.endsWith(".html") && !E.startsWith(".") && P.statSync(E).isFile()
|
|
2186
2186
|
);
|
|
2187
|
-
u.length === 1 ?
|
|
2187
|
+
u.length === 1 ? a = u[0] : (console.error("❌ No HTML file found to upload."), console.log(" Expected: a single .html file in root or ./dist/index.html"), process.exit(1));
|
|
2188
2188
|
}
|
|
2189
|
-
const p = P.readFileSync(
|
|
2190
|
-
console.log(` File: ${
|
|
2189
|
+
const p = P.readFileSync(a, "utf-8");
|
|
2190
|
+
console.log(` File: ${a} (${(p.length / 1024).toFixed(1)} KB)`);
|
|
2191
2191
|
let m;
|
|
2192
2192
|
try {
|
|
2193
|
-
m = await
|
|
2193
|
+
m = await Qe();
|
|
2194
2194
|
} catch (u) {
|
|
2195
|
-
|
|
2195
|
+
ae(u) ? (console.error("❌ Network error: Unable to reach mcp.myop.dev"), le("push")) : (console.error("❌ Authentication failed:", u.message), console.error(`
|
|
2196
2196
|
[MYOP_AUTH_REQUIRED] Run 'myop login' to authenticate,`), console.error(` or use the setup_cli_auth MCP tool to set up credentials automatically.
|
|
2197
2197
|
`)), process.exit(1);
|
|
2198
2198
|
}
|
|
2199
|
-
const
|
|
2200
|
-
let
|
|
2199
|
+
const r = Ee();
|
|
2200
|
+
let c = Y("Uploading...").start(), y;
|
|
2201
2201
|
try {
|
|
2202
|
-
const u = await fetch(`${
|
|
2202
|
+
const u = await fetch(`${r}/mcp`, {
|
|
2203
2203
|
method: "POST",
|
|
2204
2204
|
headers: {
|
|
2205
2205
|
"Content-Type": "application/json",
|
|
@@ -2225,27 +2225,27 @@ v.program.command("push").description("Upload component to Myop platform").argum
|
|
|
2225
2225
|
const E = await u.json();
|
|
2226
2226
|
if (E.error)
|
|
2227
2227
|
throw new Error(E.error.message);
|
|
2228
|
-
const
|
|
2229
|
-
if (
|
|
2230
|
-
throw new Error(
|
|
2231
|
-
|
|
2228
|
+
const k = (h = ($ = (S = E.result) == null ? void 0 : S.content) == null ? void 0 : $[0]) == null ? void 0 : h.text;
|
|
2229
|
+
if (y = JSON.parse(k), !y.success)
|
|
2230
|
+
throw new Error(y.error);
|
|
2231
|
+
c.succeed("Pushed successfully");
|
|
2232
2232
|
} catch (u) {
|
|
2233
|
-
|
|
2233
|
+
c.fail("Upload failed"), ae(u) ? (console.error("❌ Network error: Unable to reach mcp.myop.dev"), le("push")) : console.error(" ", u.message), process.exit(1);
|
|
2234
2234
|
}
|
|
2235
|
-
if (
|
|
2236
|
-
e.componentId =
|
|
2235
|
+
if (y.isNewComponent || !e.componentId || e.componentId === "DEV") {
|
|
2236
|
+
e.componentId = y.componentId, e.organization = y.orgId, e.name || (e.name = y.componentName);
|
|
2237
2237
|
try {
|
|
2238
2238
|
P.writeFileSync(t, JSON.stringify(e, null, 2));
|
|
2239
2239
|
} catch (u) {
|
|
2240
|
-
console.log(`⚠️ Could not update ${t}: ${u.message}`), console.log(` Add componentId: "${
|
|
2240
|
+
console.log(`⚠️ Could not update ${t}: ${u.message}`), console.log(` Add componentId: "${y.componentId}" manually`);
|
|
2241
2241
|
}
|
|
2242
2242
|
}
|
|
2243
2243
|
console.log(`
|
|
2244
|
-
${
|
|
2244
|
+
${y.componentName}`), console.log(` ${y.dashboardUrl}
|
|
2245
2245
|
`), process.exit(0);
|
|
2246
2246
|
});
|
|
2247
2247
|
v.program.command("pull").description("Download component HTML from Myop platform").argument("[componentId]", "Component ID to pull (overrides myop.config.json)").option("-o, --output <path>", "Output file path (default: index.html or dist/index.html)").option("-e, --env <environment>", "Pull the variant released to this environment (e.g., staging, production)").action(async (o, t) => {
|
|
2248
|
-
var
|
|
2248
|
+
var U, D, F;
|
|
2249
2249
|
const e = v.program.getOptionValue("config") || "./myop.config.json";
|
|
2250
2250
|
let n = {};
|
|
2251
2251
|
if (P.existsSync(e))
|
|
@@ -2256,24 +2256,22 @@ v.program.command("pull").description("Download component HTML from Myop platfor
|
|
|
2256
2256
|
const s = o || n.componentId;
|
|
2257
2257
|
(!s || s === "DEV") && (console.error("❌ No component ID provided."), console.log(" Pass a component ID: myop pull <componentId>"), console.log(" Or ensure myop.config.json has a valid componentId."), process.exit(1));
|
|
2258
2258
|
const i = n.name || n.componentName || s;
|
|
2259
|
-
|
|
2260
|
-
📥 Pulling: ${i}`), console.log(` ID: ${s}`), t.env && console.log(` Environment: ${t.env}`);
|
|
2261
|
-
let r;
|
|
2259
|
+
let a;
|
|
2262
2260
|
try {
|
|
2263
|
-
|
|
2264
|
-
} catch (
|
|
2265
|
-
|
|
2261
|
+
a = await Qe();
|
|
2262
|
+
} catch (T) {
|
|
2263
|
+
ae(T) ? (console.error("❌ Network error: Unable to reach mcp.myop.dev"), le("pull")) : (console.error("❌ Authentication failed:", T.message), console.error(`
|
|
2266
2264
|
[MYOP_AUTH_REQUIRED] Run 'myop login' to authenticate,`), console.error(` or use the setup_cli_auth MCP tool to set up credentials automatically.
|
|
2267
2265
|
`)), process.exit(1);
|
|
2268
2266
|
}
|
|
2269
|
-
const p =
|
|
2270
|
-
let
|
|
2267
|
+
const p = Ee(), m = Y("Fetching component...").start();
|
|
2268
|
+
let r;
|
|
2271
2269
|
try {
|
|
2272
|
-
const
|
|
2270
|
+
const T = await fetch(`${p}/mcp`, {
|
|
2273
2271
|
method: "POST",
|
|
2274
2272
|
headers: {
|
|
2275
2273
|
"Content-Type": "application/json",
|
|
2276
|
-
Authorization: `Bearer ${
|
|
2274
|
+
Authorization: `Bearer ${a.accessToken}`
|
|
2277
2275
|
},
|
|
2278
2276
|
body: JSON.stringify({
|
|
2279
2277
|
jsonrpc: "2.0",
|
|
@@ -2285,68 +2283,96 @@ v.program.command("pull").description("Download component HTML from Myop platfor
|
|
|
2285
2283
|
}
|
|
2286
2284
|
})
|
|
2287
2285
|
});
|
|
2288
|
-
if (!
|
|
2289
|
-
throw new Error(`Server returned ${
|
|
2290
|
-
const
|
|
2291
|
-
if (
|
|
2292
|
-
throw new Error(
|
|
2293
|
-
const
|
|
2294
|
-
|
|
2295
|
-
} catch (
|
|
2296
|
-
m.fail("Failed to fetch component"),
|
|
2297
|
-
}
|
|
2298
|
-
let
|
|
2299
|
-
|
|
2300
|
-
const
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2286
|
+
if (!T.ok)
|
|
2287
|
+
throw new Error(`Server returned ${T.status}`);
|
|
2288
|
+
const O = await T.json();
|
|
2289
|
+
if (O.error)
|
|
2290
|
+
throw new Error(O.error.message);
|
|
2291
|
+
const z = (F = (D = (U = O.result) == null ? void 0 : U.content) == null ? void 0 : D[0]) == null ? void 0 : F.text;
|
|
2292
|
+
r = JSON.parse(z), !r.success && !r.html && (m.fail("Failed to fetch component"), console.error(" ", r.error || "No HTML content returned"), r.message && console.error(" ", r.message), process.exit(1)), m.succeed("Component fetched");
|
|
2293
|
+
} catch (T) {
|
|
2294
|
+
m.fail("Failed to fetch component"), ae(T) ? (console.error("❌ Network error: Unable to reach mcp.myop.dev"), le("pull")) : console.error(" ", T.message), process.exit(1);
|
|
2295
|
+
}
|
|
2296
|
+
let c = t.output;
|
|
2297
|
+
c || (P.existsSync("./dist/index.html") ? c = "./dist/index.html" : c = "./index.html");
|
|
2298
|
+
const y = r.htmlContent || r.html;
|
|
2299
|
+
let S = [];
|
|
2300
|
+
P.existsSync(c) && (S = P.readFileSync(c, "utf-8").split(`
|
|
2301
|
+
`));
|
|
2302
|
+
const $ = y.split(`
|
|
2303
|
+
`), h = _.dirname(c);
|
|
2304
|
+
h && !P.existsSync(h) && P.mkdirSync(h, { recursive: !0 }), P.writeFileSync(c, y);
|
|
2305
|
+
const u = P.existsSync(e);
|
|
2306
|
+
let E = !1;
|
|
2307
|
+
if (u ? ((!n.componentId || n.componentId === "DEV") && (n.componentId = s, E = !0), !n.name && r.name && (n.name = r.name, E = !0)) : (n = {
|
|
2308
|
+
name: r.name || _.basename(process.cwd()),
|
|
2306
2309
|
componentId: s,
|
|
2307
2310
|
type: "html",
|
|
2308
2311
|
author: "@myop-cli",
|
|
2309
2312
|
HMR: !0
|
|
2310
|
-
},
|
|
2313
|
+
}, E = !0), E)
|
|
2311
2314
|
try {
|
|
2312
|
-
P.writeFileSync(e, JSON.stringify(n, null, 2))
|
|
2313
|
-
} catch
|
|
2314
|
-
console.log(` ⚠️ Could not write ${e}: ${b.message}`);
|
|
2315
|
+
P.writeFileSync(e, JSON.stringify(n, null, 2));
|
|
2316
|
+
} catch {
|
|
2315
2317
|
}
|
|
2318
|
+
const k = (T) => {
|
|
2319
|
+
if (!T) return "";
|
|
2320
|
+
const O = Math.floor((Date.now() - new Date(T).getTime()) / 1e3);
|
|
2321
|
+
if (O < 60) return "just now";
|
|
2322
|
+
const z = Math.floor(O / 60);
|
|
2323
|
+
if (z < 60) return `${z} minute${z !== 1 ? "s" : ""} ago`;
|
|
2324
|
+
const ee = Math.floor(z / 60);
|
|
2325
|
+
if (ee < 24) return `${ee} hour${ee !== 1 ? "s" : ""} ago`;
|
|
2326
|
+
const W = Math.floor(ee / 24);
|
|
2327
|
+
return `${W} day${W !== 1 ? "s" : ""} ago`;
|
|
2328
|
+
}, C = r.latestVariant, b = r.component || r, A = (b == null ? void 0 : b.name) || i, M = t.env ? ` [${t.env}]` : "";
|
|
2316
2329
|
console.log(`
|
|
2317
|
-
|
|
2318
|
-
|
|
2330
|
+
From myop.dev (${A})${M}`), C != null && C.name ? console.log(` * variant ${C.name} -> ${c}`) : console.log(` * -> ${c}`);
|
|
2331
|
+
const N = (C == null ? void 0 : C.updatedBy) || (b == null ? void 0 : b.updatedBy), R = (C == null ? void 0 : C.updatedOn) || (b == null ? void 0 : b.updatedOn);
|
|
2332
|
+
if (N || R) {
|
|
2333
|
+
const T = [N, k(R)].filter(Boolean);
|
|
2334
|
+
console.log(` author ${T.join(", ")}`);
|
|
2335
|
+
}
|
|
2336
|
+
if (S.length > 0 && S.join(`
|
|
2337
|
+
`) === y)
|
|
2338
|
+
console.log("Already up to date.");
|
|
2339
|
+
else if (S.length > 0) {
|
|
2340
|
+
const T = Math.max(0, $.length - S.length), O = Math.max(0, S.length - $.length), z = Math.abs($.length - S.length), W = z > 0 ? Math.min(1, 20 / z) : 0, oe = Math.round(T * W) || (T > 0 ? 1 : 0), Q = Math.round(O * W) || (O > 0 ? 1 : 0), Oe = "\x1B[32m" + "+".repeat(oe) + "\x1B[31m" + "-".repeat(Q) + "\x1B[0m";
|
|
2341
|
+
console.log(` ${_.basename(c)} | ${Oe}`), console.log(` 1 file changed, \x1B[32m+${T}\x1B[0m \x1B[31m-${O}\x1B[0m lines`);
|
|
2342
|
+
} else
|
|
2343
|
+
console.log(` ${_.basename(c)} (new file, ${$.length} lines)`);
|
|
2344
|
+
console.log(""), process.exit(0);
|
|
2319
2345
|
});
|
|
2320
2346
|
v.program.command("list").description("Browse and pull/push remote components").option("--org <orgId>", "Organization ID to use").action(async (o) => {
|
|
2321
2347
|
const { search: t, select: e } = await import("@inquirer/prompts");
|
|
2322
2348
|
let n;
|
|
2323
2349
|
try {
|
|
2324
|
-
n = await
|
|
2325
|
-
} catch (
|
|
2326
|
-
|
|
2350
|
+
n = await Qe();
|
|
2351
|
+
} catch (h) {
|
|
2352
|
+
ae(h) ? (console.error("❌ Network error: Unable to reach mcp.myop.dev"), le("list")) : (console.error("❌ Authentication failed:", h.message), console.error(`
|
|
2327
2353
|
[MYOP_AUTH_REQUIRED] Run 'myop login' to authenticate,`), console.error(` or use the setup_cli_auth MCP tool to set up credentials automatically.
|
|
2328
2354
|
`)), process.exit(1);
|
|
2329
2355
|
}
|
|
2330
|
-
const s =
|
|
2331
|
-
let
|
|
2356
|
+
const s = Ee(), i = (h, u) => yo(s, n.accessToken, h, u);
|
|
2357
|
+
let a = Y("Loading organizations...").start(), p;
|
|
2332
2358
|
try {
|
|
2333
|
-
const
|
|
2334
|
-
if (p =
|
|
2359
|
+
const h = await i("list_organizations");
|
|
2360
|
+
if (p = h.organizations || h, !Array.isArray(p))
|
|
2335
2361
|
throw new Error("Unexpected response from list_organizations");
|
|
2336
|
-
} catch (
|
|
2337
|
-
|
|
2362
|
+
} catch (h) {
|
|
2363
|
+
a.fail("Failed to load organizations"), ae(h) ? (console.error("❌ Network error: Unable to reach mcp.myop.dev"), le("list")) : console.error(" ", h.message), process.exit(1);
|
|
2338
2364
|
}
|
|
2339
|
-
p.length === 0 && (
|
|
2340
|
-
let m,
|
|
2365
|
+
p.length === 0 && (a.fail("No organizations found for this account"), process.exit(1)), a.stop();
|
|
2366
|
+
let m, r;
|
|
2341
2367
|
if (o.org) {
|
|
2342
|
-
const
|
|
2343
|
-
|
|
2368
|
+
const h = p.find((u) => u.id === o.org || u._id === o.org);
|
|
2369
|
+
h || (console.error(`Organization "${o.org}" not found. Available:`), p.forEach((u) => console.log(` ${u.id || u._id} ${u.name}`)), process.exit(1)), m = h.id || h._id, r = h.name, Ue({ id: m, name: r });
|
|
2344
2370
|
} else {
|
|
2345
|
-
const
|
|
2346
|
-
if (
|
|
2347
|
-
m =
|
|
2371
|
+
const h = ho();
|
|
2372
|
+
if (h && p.find((u) => (u.id || u._id) === h.id))
|
|
2373
|
+
m = h.id, r = h.name;
|
|
2348
2374
|
else if (p.length === 1)
|
|
2349
|
-
m = p[0].id || p[0]._id,
|
|
2375
|
+
m = p[0].id || p[0]._id, r = p[0].name, Ue({ id: m, name: r });
|
|
2350
2376
|
else
|
|
2351
2377
|
try {
|
|
2352
2378
|
const u = await e({
|
|
@@ -2356,7 +2382,7 @@ v.program.command("list").description("Browse and pull/push remote components").
|
|
|
2356
2382
|
value: { id: E.id || E._id, name: E.name }
|
|
2357
2383
|
}))
|
|
2358
2384
|
});
|
|
2359
|
-
m = u.id,
|
|
2385
|
+
m = u.id, r = u.name, Ue({ id: m, name: r });
|
|
2360
2386
|
} catch (u) {
|
|
2361
2387
|
throw u.name === "ExitPromptError" && (console.log(`
|
|
2362
2388
|
|
|
@@ -2364,146 +2390,146 @@ v.program.command("list").description("Browse and pull/push remote components").
|
|
|
2364
2390
|
`), process.exit(0)), u;
|
|
2365
2391
|
}
|
|
2366
2392
|
}
|
|
2367
|
-
console.log(` Using organization: ${
|
|
2368
|
-
let
|
|
2393
|
+
console.log(` Using organization: ${r}`), a = Y("Loading components...").start();
|
|
2394
|
+
let c;
|
|
2369
2395
|
try {
|
|
2370
|
-
const
|
|
2371
|
-
if (
|
|
2396
|
+
const h = await i("list_components", { organizationId: m });
|
|
2397
|
+
if (c = h.components || h, !Array.isArray(c))
|
|
2372
2398
|
throw new Error("Unexpected response from list_components");
|
|
2373
|
-
} catch (
|
|
2374
|
-
|
|
2399
|
+
} catch (h) {
|
|
2400
|
+
a.fail("Failed to load components"), console.error(" ", h.message), process.exit(1);
|
|
2375
2401
|
}
|
|
2376
|
-
|
|
2377
|
-
`), process.exit(0)), console.log(` ${
|
|
2402
|
+
a.stop(), c.length === 0 && (console.log(` No components found in this organization.
|
|
2403
|
+
`), process.exit(0)), console.log(` ${r} - ${c.length} component(s)
|
|
2378
2404
|
`);
|
|
2379
|
-
const
|
|
2405
|
+
const y = [];
|
|
2380
2406
|
for (; ; ) {
|
|
2381
|
-
const
|
|
2382
|
-
let
|
|
2407
|
+
const h = `[Done - pull/push ${y.length} selected]`, u = "__done__", E = new Set(y.map((b) => b.id || b._id || b.componentId));
|
|
2408
|
+
let k;
|
|
2383
2409
|
try {
|
|
2384
|
-
|
|
2410
|
+
k = await t({
|
|
2385
2411
|
message: "Search & select components:",
|
|
2386
|
-
source: (
|
|
2387
|
-
const
|
|
2388
|
-
const
|
|
2389
|
-
return E.has(
|
|
2412
|
+
source: (b) => {
|
|
2413
|
+
const A = (b || "").toLowerCase(), M = c.filter((R) => {
|
|
2414
|
+
const U = R.id || R._id || R.componentId;
|
|
2415
|
+
return E.has(U) ? !1 : A ? (R.name || "").toLowerCase().includes(A) : !0;
|
|
2390
2416
|
}), N = [
|
|
2391
|
-
{ name:
|
|
2417
|
+
{ name: h, value: u }
|
|
2392
2418
|
];
|
|
2393
|
-
for (const
|
|
2394
|
-
const
|
|
2419
|
+
for (const R of M) {
|
|
2420
|
+
const U = R.id || R._id || R.componentId, D = U ? U.substring(0, 8) + "..." : "";
|
|
2395
2421
|
N.push({
|
|
2396
|
-
name: `${
|
|
2397
|
-
value:
|
|
2422
|
+
name: `${R.name} (${D})`,
|
|
2423
|
+
value: U
|
|
2398
2424
|
});
|
|
2399
2425
|
}
|
|
2400
2426
|
return N;
|
|
2401
2427
|
}
|
|
2402
2428
|
});
|
|
2403
|
-
} catch (
|
|
2404
|
-
throw
|
|
2429
|
+
} catch (b) {
|
|
2430
|
+
throw b.name === "ExitPromptError" && (console.log(`
|
|
2405
2431
|
|
|
2406
2432
|
👋 Goodbye!
|
|
2407
|
-
`), process.exit(0)),
|
|
2433
|
+
`), process.exit(0)), b;
|
|
2408
2434
|
}
|
|
2409
|
-
if (
|
|
2435
|
+
if (k === u)
|
|
2410
2436
|
break;
|
|
2411
|
-
const
|
|
2412
|
-
|
|
2437
|
+
const C = c.find((b) => (b.id || b._id || b.componentId) === k);
|
|
2438
|
+
C && (y.push(C), console.log(` + ${C.name}`));
|
|
2413
2439
|
}
|
|
2414
|
-
|
|
2440
|
+
y.length === 0 && (console.log(` No components selected.
|
|
2415
2441
|
`), process.exit(0));
|
|
2416
|
-
let
|
|
2442
|
+
let S;
|
|
2417
2443
|
try {
|
|
2418
|
-
|
|
2419
|
-
message: `${
|
|
2444
|
+
S = await e({
|
|
2445
|
+
message: `${y.length} component(s) selected:`,
|
|
2420
2446
|
choices: [
|
|
2421
2447
|
{ name: "Pull selected", value: "pull" },
|
|
2422
2448
|
{ name: "Push selected", value: "push" },
|
|
2423
2449
|
{ name: "Cancel", value: "cancel" }
|
|
2424
2450
|
]
|
|
2425
2451
|
});
|
|
2426
|
-
} catch (
|
|
2427
|
-
throw
|
|
2452
|
+
} catch (h) {
|
|
2453
|
+
throw h.name === "ExitPromptError" && (console.log(`
|
|
2428
2454
|
|
|
2429
2455
|
👋 Goodbye!
|
|
2430
|
-
`), process.exit(0)),
|
|
2456
|
+
`), process.exit(0)), h;
|
|
2431
2457
|
}
|
|
2432
|
-
|
|
2458
|
+
S === "cancel" && (console.log(` Cancelled.
|
|
2433
2459
|
`), process.exit(0));
|
|
2434
|
-
const $ = (
|
|
2435
|
-
if (
|
|
2460
|
+
const $ = (h) => h.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
2461
|
+
if (S === "pull") {
|
|
2436
2462
|
console.log(`
|
|
2437
|
-
Pulling ${
|
|
2463
|
+
Pulling ${y.length} components...
|
|
2438
2464
|
`);
|
|
2439
|
-
const
|
|
2440
|
-
const
|
|
2465
|
+
const h = await Promise.all(y.map(async (k) => {
|
|
2466
|
+
const C = k.id || k._id || k.componentId;
|
|
2441
2467
|
try {
|
|
2442
|
-
const
|
|
2443
|
-
P.mkdirSync(
|
|
2444
|
-
const
|
|
2445
|
-
if (!
|
|
2468
|
+
const b = await i("get_component", { componentId: C }), A = $(k.name);
|
|
2469
|
+
P.mkdirSync(A, { recursive: !0 });
|
|
2470
|
+
const M = b.htmlContent || b.html;
|
|
2471
|
+
if (!M)
|
|
2446
2472
|
throw new Error("No HTML content returned");
|
|
2447
|
-
return P.writeFileSync(
|
|
2448
|
-
name:
|
|
2449
|
-
componentId:
|
|
2473
|
+
return P.writeFileSync(_.join(A, "index.html"), M), P.writeFileSync(_.join(A, "myop.config.json"), JSON.stringify({
|
|
2474
|
+
name: k.name,
|
|
2475
|
+
componentId: C,
|
|
2450
2476
|
organization: m,
|
|
2451
2477
|
type: "html",
|
|
2452
2478
|
author: "@myop-cli",
|
|
2453
2479
|
HMR: !0
|
|
2454
|
-
}, null, 2)), { name:
|
|
2455
|
-
} catch (
|
|
2456
|
-
return { name:
|
|
2480
|
+
}, null, 2)), { name: k.name, status: "ok", dir: A };
|
|
2481
|
+
} catch (b) {
|
|
2482
|
+
return { name: k.name, status: "failed", error: b.message };
|
|
2457
2483
|
}
|
|
2458
2484
|
}));
|
|
2459
2485
|
let u = 0, E = 0;
|
|
2460
|
-
for (const
|
|
2461
|
-
|
|
2486
|
+
for (const k of h)
|
|
2487
|
+
k.status === "ok" ? (console.log(` \x1B[32m✔\x1B[0m ${k.name} -> ./${k.dir}/`), u++) : (console.log(` \x1B[31m✖\x1B[0m ${k.name} - ${k.error}`), E++);
|
|
2462
2488
|
console.log(`
|
|
2463
2489
|
Done! Pulled ${u} component${u !== 1 ? "s" : ""}.${E ? ` ${E} failed.` : ""}
|
|
2464
2490
|
`);
|
|
2465
|
-
} else if (
|
|
2491
|
+
} else if (S === "push") {
|
|
2466
2492
|
console.log(`
|
|
2467
|
-
Pushing ${
|
|
2493
|
+
Pushing ${y.length} components...
|
|
2468
2494
|
`);
|
|
2469
|
-
const
|
|
2470
|
-
const
|
|
2471
|
-
if (!
|
|
2472
|
-
return { name:
|
|
2495
|
+
const h = qe(".", 3), u = await Promise.all(y.map(async (b) => {
|
|
2496
|
+
const A = b.id || b._id || b.componentId, M = h.find((N) => N.componentId === A);
|
|
2497
|
+
if (!M)
|
|
2498
|
+
return { name: b.name, status: "skipped", reason: "no local match" };
|
|
2473
2499
|
try {
|
|
2474
2500
|
let N;
|
|
2475
|
-
const
|
|
2476
|
-
if (P.existsSync(
|
|
2477
|
-
N =
|
|
2501
|
+
const R = M.path;
|
|
2502
|
+
if (P.existsSync(_.join(R, "dist", "index.html")))
|
|
2503
|
+
N = _.join(R, "dist", "index.html");
|
|
2478
2504
|
else {
|
|
2479
|
-
const
|
|
2480
|
-
(
|
|
2505
|
+
const T = P.readdirSync(R).filter(
|
|
2506
|
+
(O) => O.endsWith(".html") && !O.startsWith(".") && P.statSync(_.join(R, O)).isFile()
|
|
2481
2507
|
);
|
|
2482
|
-
if (
|
|
2483
|
-
N =
|
|
2484
|
-
else if (
|
|
2485
|
-
N =
|
|
2508
|
+
if (T.length === 1)
|
|
2509
|
+
N = _.join(R, T[0]);
|
|
2510
|
+
else if (T.includes("index.html"))
|
|
2511
|
+
N = _.join(R, "index.html");
|
|
2486
2512
|
else
|
|
2487
2513
|
throw new Error("No HTML file found");
|
|
2488
2514
|
}
|
|
2489
|
-
const
|
|
2515
|
+
const U = P.readFileSync(N, "utf-8"), D = M.name || b.name, F = await i("upload_component", {
|
|
2490
2516
|
name: D,
|
|
2491
|
-
componentId:
|
|
2517
|
+
componentId: A,
|
|
2492
2518
|
organization: m,
|
|
2493
|
-
htmlContent:
|
|
2519
|
+
htmlContent: U
|
|
2494
2520
|
});
|
|
2495
2521
|
if (!F.success)
|
|
2496
2522
|
throw new Error(F.error || "Upload failed");
|
|
2497
2523
|
return { name: D, status: "ok" };
|
|
2498
2524
|
} catch (N) {
|
|
2499
|
-
return { name:
|
|
2525
|
+
return { name: b.name, status: "failed", error: N.message };
|
|
2500
2526
|
}
|
|
2501
2527
|
}));
|
|
2502
|
-
let E = 0,
|
|
2503
|
-
for (const
|
|
2504
|
-
|
|
2528
|
+
let E = 0, k = 0, C = 0;
|
|
2529
|
+
for (const b of u)
|
|
2530
|
+
b.status === "ok" ? (console.log(` \x1B[32m✔\x1B[0m ${b.name}`), E++) : b.status === "skipped" ? (console.log(` \x1B[33m⊘\x1B[0m ${b.name} (${b.reason})`), k++) : (console.log(` \x1B[31m✖\x1B[0m ${b.name} - ${b.error}`), C++);
|
|
2505
2531
|
console.log(`
|
|
2506
|
-
Done! Pushed ${E}${
|
|
2532
|
+
Done! Pushed ${E}${k ? `, skipped ${k}` : ""}${C ? `, ${C} failed` : ""}.
|
|
2507
2533
|
`);
|
|
2508
2534
|
}
|
|
2509
2535
|
process.exit(0);
|
|
@@ -2532,7 +2558,7 @@ v.program.command("create").description("Create a new Myop HTML component and st
|
|
|
2532
2558
|
HMR: !0
|
|
2533
2559
|
};
|
|
2534
2560
|
t.writeFileSync("myop.config.json", JSON.stringify(i, null, 2));
|
|
2535
|
-
const
|
|
2561
|
+
const a = `<!DOCTYPE html>
|
|
2536
2562
|
<html lang="en">
|
|
2537
2563
|
<head>
|
|
2538
2564
|
<meta charset="UTF-8">
|
|
@@ -2654,24 +2680,24 @@ v.program.command("create").description("Create a new Myop HTML component and st
|
|
|
2654
2680
|
<\/script>
|
|
2655
2681
|
</body>
|
|
2656
2682
|
</html>`;
|
|
2657
|
-
t.writeFileSync("index.html",
|
|
2658
|
-
const p = await
|
|
2683
|
+
t.writeFileSync("index.html", a);
|
|
2684
|
+
const p = await Ze(process.cwd());
|
|
2659
2685
|
console.log(`
|
|
2660
|
-
✅ Created ${s}`), console.log(" index.html"), console.log(" myop.config.json"), p.success && console.log(" AI agent skills installed"), console.log(""), await
|
|
2686
|
+
✅ Created ${s}`), console.log(" index.html"), console.log(" myop.config.json"), p.success && console.log(" AI agent skills installed"), console.log(""), await Me();
|
|
2661
2687
|
});
|
|
2662
|
-
v.program.command("dev").description("Start development server with file watching").action(
|
|
2663
|
-
const
|
|
2664
|
-
const o = process.cwd(), t =
|
|
2688
|
+
v.program.command("dev").description("Start development server with file watching").action(Me);
|
|
2689
|
+
const wt = async () => {
|
|
2690
|
+
const o = process.cwd(), t = Y("Installing AI agent skills...").start(), e = await Ze(o);
|
|
2665
2691
|
e.success ? (t.succeed("AI agent skills installed"), e.detected.length > 0 && console.log(` Detected: ${e.detected.join(", ")}`), console.log(` Skills: ${e.skillNames.join(", ")}`)) : t.fail("Failed to install skills"), process.exit(e.success ? 0 : 1);
|
|
2666
2692
|
};
|
|
2667
|
-
v.program.command("skill").description("Install or update AI agent skills in the current directory").action(
|
|
2668
|
-
v.program.command("train").description("Install or update AI agent skills in the current directory (alias for skill)").action(
|
|
2693
|
+
v.program.command("skill").description("Install or update AI agent skills in the current directory").action(wt);
|
|
2694
|
+
v.program.command("train").description("Install or update AI agent skills in the current directory (alias for skill)").action(wt);
|
|
2669
2695
|
v.program.command("mcp").description("Configure Myop MCP server for your AI coding assistant").action(async () => {
|
|
2670
|
-
const { select: o, confirm: t } = await import("@inquirer/prompts"), n = (await import("os")).homedir(), s =
|
|
2696
|
+
const { select: o, confirm: t } = await import("@inquirer/prompts"), n = (await import("os")).homedir(), s = Ee() + "/mcp", i = [
|
|
2671
2697
|
{
|
|
2672
2698
|
name: "Claude Code",
|
|
2673
2699
|
value: "claude",
|
|
2674
|
-
configPath:
|
|
2700
|
+
configPath: _.join(n, ".claude.json"),
|
|
2675
2701
|
getEntry: () => ({ type: "http", url: s }),
|
|
2676
2702
|
nextSteps: [
|
|
2677
2703
|
"Restart Claude Code to pick up the new MCP config.",
|
|
@@ -2683,7 +2709,7 @@ v.program.command("mcp").description("Configure Myop MCP server for your AI codi
|
|
|
2683
2709
|
{
|
|
2684
2710
|
name: "Cursor",
|
|
2685
2711
|
value: "cursor",
|
|
2686
|
-
configPath:
|
|
2712
|
+
configPath: _.join(n, ".cursor", "mcp.json"),
|
|
2687
2713
|
getEntry: () => ({ url: s }),
|
|
2688
2714
|
nextSteps: [
|
|
2689
2715
|
'Go to Cursor Settings > Tools & MCP to verify "myop" appears.',
|
|
@@ -2696,7 +2722,7 @@ v.program.command("mcp").description("Configure Myop MCP server for your AI codi
|
|
|
2696
2722
|
{
|
|
2697
2723
|
name: "Windsurf",
|
|
2698
2724
|
value: "windsurf",
|
|
2699
|
-
configPath:
|
|
2725
|
+
configPath: _.join(n, ".codeium", "windsurf", "mcp_config.json"),
|
|
2700
2726
|
getEntry: () => ({ url: s }),
|
|
2701
2727
|
nextSteps: [
|
|
2702
2728
|
"Open Cascade and click the hammer icon (top-right) to see MCP servers.",
|
|
@@ -2708,7 +2734,7 @@ v.program.command("mcp").description("Configure Myop MCP server for your AI codi
|
|
|
2708
2734
|
{
|
|
2709
2735
|
name: "VS Code (GitHub Copilot)",
|
|
2710
2736
|
value: "vscode",
|
|
2711
|
-
configPath: process.platform === "darwin" ?
|
|
2737
|
+
configPath: process.platform === "darwin" ? _.join(n, "Library", "Application Support", "Code", "User", "mcp.json") : process.platform === "win32" ? _.join(process.env.APPDATA || _.join(n, "AppData", "Roaming"), "Code", "User", "mcp.json") : _.join(n, ".config", "Code", "User", "mcp.json"),
|
|
2712
2738
|
getEntry: () => ({ type: "http", url: s }),
|
|
2713
2739
|
nextSteps: [
|
|
2714
2740
|
"Requires VS Code 1.99+ and GitHub Copilot extension.",
|
|
@@ -2723,64 +2749,64 @@ v.program.command("mcp").description("Configure Myop MCP server for your AI codi
|
|
|
2723
2749
|
console.log(`
|
|
2724
2750
|
Configure Myop MCP server for your AI coding assistant.
|
|
2725
2751
|
`);
|
|
2726
|
-
let
|
|
2752
|
+
let a;
|
|
2727
2753
|
try {
|
|
2728
|
-
|
|
2754
|
+
a = await o({
|
|
2729
2755
|
message: "Select your AI coding assistant:",
|
|
2730
|
-
choices: i.map((
|
|
2756
|
+
choices: i.map((c) => ({ name: c.name, value: c.value }))
|
|
2731
2757
|
});
|
|
2732
|
-
} catch (
|
|
2733
|
-
throw
|
|
2758
|
+
} catch (c) {
|
|
2759
|
+
throw c.name === "ExitPromptError" && (console.log(`
|
|
2734
2760
|
|
|
2735
2761
|
👋 Goodbye!
|
|
2736
|
-
`), process.exit(0)),
|
|
2762
|
+
`), process.exit(0)), c;
|
|
2737
2763
|
}
|
|
2738
|
-
const p = i.find((
|
|
2764
|
+
const p = i.find((c) => c.value === a);
|
|
2739
2765
|
let m = {};
|
|
2740
2766
|
try {
|
|
2741
|
-
const
|
|
2742
|
-
m = JSON.parse(
|
|
2767
|
+
const c = P.readFileSync(p.configPath, "utf-8");
|
|
2768
|
+
m = JSON.parse(c);
|
|
2743
2769
|
} catch {
|
|
2744
2770
|
}
|
|
2745
2771
|
m.mcpServers || (m.mcpServers = {});
|
|
2746
|
-
const
|
|
2747
|
-
if (
|
|
2772
|
+
const r = m.mcpServers.myop;
|
|
2773
|
+
if (r && r.url === s) {
|
|
2748
2774
|
console.log(`
|
|
2749
2775
|
Myop MCP is already configured for ${p.name}.`), console.log(` Config: ${p.configPath}`), console.log(`
|
|
2750
2776
|
\x1B[1mNext steps:\x1B[0m`);
|
|
2751
|
-
for (const
|
|
2752
|
-
console.log(` ${
|
|
2777
|
+
for (const c of p.nextSteps)
|
|
2778
|
+
console.log(` ${c}`);
|
|
2753
2779
|
console.log(""), process.exit(0);
|
|
2754
2780
|
}
|
|
2755
|
-
if (
|
|
2781
|
+
if (r) {
|
|
2756
2782
|
console.log(`
|
|
2757
|
-
Myop MCP is already configured (URL: ${
|
|
2783
|
+
Myop MCP is already configured (URL: ${r.url}).`);
|
|
2758
2784
|
try {
|
|
2759
2785
|
await t({ message: "Update to latest URL?", default: !0 }) || process.exit(0);
|
|
2760
|
-
} catch (
|
|
2761
|
-
throw
|
|
2786
|
+
} catch (c) {
|
|
2787
|
+
throw c.name === "ExitPromptError" && process.exit(0), c;
|
|
2762
2788
|
}
|
|
2763
2789
|
}
|
|
2764
|
-
m.mcpServers.myop = p.getEntry(), P.mkdirSync(
|
|
2790
|
+
m.mcpServers.myop = p.getEntry(), P.mkdirSync(_.dirname(p.configPath), { recursive: !0 }), P.writeFileSync(p.configPath, JSON.stringify(m, null, 2)), console.log(`
|
|
2765
2791
|
\x1B[32m✔\x1B[0m Myop MCP configured for ${p.name}`), console.log(` Config: ${p.configPath}`), console.log(` Server: ${s}`), console.log(`
|
|
2766
2792
|
\x1B[1mNext steps:\x1B[0m`);
|
|
2767
|
-
for (const
|
|
2768
|
-
console.log(` ${
|
|
2793
|
+
for (const c of p.nextSteps)
|
|
2794
|
+
console.log(` ${c}`);
|
|
2769
2795
|
console.log(""), process.exit(0);
|
|
2770
2796
|
});
|
|
2771
2797
|
const $o = () => {
|
|
2772
2798
|
try {
|
|
2773
|
-
|
|
2799
|
+
X("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
2774
2800
|
} catch {
|
|
2775
2801
|
return { gitNotInstalled: !0 };
|
|
2776
2802
|
}
|
|
2777
2803
|
try {
|
|
2778
|
-
|
|
2804
|
+
X("git rev-parse --git-dir", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
2779
2805
|
} catch {
|
|
2780
2806
|
return { notARepo: !0 };
|
|
2781
2807
|
}
|
|
2782
2808
|
try {
|
|
2783
|
-
const o =
|
|
2809
|
+
const o = X("git diff --stat HEAD -- . 2>/dev/null || git diff --stat -- . 2>/dev/null", {
|
|
2784
2810
|
encoding: "utf-8",
|
|
2785
2811
|
stdio: ["pipe", "pipe", "pipe"]
|
|
2786
2812
|
}).trim();
|
|
@@ -2800,12 +2826,12 @@ const $o = () => {
|
|
|
2800
2826
|
} catch {
|
|
2801
2827
|
return null;
|
|
2802
2828
|
}
|
|
2803
|
-
},
|
|
2804
|
-
var
|
|
2805
|
-
const e = Pe(), n = !!(e != null && e.email), s = ((
|
|
2829
|
+
}, ie = async (o = !1, t = !1) => {
|
|
2830
|
+
var c, y, S;
|
|
2831
|
+
const e = Pe(), n = !!(e != null && e.email), s = ((c = v.myopConfig) == null ? void 0 : c.name) || ((y = v.myopConfig) == null ? void 0 : y.componentName), i = (S = v.myopConfig) == null ? void 0 : S.componentId, a = $o();
|
|
2806
2832
|
console.log(`
|
|
2807
2833
|
┌─────────────────────────────────────────────────┐`), console.log("│ │"), console.log("│ Welcome to Myop CLI - Remote UI Made Easy │"), console.log("│ │"), console.log(`└─────────────────────────────────────────────────┘
|
|
2808
|
-
`), o && s ? (console.log(` Component: ${s}`), i ? (console.log(` ID: ${i}`), console.log(` Dashboard: https://dashboard.myop.dev/dashboard/2.0/component/${i}`)) : console.log(" ID: (not yet pushed)")) : console.log(" Component: No myop.config.json found"), console.log(` User: ${n ? e.email : "Not logged in"}`),
|
|
2834
|
+
`), o && s ? (console.log(` Component: ${s}`), i ? (console.log(` ID: ${i}`), console.log(` Dashboard: https://dashboard.myop.dev/dashboard/2.0/component/${i}`)) : console.log(" ID: (not yet pushed)")) : console.log(" Component: No myop.config.json found"), console.log(` User: ${n ? e.email : "Not logged in"}`), a != null && a.gitNotInstalled ? (console.log(" Changes: Git not installed"), console.log(" Install: https://git-scm.com/downloads"), console.log(" Mac: brew install git | Windows: https://gitforwindows.org")) : a != null && a.notARepo ? console.log(" Changes: Not a git repository") : a && (a.insertions > 0 || a.deletions > 0) ? console.log(` Changes: ${a.files} file${a.files !== 1 ? "s" : ""} | \x1B[32m+${a.insertions}\x1B[0m \x1B[31m-${a.deletions}\x1B[0m`) : a && console.log(" Changes: No uncommitted changes"), console.log("");
|
|
2809
2835
|
const m = [
|
|
2810
2836
|
{
|
|
2811
2837
|
emoji: "🚀",
|
|
@@ -2835,7 +2861,7 @@ const $o = () => {
|
|
|
2835
2861
|
disabled: $.disabled
|
|
2836
2862
|
}));
|
|
2837
2863
|
m.push(
|
|
2838
|
-
new
|
|
2864
|
+
new He(),
|
|
2839
2865
|
{
|
|
2840
2866
|
name: t && n ? `🔓 Logout (${e.email})
|
|
2841
2867
|
Clears stored credentials from this machine` : t && !n ? `🔐 Login to Myop
|
|
@@ -2846,15 +2872,15 @@ const $o = () => {
|
|
|
2846
2872
|
name: t ? "📖 Hide help" : "📖 Show help",
|
|
2847
2873
|
value: "help"
|
|
2848
2874
|
},
|
|
2849
|
-
new
|
|
2875
|
+
new He(),
|
|
2850
2876
|
{
|
|
2851
2877
|
name: "👋 Exit",
|
|
2852
2878
|
value: "exit"
|
|
2853
2879
|
}
|
|
2854
2880
|
);
|
|
2855
|
-
let
|
|
2881
|
+
let r;
|
|
2856
2882
|
try {
|
|
2857
|
-
|
|
2883
|
+
r = await it({
|
|
2858
2884
|
message: "What would you like to do?",
|
|
2859
2885
|
choices: m
|
|
2860
2886
|
});
|
|
@@ -2864,9 +2890,9 @@ const $o = () => {
|
|
|
2864
2890
|
👋 Goodbye!
|
|
2865
2891
|
`), process.exit(0)), $;
|
|
2866
2892
|
}
|
|
2867
|
-
switch (
|
|
2893
|
+
switch (r) {
|
|
2868
2894
|
case "init":
|
|
2869
|
-
await
|
|
2895
|
+
await Po();
|
|
2870
2896
|
break;
|
|
2871
2897
|
case "sync":
|
|
2872
2898
|
console.log(`
|
|
@@ -2877,32 +2903,32 @@ Pushing component...
|
|
|
2877
2903
|
$("node " + process.argv[1] + " push", { stdio: "inherit" });
|
|
2878
2904
|
} catch {
|
|
2879
2905
|
}
|
|
2880
|
-
await
|
|
2906
|
+
await ie(!0, t);
|
|
2881
2907
|
break;
|
|
2882
2908
|
case "dev":
|
|
2883
|
-
await
|
|
2909
|
+
await Me();
|
|
2884
2910
|
break;
|
|
2885
2911
|
case "login":
|
|
2886
2912
|
try {
|
|
2887
|
-
await
|
|
2888
|
-
`), await
|
|
2889
|
-
} catch (
|
|
2890
|
-
console.error("Login failed:",
|
|
2913
|
+
await ue(), console.log(`
|
|
2914
|
+
`), await ie(o, t);
|
|
2915
|
+
} catch (h) {
|
|
2916
|
+
console.error("Login failed:", h.message), await ie(o, t);
|
|
2891
2917
|
}
|
|
2892
2918
|
break;
|
|
2893
2919
|
case "logout":
|
|
2894
|
-
await
|
|
2895
|
-
`), await
|
|
2920
|
+
await ht(), console.log(`
|
|
2921
|
+
`), await ie(o, t);
|
|
2896
2922
|
break;
|
|
2897
2923
|
case "help":
|
|
2898
|
-
await
|
|
2924
|
+
await ie(o, !t);
|
|
2899
2925
|
break;
|
|
2900
2926
|
case "exit":
|
|
2901
2927
|
process.exit(0);
|
|
2902
2928
|
}
|
|
2903
|
-
},
|
|
2929
|
+
}, Ce = ".myop-monorepo.json", bo = () => {
|
|
2904
2930
|
try {
|
|
2905
|
-
const o = P.readFileSync(
|
|
2931
|
+
const o = P.readFileSync(Ce, "utf-8");
|
|
2906
2932
|
return JSON.parse(o);
|
|
2907
2933
|
} catch {
|
|
2908
2934
|
return null;
|
|
@@ -2913,37 +2939,37 @@ Pushing component...
|
|
|
2913
2939
|
selectedComponents: o,
|
|
2914
2940
|
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
2915
2941
|
};
|
|
2916
|
-
P.writeFileSync(
|
|
2942
|
+
P.writeFileSync(Ce, JSON.stringify(t, null, 2));
|
|
2917
2943
|
} catch {
|
|
2918
2944
|
}
|
|
2919
|
-
},
|
|
2945
|
+
}, Mo = async () => {
|
|
2920
2946
|
const o = Pe(), t = !!(o != null && o.email);
|
|
2921
2947
|
console.log(`
|
|
2922
2948
|
┌─────────────────────────────────────────────────┐`), console.log("│ │"), console.log("│ Myop CLI - Monorepo Mode │"), console.log("│ │"), console.log(`└─────────────────────────────────────────────────┘
|
|
2923
2949
|
`);
|
|
2924
|
-
const e =
|
|
2950
|
+
const e = Y("Scanning for components...").start(), n = qe(".");
|
|
2925
2951
|
e.stop(), n.length === 0 && (console.log(` ⚠️ No myop.config.json files found in this directory or subdirectories.
|
|
2926
2952
|
`), console.log(" Run `myop` without -m flag to initialize a single component.\n"), process.exit(0));
|
|
2927
|
-
const s = bo(), i = (s == null ? void 0 : s.selectedComponents) || [],
|
|
2953
|
+
const s = bo(), i = (s == null ? void 0 : s.selectedComponents) || [], a = i.length > 0;
|
|
2928
2954
|
console.log(` Found ${n.length} component${n.length > 1 ? "s" : ""}:
|
|
2929
|
-
`), n.forEach((
|
|
2930
|
-
const $ =
|
|
2931
|
-
console.log(` ${$} ${
|
|
2932
|
-
}), console.log(` User: ${t ? o.email : "Not logged in"}`),
|
|
2955
|
+
`), n.forEach((y, S) => {
|
|
2956
|
+
const $ = y.componentId ? "✅" : "⚪", h = y.componentId ? y.componentId.substring(0, 8) + "..." : "(not pushed)";
|
|
2957
|
+
console.log(` ${$} ${y.name}`), console.log(` Path: ${y.path}`), console.log(` ID: ${h}`), console.log("");
|
|
2958
|
+
}), console.log(` User: ${t ? o.email : "Not logged in"}`), a && console.log(` 📋 Using saved selection from ${Ce}`), console.log("");
|
|
2933
2959
|
const p = v.program.getOptionValue("ci");
|
|
2934
2960
|
let m;
|
|
2935
2961
|
if (p)
|
|
2936
|
-
|
|
2962
|
+
a ? (m = i, console.log(` 🤖 CI mode: using saved selection (${m.length} components)`)) : (m = n.map((y) => y.path), console.log(` 🤖 CI mode: no saved selection, using all ${m.length} components`));
|
|
2937
2963
|
else {
|
|
2938
|
-
const { checkbox:
|
|
2964
|
+
const { checkbox: y } = await import("@inquirer/prompts"), S = n.map(($) => ({
|
|
2939
2965
|
name: `${$.name} (${$.path})`,
|
|
2940
2966
|
value: $.path,
|
|
2941
|
-
checked:
|
|
2967
|
+
checked: a ? i.includes($.path) : !0
|
|
2942
2968
|
}));
|
|
2943
2969
|
try {
|
|
2944
|
-
m = await
|
|
2970
|
+
m = await y({
|
|
2945
2971
|
message: "Select components to start in dev mode:",
|
|
2946
|
-
choices:
|
|
2972
|
+
choices: S
|
|
2947
2973
|
});
|
|
2948
2974
|
} catch ($) {
|
|
2949
2975
|
throw $.name === "ExitPromptError" && (console.log(`
|
|
@@ -2955,20 +2981,20 @@ Pushing component...
|
|
|
2955
2981
|
m.length === 0 && (console.log(`
|
|
2956
2982
|
⚠️ No components selected.
|
|
2957
2983
|
`), process.exit(0)), p || (Co(m), console.log(`
|
|
2958
|
-
💾 Selection saved to ${
|
|
2959
|
-
const
|
|
2960
|
-
console.log(`🚀 Starting dev mode for ${
|
|
2984
|
+
💾 Selection saved to ${Ce}`));
|
|
2985
|
+
const r = n.filter((y) => m.includes(y.path));
|
|
2986
|
+
console.log(`🚀 Starting dev mode for ${r.length} component${r.length > 1 ? "s" : ""}...
|
|
2961
2987
|
`);
|
|
2962
|
-
const { monorepoDevCommand:
|
|
2963
|
-
await
|
|
2964
|
-
},
|
|
2988
|
+
const { monorepoDevCommand: c } = await Promise.resolve().then(() => Vt);
|
|
2989
|
+
await c(r);
|
|
2990
|
+
}, Po = async () => {
|
|
2965
2991
|
const { input: o, select: t } = await import("@inquirer/prompts"), e = await import("fs"), n = await import("path"), s = n.default.basename(process.cwd());
|
|
2966
|
-
let i,
|
|
2992
|
+
let i, a;
|
|
2967
2993
|
try {
|
|
2968
2994
|
i = await o({
|
|
2969
2995
|
message: "Component name:",
|
|
2970
2996
|
default: s
|
|
2971
|
-
}),
|
|
2997
|
+
}), a = await t({
|
|
2972
2998
|
message: "Component type:",
|
|
2973
2999
|
choices: [
|
|
2974
3000
|
{ name: "📄 HTML", value: "html", description: "Plain HTML/JS/CSS component" },
|
|
@@ -2977,22 +3003,22 @@ Pushing component...
|
|
|
2977
3003
|
{ name: "🅰️ Angular", value: "angular", disabled: "(coming soon)" }
|
|
2978
3004
|
]
|
|
2979
3005
|
});
|
|
2980
|
-
} catch (
|
|
2981
|
-
throw
|
|
3006
|
+
} catch (r) {
|
|
3007
|
+
throw r.name === "ExitPromptError" && (console.log(`
|
|
2982
3008
|
|
|
2983
3009
|
👋 Goodbye!
|
|
2984
|
-
`), process.exit(0)),
|
|
3010
|
+
`), process.exit(0)), r;
|
|
2985
3011
|
}
|
|
2986
3012
|
const p = {
|
|
2987
3013
|
name: i,
|
|
2988
|
-
type:
|
|
3014
|
+
type: a,
|
|
2989
3015
|
author: "@myop-cli",
|
|
2990
3016
|
HMR: !0
|
|
2991
3017
|
}, m = v.program.getOptionValue("config") || "./myop.config.json";
|
|
2992
3018
|
try {
|
|
2993
3019
|
e.writeFileSync(m, JSON.stringify(p, null, 2)), console.log(`
|
|
2994
3020
|
✅ Created ${m}`);
|
|
2995
|
-
const
|
|
3021
|
+
const r = {
|
|
2996
3022
|
name: i.toLowerCase().replace(/\s+/g, "-"),
|
|
2997
3023
|
version: "1.0.0",
|
|
2998
3024
|
type: "module",
|
|
@@ -3004,7 +3030,7 @@ Pushing component...
|
|
|
3004
3030
|
esbuild: "^0.24.0"
|
|
3005
3031
|
}
|
|
3006
3032
|
};
|
|
3007
|
-
e.writeFileSync("package.json", JSON.stringify(
|
|
3033
|
+
e.writeFileSync("package.json", JSON.stringify(r, null, 2)), console.log("✅ Created package.json"), e.mkdirSync("src/modules", { recursive: !0 }), e.mkdirSync("src/styles", { recursive: !0 }), e.writeFileSync("build.js", `import * as esbuild from 'esbuild';
|
|
3008
3034
|
import fs from 'fs';
|
|
3009
3035
|
import path from 'path';
|
|
3010
3036
|
|
|
@@ -3084,7 +3110,7 @@ fs.writeFileSync('dist/index.html', html);
|
|
|
3084
3110
|
console.log('✅ Built dist/index.html');
|
|
3085
3111
|
console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS files\`);
|
|
3086
3112
|
`), console.log("✅ Created build.js");
|
|
3087
|
-
const
|
|
3113
|
+
const y = `<!DOCTYPE html>
|
|
3088
3114
|
<html lang="en">
|
|
3089
3115
|
<head>
|
|
3090
3116
|
<meta charset="UTF-8">
|
|
@@ -3101,8 +3127,8 @@ console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS
|
|
|
3101
3127
|
</body>
|
|
3102
3128
|
</html>
|
|
3103
3129
|
`;
|
|
3104
|
-
e.writeFileSync("index.html",
|
|
3105
|
-
const
|
|
3130
|
+
e.writeFileSync("index.html", y), console.log("✅ Created index.html");
|
|
3131
|
+
const S = `// ${i} - Entry Point
|
|
3106
3132
|
import { init } from './modules/app.js';
|
|
3107
3133
|
import { setupMyopInterface } from './modules/myop.js';
|
|
3108
3134
|
|
|
@@ -3111,7 +3137,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
3111
3137
|
setupMyopInterface();
|
|
3112
3138
|
});
|
|
3113
3139
|
`;
|
|
3114
|
-
e.writeFileSync("src/index.js",
|
|
3140
|
+
e.writeFileSync("src/index.js", S), console.log("✅ Created src/index.js");
|
|
3115
3141
|
const $ = `// ${i} - Main Application Logic
|
|
3116
3142
|
|
|
3117
3143
|
export function init() {
|
|
@@ -3176,12 +3202,12 @@ dist/
|
|
|
3176
3202
|
.temp-styles.css
|
|
3177
3203
|
.DS_Store
|
|
3178
3204
|
`), console.log("✅ Created .gitignore");
|
|
3179
|
-
const
|
|
3180
|
-
|
|
3181
|
-
const
|
|
3205
|
+
const C = await Ze(process.cwd());
|
|
3206
|
+
C.success && console.log("✅ Installed AI agent skills");
|
|
3207
|
+
const b = await import("./index-DuEoKctW.js").then((M) => M.i), A = process.cwd();
|
|
3182
3208
|
try {
|
|
3183
|
-
await
|
|
3184
|
-
const
|
|
3209
|
+
await b.init({ fs: e, dir: A });
|
|
3210
|
+
const M = [
|
|
3185
3211
|
"myop.config.json",
|
|
3186
3212
|
"package.json",
|
|
3187
3213
|
"build.js",
|
|
@@ -3193,85 +3219,85 @@ dist/
|
|
|
3193
3219
|
"src/styles/index.css",
|
|
3194
3220
|
"src/styles/main.css"
|
|
3195
3221
|
];
|
|
3196
|
-
if (
|
|
3197
|
-
const N = (
|
|
3222
|
+
if (C.success) {
|
|
3223
|
+
const N = (R, U) => {
|
|
3198
3224
|
try {
|
|
3199
|
-
const D = e.readdirSync(
|
|
3225
|
+
const D = e.readdirSync(R, { withFileTypes: !0 });
|
|
3200
3226
|
for (const F of D) {
|
|
3201
|
-
const
|
|
3202
|
-
F.isDirectory() ? N(
|
|
3227
|
+
const T = n.join(R, F.name), O = n.join(U, F.name);
|
|
3228
|
+
F.isDirectory() ? N(T, O) : M.push(O);
|
|
3203
3229
|
}
|
|
3204
3230
|
} catch {
|
|
3205
3231
|
}
|
|
3206
3232
|
};
|
|
3207
3233
|
try {
|
|
3208
|
-
const
|
|
3209
|
-
for (const
|
|
3210
|
-
if (
|
|
3211
|
-
const D = n.join(
|
|
3234
|
+
const R = e.readdirSync(".", { withFileTypes: !0 });
|
|
3235
|
+
for (const U of R)
|
|
3236
|
+
if (U.isDirectory() && U.name.startsWith(".")) {
|
|
3237
|
+
const D = n.join(U.name, "skills");
|
|
3212
3238
|
e.existsSync(D) && N(D, D);
|
|
3213
3239
|
}
|
|
3214
3240
|
} catch {
|
|
3215
3241
|
}
|
|
3216
3242
|
}
|
|
3217
|
-
for (const N of
|
|
3218
|
-
await
|
|
3219
|
-
await
|
|
3243
|
+
for (const N of M)
|
|
3244
|
+
await b.add({ fs: e, dir: A, filepath: N });
|
|
3245
|
+
await b.commit({
|
|
3220
3246
|
fs: e,
|
|
3221
|
-
dir:
|
|
3247
|
+
dir: A,
|
|
3222
3248
|
message: "init",
|
|
3223
3249
|
author: { name: "myop-cli", email: "cli@myop.dev" }
|
|
3224
3250
|
}), console.log("✅ Initialized git repository");
|
|
3225
|
-
} catch (
|
|
3226
|
-
console.log("⚠️ Failed to initialize git repository:",
|
|
3251
|
+
} catch (M) {
|
|
3252
|
+
console.log("⚠️ Failed to initialize git repository:", M.message);
|
|
3227
3253
|
}
|
|
3228
3254
|
console.log(`
|
|
3229
3255
|
📦 Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
|
|
3230
|
-
`), v.myopConfig = p, await
|
|
3231
|
-
} catch (
|
|
3232
|
-
console.error(`Failed to initialize component: ${
|
|
3256
|
+
`), v.myopConfig = p, await ie(!0);
|
|
3257
|
+
} catch (r) {
|
|
3258
|
+
console.error(`Failed to initialize component: ${r.message}`), process.exit(1);
|
|
3233
3259
|
}
|
|
3234
3260
|
};
|
|
3235
3261
|
v.program.command("default", { isDefault: !0 }).action(async () => {
|
|
3236
3262
|
if (v.program.getOptionValue("help") && (console.log(Rt), process.exit()), v.program.getOptionValue("monorepo")) {
|
|
3237
|
-
await
|
|
3263
|
+
await Mo();
|
|
3238
3264
|
return;
|
|
3239
3265
|
}
|
|
3240
3266
|
if (v.program.getOptionValue("ci")) {
|
|
3241
|
-
const p = await import("fs"), m = v.program.getOptionValue("config") || "./myop.config.json",
|
|
3242
|
-
let
|
|
3267
|
+
const p = await import("fs"), m = v.program.getOptionValue("config") || "./myop.config.json", r = v.program.version(), c = Pe();
|
|
3268
|
+
let y = { found: !1 };
|
|
3243
3269
|
try {
|
|
3244
3270
|
if (p.existsSync(m)) {
|
|
3245
|
-
const $ = p.readFileSync(m, "utf-8"),
|
|
3246
|
-
|
|
3271
|
+
const $ = p.readFileSync(m, "utf-8"), h = JSON.parse($);
|
|
3272
|
+
y = {
|
|
3247
3273
|
found: !0,
|
|
3248
3274
|
path: m,
|
|
3249
|
-
name:
|
|
3250
|
-
componentId:
|
|
3251
|
-
organization:
|
|
3275
|
+
name: h.name || h.componentName || null,
|
|
3276
|
+
componentId: h.componentId || null,
|
|
3277
|
+
organization: h.organization || null
|
|
3252
3278
|
};
|
|
3253
3279
|
}
|
|
3254
3280
|
} catch ($) {
|
|
3255
|
-
|
|
3281
|
+
y = { found: !1, error: $.message };
|
|
3256
3282
|
}
|
|
3257
|
-
const
|
|
3258
|
-
version:
|
|
3259
|
-
config:
|
|
3283
|
+
const S = {
|
|
3284
|
+
version: r,
|
|
3285
|
+
config: y,
|
|
3260
3286
|
auth: {
|
|
3261
|
-
loggedIn: !!(
|
|
3262
|
-
email: (
|
|
3287
|
+
loggedIn: !!(c != null && c.email),
|
|
3288
|
+
email: (c == null ? void 0 : c.email) || null
|
|
3263
3289
|
}
|
|
3264
3290
|
};
|
|
3265
|
-
console.log(JSON.stringify(
|
|
3291
|
+
console.log(JSON.stringify(S, null, 2)), process.exit(0);
|
|
3266
3292
|
}
|
|
3267
|
-
let n =
|
|
3293
|
+
let n = Y({
|
|
3268
3294
|
text: "Loading Myop CLI...",
|
|
3269
3295
|
color: "green"
|
|
3270
3296
|
}).start();
|
|
3271
|
-
const s =
|
|
3297
|
+
const s = Ie();
|
|
3272
3298
|
await wo(500), n.stop();
|
|
3273
3299
|
const i = v.program.version();
|
|
3274
|
-
await uo(i) || await
|
|
3300
|
+
await uo(i) || await ie(s.configFound);
|
|
3275
3301
|
});
|
|
3276
3302
|
Qt();
|
|
3277
3303
|
v.program.parse(process.argv);
|