@myop/cli 0.1.11 → 0.1.12
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 +334 -307
- package/package.json +1 -1
package/dist/myop-cli.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import A from "ora";
|
|
3
|
-
import { select as
|
|
4
|
-
import { Command as
|
|
3
|
+
import { select as Me, Separator as pe } from "@inquirer/prompts";
|
|
4
|
+
import { Command as Be, Option as ie } from "commander";
|
|
5
5
|
import { execSync as ne } from "child_process";
|
|
6
6
|
import Z from "path";
|
|
7
7
|
import E from "fs";
|
|
8
8
|
import ue from "crypto";
|
|
9
9
|
import We from "http";
|
|
10
|
-
import { URL as
|
|
10
|
+
import { URL as Oe, URLSearchParams as je } from "url";
|
|
11
11
|
import Ye from "open";
|
|
12
12
|
import Ge from "os";
|
|
13
13
|
const Ve = `
|
|
@@ -52,7 +52,7 @@ Examples:
|
|
|
52
52
|
verbose: !1
|
|
53
53
|
},
|
|
54
54
|
myopConfig: null
|
|
55
|
-
},
|
|
55
|
+
}, Ie = {
|
|
56
56
|
name: "📥 Install Myop generated dependencies",
|
|
57
57
|
value: "myopInstall",
|
|
58
58
|
description: "Fetch and generates Myop dependencies. flows including components, refs and props.",
|
|
@@ -88,7 +88,7 @@ Examples:
|
|
|
88
88
|
},
|
|
89
89
|
action: async () => {
|
|
90
90
|
}
|
|
91
|
-
},
|
|
91
|
+
}, Pe = {
|
|
92
92
|
name: "🚫 Remove flow definition from your project",
|
|
93
93
|
value: "removeFlow",
|
|
94
94
|
description: "Removes flow to yours myop.config.json",
|
|
@@ -216,21 +216,21 @@ ${a}
|
|
|
216
216
|
</body>
|
|
217
217
|
</html>`;
|
|
218
218
|
}
|
|
219
|
-
async function
|
|
220
|
-
const e = await import("fs"), o = await import("path"), { exec: n } = await import("child_process"), a = await import("http"), { createHash:
|
|
219
|
+
async function _e() {
|
|
220
|
+
const e = await import("fs"), o = await import("path"), { exec: n } = await import("child_process"), a = await import("http"), { createHash: m } = await import("node:crypto");
|
|
221
221
|
let c;
|
|
222
222
|
if (import.meta.url.startsWith("file://")) {
|
|
223
223
|
const s = import.meta.url.slice(7);
|
|
224
224
|
c = o.default.dirname(s);
|
|
225
225
|
} else
|
|
226
226
|
c = o.default.dirname(import.meta.url);
|
|
227
|
-
const p = o.default.join(c, "commands", "dev", "management-website"), v = e.default.readFileSync(o.default.join(p, "styles.css"), "utf-8"),
|
|
228
|
-
let
|
|
229
|
-
const _ = /* @__PURE__ */ new Map(),
|
|
230
|
-
let
|
|
227
|
+
const p = o.default.join(c, "commands", "dev", "management-website"), v = e.default.readFileSync(o.default.join(p, "styles.css"), "utf-8"), S = e.default.readFileSync(o.default.join(p, "app.js"), "utf-8"), f = 9292, w = 9293, y = "./dist";
|
|
228
|
+
let j = !1, $ = !1;
|
|
229
|
+
const _ = /* @__PURE__ */ new Map(), z = l.program.getOptionValue("config") || "./myop.config.json";
|
|
230
|
+
let x, P, g = !1;
|
|
231
231
|
try {
|
|
232
|
-
const s = e.default.readFileSync(
|
|
233
|
-
|
|
232
|
+
const s = e.default.readFileSync(z, "utf-8"), t = JSON.parse(s);
|
|
233
|
+
x = t.componentId, P = t.componentName || null, g = t.HMR === !0, x || (console.error("❌ Error: componentId not found in myop.config.json"), process.exit(1)), g && console.log("🔥 HMR enabled");
|
|
234
234
|
} catch (s) {
|
|
235
235
|
console.error("❌ Error reading myop.config.json:", s.message), process.exit(1);
|
|
236
236
|
}
|
|
@@ -247,9 +247,9 @@ async function Pe() {
|
|
|
247
247
|
".svg": "image/svg+xml",
|
|
248
248
|
".ico": "image/x-icon"
|
|
249
249
|
}[t] || "application/octet-stream";
|
|
250
|
-
},
|
|
250
|
+
}, M = /* @__PURE__ */ new Map(), F = [], Ne = 50, J = [], B = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map(), Ae = (s, t, r) => {
|
|
251
251
|
if (s.url.startsWith("/_hmr/")) {
|
|
252
|
-
const i = s.url.split("/_hmr/")[1],
|
|
252
|
+
const i = s.url.split("/_hmr/")[1], u = s.headers["sec-websocket-key"], d = m("sha1").update(u + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
|
|
253
253
|
t.write(
|
|
254
254
|
`HTTP/1.1 101 Switching Protocols\r
|
|
255
255
|
Upgrade: websocket\r
|
|
@@ -265,25 +265,25 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
265
265
|
h && h.delete(t);
|
|
266
266
|
});
|
|
267
267
|
}
|
|
268
|
-
},
|
|
268
|
+
}, ce = a.default.createServer((s, t) => {
|
|
269
269
|
if (t.setHeader("Content-Type", "application/json"), s.method === "POST" && s.url === "/_register") {
|
|
270
270
|
let r = "";
|
|
271
271
|
s.on("data", (i) => r += i), s.on("end", () => {
|
|
272
272
|
try {
|
|
273
|
-
const { componentId: i, distPath:
|
|
274
|
-
|
|
273
|
+
const { componentId: i, distPath: u, componentName: d } = JSON.parse(r);
|
|
274
|
+
M.set(i, { path: u, name: d || null });
|
|
275
275
|
const h = d ? ` (${d})` : "";
|
|
276
|
-
console.log(`✅ Registered: ${i}${h} -> ${
|
|
277
|
-
const
|
|
276
|
+
console.log(`✅ Registered: ${i}${h} -> ${u}`), t.writeHead(200), t.end(JSON.stringify({ success: !0, registered: Array.from(M.keys()) }));
|
|
277
|
+
const I = Array.from(M.entries()).map(([T, V]) => ({
|
|
278
278
|
id: T,
|
|
279
279
|
path: V.path,
|
|
280
280
|
name: V.name
|
|
281
281
|
}));
|
|
282
|
-
|
|
282
|
+
J.forEach((T) => {
|
|
283
283
|
try {
|
|
284
284
|
T.write(`data: ${JSON.stringify({
|
|
285
285
|
type: "components",
|
|
286
|
-
components:
|
|
286
|
+
components: I
|
|
287
287
|
})}
|
|
288
288
|
|
|
289
289
|
`);
|
|
@@ -299,17 +299,17 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
299
299
|
s.on("data", (i) => r += i), s.on("end", () => {
|
|
300
300
|
try {
|
|
301
301
|
const { componentId: i } = JSON.parse(r);
|
|
302
|
-
|
|
303
|
-
const
|
|
302
|
+
M.delete(i), console.log(`❌ Unregistered: ${i}`), t.writeHead(200), t.end(JSON.stringify({ success: !0 }));
|
|
303
|
+
const u = Array.from(M.entries()).map(([d, h]) => ({
|
|
304
304
|
id: d,
|
|
305
305
|
path: h.path,
|
|
306
306
|
name: h.name
|
|
307
307
|
}));
|
|
308
|
-
|
|
308
|
+
J.forEach((d) => {
|
|
309
309
|
try {
|
|
310
310
|
d.write(`data: ${JSON.stringify({
|
|
311
311
|
type: "components",
|
|
312
|
-
components:
|
|
312
|
+
components: u
|
|
313
313
|
})}
|
|
314
314
|
|
|
315
315
|
`);
|
|
@@ -320,99 +320,99 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
320
320
|
t.writeHead(400), t.end(JSON.stringify({ error: i.message }));
|
|
321
321
|
}
|
|
322
322
|
});
|
|
323
|
-
} else s.method === "GET" && s.url === "/_list" ? (t.writeHead(200), t.end(JSON.stringify({ components: Array.from(
|
|
323
|
+
} else s.method === "GET" && s.url === "/_list" ? (t.writeHead(200), t.end(JSON.stringify({ components: Array.from(M.entries()) }))) : (t.writeHead(404), t.end(JSON.stringify({ error: "Not found" })));
|
|
324
324
|
}), q = a.default.createServer((s, t) => {
|
|
325
325
|
if (s.url.includes("..")) {
|
|
326
326
|
t.writeHead(403, { "Content-Type": "text/plain" }), t.end("Forbidden");
|
|
327
327
|
return;
|
|
328
328
|
}
|
|
329
|
-
const r = new URL(s.url, `http://localhost:${
|
|
329
|
+
const r = new URL(s.url, `http://localhost:${f}`), i = r.pathname, u = i.split("/").filter((k) => k);
|
|
330
330
|
if (i.startsWith("/consume")) {
|
|
331
331
|
const k = r.searchParams.get("id");
|
|
332
332
|
if (!k) {
|
|
333
333
|
t.writeHead(400, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Component ID required. Use /consume?id=<componentId>" }));
|
|
334
334
|
return;
|
|
335
335
|
}
|
|
336
|
-
const N =
|
|
337
|
-
let
|
|
336
|
+
const N = M.get(k), L = N ? N.path : null, $e = (W) => {
|
|
337
|
+
let C = "Unknown", R = "Unknown";
|
|
338
338
|
if (s.headers.referer || s.headers.referrer) {
|
|
339
|
-
const
|
|
339
|
+
const O = s.headers.referer || s.headers.referrer;
|
|
340
340
|
try {
|
|
341
|
-
const Y = new URL(
|
|
342
|
-
|
|
341
|
+
const Y = new URL(O);
|
|
342
|
+
C = Y.origin, R = Y.hostname || Y.origin;
|
|
343
343
|
} catch {
|
|
344
|
-
|
|
344
|
+
C = O, R = O;
|
|
345
345
|
}
|
|
346
346
|
} else if (s.headers.origin)
|
|
347
347
|
try {
|
|
348
|
-
const
|
|
349
|
-
|
|
348
|
+
const O = new URL(s.headers.origin);
|
|
349
|
+
C = O.origin, R = O.hostname || O.origin;
|
|
350
350
|
} catch {
|
|
351
|
-
|
|
351
|
+
C = s.headers.origin, R = s.headers.origin;
|
|
352
352
|
}
|
|
353
353
|
else if (s.socket.remoteAddress) {
|
|
354
|
-
const
|
|
355
|
-
|
|
354
|
+
const O = s.socket.remoteAddress;
|
|
355
|
+
O === "::1" || O === "::ffff:127.0.0.1" ? (C = "localhost", R = "localhost (direct)") : (C = O, R = O.replace("::ffff:", ""));
|
|
356
356
|
}
|
|
357
|
-
const
|
|
357
|
+
const de = s.headers.referer || s.headers.referrer || C, te = {
|
|
358
358
|
type: "request",
|
|
359
359
|
componentId: k,
|
|
360
360
|
timestamp: Date.now(),
|
|
361
361
|
servedLocally: W,
|
|
362
|
-
referrer:
|
|
363
|
-
origin:
|
|
362
|
+
referrer: de,
|
|
363
|
+
origin: C,
|
|
364
364
|
originLabel: R
|
|
365
365
|
};
|
|
366
|
-
|
|
367
|
-
url:
|
|
366
|
+
B.has(C) || (B.set(C, {
|
|
367
|
+
url: C,
|
|
368
368
|
label: R,
|
|
369
369
|
firstSeen: Date.now(),
|
|
370
370
|
requestCount: 0
|
|
371
|
-
}),
|
|
371
|
+
}), J.forEach((O) => {
|
|
372
372
|
try {
|
|
373
|
-
|
|
373
|
+
O.write(`data: ${JSON.stringify({
|
|
374
374
|
type: "origins",
|
|
375
|
-
origins: Array.from(
|
|
375
|
+
origins: Array.from(B.values())
|
|
376
376
|
})}
|
|
377
377
|
|
|
378
378
|
`);
|
|
379
379
|
} catch {
|
|
380
380
|
}
|
|
381
381
|
}));
|
|
382
|
-
const
|
|
383
|
-
|
|
382
|
+
const ze = B.get(C);
|
|
383
|
+
ze.requestCount++, J.forEach((O) => {
|
|
384
384
|
try {
|
|
385
|
-
|
|
385
|
+
O.write(`data: ${JSON.stringify({
|
|
386
386
|
type: "origins",
|
|
387
|
-
origins: Array.from(
|
|
387
|
+
origins: Array.from(B.values())
|
|
388
388
|
})}
|
|
389
389
|
|
|
390
390
|
`);
|
|
391
391
|
} catch {
|
|
392
392
|
}
|
|
393
|
-
}), F.push(te), F.length > Ne && F.shift(),
|
|
393
|
+
}), F.push(te), F.length > Ne && F.shift(), J.forEach((O) => {
|
|
394
394
|
try {
|
|
395
|
-
|
|
395
|
+
O.write(`data: ${JSON.stringify(te)}
|
|
396
396
|
|
|
397
397
|
`);
|
|
398
398
|
} catch {
|
|
399
399
|
}
|
|
400
400
|
});
|
|
401
401
|
};
|
|
402
|
-
if (
|
|
403
|
-
const W = o.default.join(
|
|
404
|
-
e.default.readFile(W, "utf-8", (
|
|
405
|
-
if (
|
|
402
|
+
if (L) {
|
|
403
|
+
const W = o.default.join(L, "index.html");
|
|
404
|
+
e.default.readFile(W, "utf-8", (C, R) => {
|
|
405
|
+
if (C) {
|
|
406
406
|
console.log(`❌ File not found: ${W}`), t.writeHead(404, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "index.html not found" }));
|
|
407
407
|
return;
|
|
408
408
|
}
|
|
409
|
-
const
|
|
409
|
+
const de = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, te = {
|
|
410
410
|
item: {
|
|
411
411
|
name: k,
|
|
412
412
|
id: k,
|
|
413
413
|
consume_variant: [
|
|
414
414
|
{
|
|
415
|
-
id:
|
|
415
|
+
id: de,
|
|
416
416
|
name: "dev version",
|
|
417
417
|
loader: {
|
|
418
418
|
type: "HTMLLoader",
|
|
@@ -423,7 +423,7 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
423
423
|
]
|
|
424
424
|
}
|
|
425
425
|
};
|
|
426
|
-
console.log(`✅ Serving consume JSON for: ${k}`),
|
|
426
|
+
console.log(`✅ Serving consume JSON for: ${k}`), $e(!0), t.writeHead(200, {
|
|
427
427
|
"Content-Type": "application/json",
|
|
428
428
|
"Access-Control-Allow-Origin": "*"
|
|
429
429
|
}), t.end(JSON.stringify(te, null, 2));
|
|
@@ -431,13 +431,13 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
431
431
|
} else {
|
|
432
432
|
console.log(`📡 Proxying consume request to cloud.myop.dev for: ${k}`);
|
|
433
433
|
const W = `https://cloud.myop.dev/consume${r.search}`;
|
|
434
|
-
|
|
434
|
+
$e(!1), fetch(W).then((C) => C.text()).then((C) => {
|
|
435
435
|
t.writeHead(200, {
|
|
436
436
|
"Content-Type": "application/json",
|
|
437
437
|
"Access-Control-Allow-Origin": "*"
|
|
438
|
-
}), t.end(
|
|
439
|
-
}).catch((
|
|
440
|
-
console.error(`❌ Proxy error: ${
|
|
438
|
+
}), t.end(C);
|
|
439
|
+
}).catch((C) => {
|
|
440
|
+
console.error(`❌ Proxy error: ${C.message}`), t.writeHead(502, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Failed to fetch from cloud.myop.dev" }));
|
|
441
441
|
});
|
|
442
442
|
}
|
|
443
443
|
return;
|
|
@@ -448,11 +448,11 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
448
448
|
"Cache-Control": "no-cache",
|
|
449
449
|
Connection: "keep-alive",
|
|
450
450
|
"Access-Control-Allow-Origin": "*"
|
|
451
|
-
}),
|
|
452
|
-
const k = Array.from(
|
|
451
|
+
}), J.push(t);
|
|
452
|
+
const k = Array.from(M.entries()).map(([N, L]) => ({
|
|
453
453
|
id: N,
|
|
454
|
-
path:
|
|
455
|
-
name:
|
|
454
|
+
path: L.path,
|
|
455
|
+
name: L.name
|
|
456
456
|
}));
|
|
457
457
|
t.write(`data: ${JSON.stringify({
|
|
458
458
|
type: "components",
|
|
@@ -461,7 +461,7 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
461
461
|
|
|
462
462
|
`), t.write(`data: ${JSON.stringify({
|
|
463
463
|
type: "origins",
|
|
464
|
-
origins: Array.from(
|
|
464
|
+
origins: Array.from(B.values())
|
|
465
465
|
})}
|
|
466
466
|
|
|
467
467
|
`), t.write(`data: ${JSON.stringify({
|
|
@@ -470,90 +470,90 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
470
470
|
})}
|
|
471
471
|
|
|
472
472
|
`), s.on("close", () => {
|
|
473
|
-
const N =
|
|
474
|
-
N !== -1 &&
|
|
473
|
+
const N = J.indexOf(t);
|
|
474
|
+
N !== -1 && J.splice(N, 1);
|
|
475
475
|
});
|
|
476
476
|
return;
|
|
477
477
|
}
|
|
478
|
-
if (
|
|
479
|
-
t.writeHead(200, { "Content-Type": "text/html" }), t.end(nt(
|
|
478
|
+
if (u.length === 0) {
|
|
479
|
+
t.writeHead(200, { "Content-Type": "text/html" }), t.end(nt(f, w, v, S));
|
|
480
480
|
return;
|
|
481
481
|
}
|
|
482
|
-
if (
|
|
482
|
+
if (u[0] !== "view") {
|
|
483
483
|
t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Not found. Use /view/<componentId>/ to access components.");
|
|
484
484
|
return;
|
|
485
485
|
}
|
|
486
|
-
if (
|
|
486
|
+
if (u.length < 2) {
|
|
487
487
|
t.writeHead(400, { "Content-Type": "text/plain" }), t.end("Component ID required. Use /view/<componentId>/");
|
|
488
488
|
return;
|
|
489
489
|
}
|
|
490
|
-
const d =
|
|
490
|
+
const d = u[1], h = M.get(d);
|
|
491
491
|
if (!h) {
|
|
492
492
|
t.writeHead(404, { "Content-Type": "text/plain" }), t.end(`Component not found: ${d}`);
|
|
493
493
|
return;
|
|
494
494
|
}
|
|
495
|
-
const
|
|
495
|
+
const I = h.path, T = u.slice(2), V = T.length === 0 ? "index.html" : T.join("/"), K = o.default.join(I, V);
|
|
496
496
|
console.log(`📥 Request: ${s.url} -> ${K}`), e.default.readFile(K, (k, N) => {
|
|
497
497
|
if (k) {
|
|
498
498
|
console.log(`❌ File not found: ${K}`), t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Not Found");
|
|
499
499
|
return;
|
|
500
500
|
}
|
|
501
|
-
const
|
|
502
|
-
console.log(`✅ Serving: ${K} (${
|
|
503
|
-
"Content-Type":
|
|
501
|
+
const L = H(K);
|
|
502
|
+
console.log(`✅ Serving: ${K} (${L})`), t.writeHead(200, {
|
|
503
|
+
"Content-Type": L,
|
|
504
504
|
"Access-Control-Allow-Origin": "*"
|
|
505
505
|
}), t.end(N);
|
|
506
506
|
});
|
|
507
|
-
}),
|
|
507
|
+
}), we = () => new Promise((s, t) => {
|
|
508
508
|
const r = JSON.stringify({
|
|
509
|
-
componentId:
|
|
510
|
-
distPath: o.default.resolve(b,
|
|
509
|
+
componentId: x,
|
|
510
|
+
distPath: o.default.resolve(b, y),
|
|
511
511
|
componentName: P
|
|
512
512
|
}), i = {
|
|
513
513
|
hostname: "localhost",
|
|
514
|
-
port:
|
|
514
|
+
port: w,
|
|
515
515
|
path: "/_register",
|
|
516
516
|
method: "POST",
|
|
517
517
|
headers: {
|
|
518
518
|
"Content-Type": "application/json",
|
|
519
519
|
"Content-Length": Buffer.byteLength(r)
|
|
520
520
|
}
|
|
521
|
-
},
|
|
521
|
+
}, u = a.default.request(i, (d) => {
|
|
522
522
|
let h = "";
|
|
523
|
-
d.on("data", (
|
|
523
|
+
d.on("data", (I) => h += I), d.on("end", () => {
|
|
524
524
|
d.statusCode === 200 ? s(JSON.parse(h)) : t(new Error(`Registration failed: ${d.statusCode}`));
|
|
525
525
|
});
|
|
526
526
|
});
|
|
527
|
-
|
|
527
|
+
u.on("error", t), u.write(r), u.end();
|
|
528
528
|
}), Ee = () => new Promise((s, t) => {
|
|
529
|
-
const r = JSON.stringify({ componentId:
|
|
529
|
+
const r = JSON.stringify({ componentId: x }), i = {
|
|
530
530
|
hostname: "localhost",
|
|
531
|
-
port:
|
|
531
|
+
port: w,
|
|
532
532
|
path: "/_unregister",
|
|
533
533
|
method: "POST",
|
|
534
534
|
headers: {
|
|
535
535
|
"Content-Type": "application/json",
|
|
536
536
|
"Content-Length": Buffer.byteLength(r)
|
|
537
537
|
}
|
|
538
|
-
},
|
|
538
|
+
}, u = a.default.request(i, (d) => {
|
|
539
539
|
s();
|
|
540
540
|
});
|
|
541
|
-
|
|
541
|
+
u.on("error", () => s()), u.write(r), u.end();
|
|
542
542
|
}), He = () => {
|
|
543
|
-
if (!
|
|
544
|
-
const s = o.default.join(
|
|
543
|
+
if (!g) return;
|
|
544
|
+
const s = o.default.join(y, "index.html");
|
|
545
545
|
try {
|
|
546
546
|
let t = e.default.readFileSync(s, "utf-8");
|
|
547
547
|
if (t.includes("<!-- MYOP HMR -->")) {
|
|
548
|
-
const i = t.indexOf("<!-- MYOP HMR -->"),
|
|
549
|
-
t = t.slice(0, i) + t.slice(
|
|
548
|
+
const i = t.indexOf("<!-- MYOP HMR -->"), u = t.indexOf("<\/script>", i) + 9;
|
|
549
|
+
t = t.slice(0, i) + t.slice(u);
|
|
550
550
|
}
|
|
551
551
|
const r = `
|
|
552
552
|
<!-- MYOP HMR -->
|
|
553
553
|
<script>
|
|
554
554
|
(function() {
|
|
555
|
-
const componentId = '${
|
|
556
|
-
const wsUrl = 'ws://localhost:${
|
|
555
|
+
const componentId = '${x}';
|
|
556
|
+
const wsUrl = 'ws://localhost:${w}/_hmr/' + componentId;
|
|
557
557
|
let ws;
|
|
558
558
|
let reconnectAttempts = 0;
|
|
559
559
|
const maxReconnectAttempts = 10;
|
|
@@ -658,7 +658,7 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
658
658
|
} catch (t) {
|
|
659
659
|
console.error("❌ Failed to inject HMR script:", t.message);
|
|
660
660
|
}
|
|
661
|
-
},
|
|
661
|
+
}, Je = (s) => {
|
|
662
662
|
const t = Buffer.from(s), r = t.length;
|
|
663
663
|
let i;
|
|
664
664
|
return r < 126 ? i = Buffer.concat([
|
|
@@ -678,13 +678,13 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
678
678
|
// 64-bit length
|
|
679
679
|
t
|
|
680
680
|
]), i;
|
|
681
|
-
},
|
|
682
|
-
if (!
|
|
683
|
-
const s = D.get(
|
|
681
|
+
}, Le = () => {
|
|
682
|
+
if (!g) return;
|
|
683
|
+
const s = D.get(x);
|
|
684
684
|
if (!s || s.size === 0)
|
|
685
685
|
return;
|
|
686
686
|
console.log(`🔥 Notifying ${s.size} HMR client(s)`);
|
|
687
|
-
const t = o.default.join(
|
|
687
|
+
const t = o.default.join(y, "index.html");
|
|
688
688
|
try {
|
|
689
689
|
let r = e.default.readFileSync(t, "utf-8");
|
|
690
690
|
if (r.includes("<!-- MYOP HMR -->")) {
|
|
@@ -694,10 +694,10 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
694
694
|
const i = JSON.stringify({
|
|
695
695
|
type: "update",
|
|
696
696
|
html: r
|
|
697
|
-
}),
|
|
697
|
+
}), u = Je(i);
|
|
698
698
|
s.forEach((d) => {
|
|
699
699
|
try {
|
|
700
|
-
d.write(
|
|
700
|
+
d.write(u);
|
|
701
701
|
} catch {
|
|
702
702
|
s.delete(d);
|
|
703
703
|
}
|
|
@@ -705,52 +705,52 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
705
705
|
} catch (r) {
|
|
706
706
|
console.error("❌ Failed to read HTML for HMR:", r.message);
|
|
707
707
|
}
|
|
708
|
-
},
|
|
709
|
-
if (
|
|
710
|
-
|
|
708
|
+
}, le = () => {
|
|
709
|
+
if (j) {
|
|
710
|
+
$ = !0;
|
|
711
711
|
return;
|
|
712
712
|
}
|
|
713
|
-
|
|
713
|
+
j = !0, console.log(`
|
|
714
714
|
🔨 Building...`), n("npm run build", (s, t, r) => {
|
|
715
|
-
|
|
715
|
+
j = !1, s ? (console.error("❌ Build failed:", s.message), r && console.error(r)) : (console.log("✅ Build completed"), t && console.log(t), He(), Le()), $ && ($ = !1, le());
|
|
716
716
|
});
|
|
717
|
-
},
|
|
717
|
+
}, ve = /* @__PURE__ */ new Set(), Se = (s) => {
|
|
718
718
|
e.default.readdir(s, { withFileTypes: !0 }, (t, r) => {
|
|
719
719
|
t || (r.forEach((i) => {
|
|
720
|
-
const
|
|
720
|
+
const u = o.default.join(s, i.name);
|
|
721
721
|
if (i.isDirectory())
|
|
722
|
-
i.name !== "node_modules" && i.name !== "dist" && !i.name.startsWith(".") &&
|
|
722
|
+
i.name !== "node_modules" && i.name !== "dist" && !i.name.startsWith(".") && Se(u);
|
|
723
723
|
else if (i.isFile()) {
|
|
724
724
|
const d = o.default.extname(i.name);
|
|
725
725
|
if (d === ".js" || d === ".css" || d === ".html")
|
|
726
726
|
try {
|
|
727
|
-
const h = e.default.readFileSync(
|
|
728
|
-
_.set(
|
|
727
|
+
const h = e.default.readFileSync(u, "utf-8");
|
|
728
|
+
_.set(u, h);
|
|
729
729
|
} catch {
|
|
730
730
|
}
|
|
731
731
|
}
|
|
732
|
-
}),
|
|
733
|
-
if (!
|
|
734
|
-
const d = o.default.extname(
|
|
732
|
+
}), ve.has(s) || (ve.add(s), e.default.watch(s, (i, u) => {
|
|
733
|
+
if (!u) return;
|
|
734
|
+
const d = o.default.extname(u);
|
|
735
735
|
if (d !== ".js" && d !== ".css" && d !== ".html") return;
|
|
736
|
-
const h = o.default.join(s,
|
|
736
|
+
const h = o.default.join(s, u);
|
|
737
737
|
setTimeout(() => {
|
|
738
738
|
try {
|
|
739
|
-
const
|
|
740
|
-
|
|
739
|
+
const I = e.default.readFileSync(h, "utf-8"), T = _.get(h);
|
|
740
|
+
I !== T && (_.set(h, I), console.log(`📝 File changed: ${h}`), le());
|
|
741
741
|
} catch {
|
|
742
742
|
}
|
|
743
743
|
}, 50);
|
|
744
744
|
})));
|
|
745
745
|
});
|
|
746
|
-
},
|
|
746
|
+
}, xe = () => {
|
|
747
747
|
console.log(`
|
|
748
|
-
🔨 Component: ${
|
|
748
|
+
🔨 Component: ${x}`), le(), Se(b), console.log("👀 Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
|
|
749
749
|
`);
|
|
750
750
|
}, De = () => new Promise((s) => {
|
|
751
751
|
const t = {
|
|
752
752
|
hostname: "localhost",
|
|
753
|
-
port:
|
|
753
|
+
port: w,
|
|
754
754
|
path: "/_list",
|
|
755
755
|
method: "GET",
|
|
756
756
|
timeout: 1e3
|
|
@@ -763,42 +763,42 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
763
763
|
}), Ue = () => new Promise((s) => {
|
|
764
764
|
const t = a.default.createServer((r, i) => {
|
|
765
765
|
if (i.setHeader("Content-Type", "application/json"), r.method === "POST" && r.url === "/_register") {
|
|
766
|
-
let
|
|
767
|
-
r.on("data", (d) =>
|
|
766
|
+
let u = "";
|
|
767
|
+
r.on("data", (d) => u += d), r.on("end", () => {
|
|
768
768
|
try {
|
|
769
|
-
const { componentId: d, distPath: h, componentName:
|
|
770
|
-
|
|
771
|
-
const T =
|
|
772
|
-
console.log(`✅ Registered: ${d}${T} -> ${h}`), i.writeHead(200), i.end(JSON.stringify({ success: !0, registered: Array.from(
|
|
769
|
+
const { componentId: d, distPath: h, componentName: I } = JSON.parse(u);
|
|
770
|
+
M.set(d, { path: h, name: I || null });
|
|
771
|
+
const T = I ? ` (${I})` : "";
|
|
772
|
+
console.log(`✅ Registered: ${d}${T} -> ${h}`), i.writeHead(200), i.end(JSON.stringify({ success: !0, registered: Array.from(M.keys()) }));
|
|
773
773
|
} catch (d) {
|
|
774
774
|
i.writeHead(400), i.end(JSON.stringify({ error: d.message }));
|
|
775
775
|
}
|
|
776
776
|
});
|
|
777
777
|
} else if (r.method === "POST" && r.url === "/_unregister") {
|
|
778
|
-
let
|
|
779
|
-
r.on("data", (d) =>
|
|
778
|
+
let u = "";
|
|
779
|
+
r.on("data", (d) => u += d), r.on("end", () => {
|
|
780
780
|
try {
|
|
781
|
-
const { componentId: d } = JSON.parse(
|
|
782
|
-
|
|
781
|
+
const { componentId: d } = JSON.parse(u);
|
|
782
|
+
M.delete(d), console.log(`❌ Unregistered: ${d}`), i.writeHead(200), i.end(JSON.stringify({ success: !0 }));
|
|
783
783
|
} catch (d) {
|
|
784
784
|
i.writeHead(400), i.end(JSON.stringify({ error: d.message }));
|
|
785
785
|
}
|
|
786
786
|
});
|
|
787
|
-
} else r.method === "GET" && r.url === "/_list" ? (i.writeHead(200), i.end(JSON.stringify({ components: Array.from(
|
|
787
|
+
} else r.method === "GET" && r.url === "/_list" ? (i.writeHead(200), i.end(JSON.stringify({ components: Array.from(M.entries()) }))) : (i.writeHead(404), i.end(JSON.stringify({ error: "Not found" })));
|
|
788
788
|
});
|
|
789
789
|
t.on("error", () => {
|
|
790
790
|
s(!1);
|
|
791
|
-
}), t.listen(
|
|
791
|
+
}), t.listen(w, () => {
|
|
792
792
|
console.log(`
|
|
793
|
-
🔄 Taking over as server...`), console.log(`📡 Management server on port ${
|
|
793
|
+
🔄 Taking over as server...`), console.log(`📡 Management server on port ${w}`), q.on("error", () => {
|
|
794
794
|
t.close(), s(!1);
|
|
795
|
-
}), q.listen(
|
|
796
|
-
console.log(`📡 Main server running at http://localhost:${
|
|
797
|
-
path: o.default.resolve(b,
|
|
795
|
+
}), q.listen(f, () => {
|
|
796
|
+
console.log(`📡 Main server running at http://localhost:${f}`), M.set(x, {
|
|
797
|
+
path: o.default.resolve(b, y),
|
|
798
798
|
name: P
|
|
799
799
|
});
|
|
800
800
|
const r = P ? ` (${P})` : "";
|
|
801
|
-
console.log(`✅ Registered component: ${
|
|
801
|
+
console.log(`✅ Registered component: ${x}${r}`), console.log(`📡 Access at: http://localhost:${f}/view/${x}/`), s(!0);
|
|
802
802
|
});
|
|
803
803
|
});
|
|
804
804
|
});
|
|
@@ -808,46 +808,46 @@ Sec-WebSocket-Accept: ${d}\r
|
|
|
808
808
|
await De() || (clearInterval(ee), console.log(`
|
|
809
809
|
⚠️ Server appears to be down, attempting to take over...`), await Ue() ? console.log("✅ Successfully took over as server") : (console.log("ℹ️ Another instance took over, re-registering..."), setTimeout(async () => {
|
|
810
810
|
try {
|
|
811
|
-
await
|
|
811
|
+
await we(), console.log(`✅ Re-registered component: ${x}`), be();
|
|
812
812
|
} catch (r) {
|
|
813
813
|
console.error("❌ Failed to re-register:", r.message);
|
|
814
814
|
}
|
|
815
815
|
}, 2e3)));
|
|
816
816
|
}, 3e3);
|
|
817
|
-
},
|
|
817
|
+
}, Ce = async () => {
|
|
818
818
|
console.log(`
|
|
819
819
|
|
|
820
820
|
🛑 Shutting down...`), ee && clearInterval(ee), await Ee(), process.exit(0);
|
|
821
821
|
};
|
|
822
|
-
process.on("SIGINT",
|
|
822
|
+
process.on("SIGINT", Ce), process.on("SIGTERM", Ce), ce.on("error", async (s) => {
|
|
823
823
|
if (s.code === "EADDRINUSE") {
|
|
824
824
|
console.log(`
|
|
825
825
|
🔗 Connecting to existing dev server...`);
|
|
826
826
|
try {
|
|
827
|
-
const t = await
|
|
828
|
-
console.log(`✅ Registered component: ${
|
|
827
|
+
const t = await we();
|
|
828
|
+
console.log(`✅ Registered component: ${x}`), console.log(`📡 Access at: http://localhost:${f}/view/${x}/`), console.log(`📋 All registered components: ${t.registered.join(", ")}`), xe(), be();
|
|
829
829
|
} catch (t) {
|
|
830
830
|
console.error("❌ Failed to register component:", t.message), process.exit(1);
|
|
831
831
|
}
|
|
832
832
|
} else
|
|
833
833
|
console.error("❌ Management server error:", s.message), process.exit(1);
|
|
834
|
-
}),
|
|
834
|
+
}), ce.on("upgrade", Ae), ce.listen(w, async () => {
|
|
835
835
|
console.log(`
|
|
836
|
-
🚀 Starting shared dev server...`), console.log(`📡 Management server on port ${
|
|
836
|
+
🚀 Starting shared dev server...`), console.log(`📡 Management server on port ${w}`), q.on("error", (s) => {
|
|
837
837
|
console.error("❌ Main server error:", s.message), process.exit(1);
|
|
838
|
-
}), q.listen(
|
|
839
|
-
console.log(`📡 Main server running at http://localhost:${
|
|
840
|
-
path: o.default.resolve(b,
|
|
838
|
+
}), q.listen(f, async () => {
|
|
839
|
+
console.log(`📡 Main server running at http://localhost:${f}`), M.set(x, {
|
|
840
|
+
path: o.default.resolve(b, y),
|
|
841
841
|
name: P
|
|
842
842
|
});
|
|
843
843
|
const s = P ? ` (${P})` : "";
|
|
844
|
-
console.log(`✅ Registered component: ${
|
|
844
|
+
console.log(`✅ Registered component: ${x}${s}`), console.log(`📡 Access at: http://localhost:${f}/view/${x}/`), xe();
|
|
845
845
|
});
|
|
846
846
|
});
|
|
847
847
|
}
|
|
848
|
-
const
|
|
848
|
+
const me = Z.join(Ge.homedir(), ".myop"), Q = Z.join(me, "credentials.json");
|
|
849
849
|
function st() {
|
|
850
|
-
E.existsSync(
|
|
850
|
+
E.existsSync(me) || E.mkdirSync(me, { recursive: !0, mode: 448 });
|
|
851
851
|
}
|
|
852
852
|
function ge() {
|
|
853
853
|
try {
|
|
@@ -859,7 +859,7 @@ function ge() {
|
|
|
859
859
|
return console.info("Failed to read credentials:", e.message), null;
|
|
860
860
|
}
|
|
861
861
|
}
|
|
862
|
-
function
|
|
862
|
+
function Te(e) {
|
|
863
863
|
st();
|
|
864
864
|
const o = {
|
|
865
865
|
...e,
|
|
@@ -870,7 +870,7 @@ function _e(e) {
|
|
|
870
870
|
// Read/write for owner only
|
|
871
871
|
});
|
|
872
872
|
}
|
|
873
|
-
function
|
|
873
|
+
function Re() {
|
|
874
874
|
try {
|
|
875
875
|
return E.existsSync(Q) && E.unlinkSync(Q), !0;
|
|
876
876
|
} catch (e) {
|
|
@@ -883,14 +883,14 @@ function rt(e) {
|
|
|
883
883
|
const o = 5 * 60 * 1e3, n = new Date(e.expiresAt).getTime();
|
|
884
884
|
return Date.now() > n - o;
|
|
885
885
|
}
|
|
886
|
-
function
|
|
886
|
+
function he() {
|
|
887
887
|
const e = ge();
|
|
888
888
|
return e ? {
|
|
889
889
|
email: e.userEmail,
|
|
890
890
|
userId: e.userId
|
|
891
891
|
} : null;
|
|
892
892
|
}
|
|
893
|
-
const G = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", se = 19284,
|
|
893
|
+
const G = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", se = 19284, ye = `http://localhost:${se}/callback`, it = "myop-cli";
|
|
894
894
|
function at() {
|
|
895
895
|
return ue.randomBytes(32).toString("base64url");
|
|
896
896
|
}
|
|
@@ -903,7 +903,7 @@ async function lt() {
|
|
|
903
903
|
headers: { "Content-Type": "application/json" },
|
|
904
904
|
body: JSON.stringify({
|
|
905
905
|
client_name: it,
|
|
906
|
-
redirect_uris: [
|
|
906
|
+
redirect_uris: [ye],
|
|
907
907
|
grant_types: ["authorization_code", "refresh_token"],
|
|
908
908
|
response_types: ["code"]
|
|
909
909
|
})
|
|
@@ -915,7 +915,7 @@ async function lt() {
|
|
|
915
915
|
return e.json();
|
|
916
916
|
}
|
|
917
917
|
function oe(e, o, n, a = null) {
|
|
918
|
-
const
|
|
918
|
+
const m = {
|
|
919
919
|
success: `<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#4ade80" stroke-width="2">
|
|
920
920
|
<circle cx="12" cy="12" r="10"/>
|
|
921
921
|
<path d="M8 12l2.5 2.5L16 9"/>
|
|
@@ -1063,7 +1063,7 @@ function oe(e, o, n, a = null) {
|
|
|
1063
1063
|
<body>
|
|
1064
1064
|
<div class="container">
|
|
1065
1065
|
<div class="icon">
|
|
1066
|
-
${
|
|
1066
|
+
${m[e] || m.error}
|
|
1067
1067
|
</div>
|
|
1068
1068
|
<h1>${o}</h1>
|
|
1069
1069
|
<p class="message">${n}</p>
|
|
@@ -1082,20 +1082,20 @@ function oe(e, o, n, a = null) {
|
|
|
1082
1082
|
}
|
|
1083
1083
|
function dt(e) {
|
|
1084
1084
|
return new Promise((o, n) => {
|
|
1085
|
-
const a = We.createServer((
|
|
1086
|
-
const p = new
|
|
1085
|
+
const a = We.createServer((m, c) => {
|
|
1086
|
+
const p = new Oe(m.url, `http://localhost:${se}`);
|
|
1087
1087
|
if (p.pathname === "/callback") {
|
|
1088
|
-
const v = p.searchParams.get("code"),
|
|
1089
|
-
if (
|
|
1088
|
+
const v = p.searchParams.get("code"), S = p.searchParams.get("state"), f = p.searchParams.get("error");
|
|
1089
|
+
if (f) {
|
|
1090
1090
|
c.writeHead(200, { "Content-Type": "text/html" }), c.end(oe(
|
|
1091
1091
|
"error",
|
|
1092
1092
|
"Authentication Failed",
|
|
1093
1093
|
"Unable to complete the authentication process.",
|
|
1094
|
-
|
|
1095
|
-
)), a.close(), n(new Error(`OAuth error: ${
|
|
1094
|
+
f
|
|
1095
|
+
)), a.close(), n(new Error(`OAuth error: ${f}`));
|
|
1096
1096
|
return;
|
|
1097
1097
|
}
|
|
1098
|
-
if (
|
|
1098
|
+
if (S !== e) {
|
|
1099
1099
|
c.writeHead(400, { "Content-Type": "text/html" }), c.end(oe(
|
|
1100
1100
|
"warning",
|
|
1101
1101
|
"Security Error",
|
|
@@ -1136,13 +1136,13 @@ async function pt(e, o, n) {
|
|
|
1136
1136
|
grant_type: "authorization_code",
|
|
1137
1137
|
code: e,
|
|
1138
1138
|
client_id: o,
|
|
1139
|
-
redirect_uri:
|
|
1139
|
+
redirect_uri: ye,
|
|
1140
1140
|
code_verifier: n
|
|
1141
1141
|
})
|
|
1142
1142
|
});
|
|
1143
1143
|
if (!a.ok) {
|
|
1144
|
-
const
|
|
1145
|
-
throw new Error(
|
|
1144
|
+
const m = await a.json();
|
|
1145
|
+
throw new Error(m.error_description || m.error || "Token exchange failed");
|
|
1146
1146
|
}
|
|
1147
1147
|
return a.json();
|
|
1148
1148
|
}
|
|
@@ -1163,7 +1163,7 @@ async function mt(e, o) {
|
|
|
1163
1163
|
return n.json();
|
|
1164
1164
|
}
|
|
1165
1165
|
async function ut(e) {
|
|
1166
|
-
var
|
|
1166
|
+
var m, c, p;
|
|
1167
1167
|
const o = await fetch(`${G}/mcp`, {
|
|
1168
1168
|
method: "POST",
|
|
1169
1169
|
headers: {
|
|
@@ -1185,7 +1185,7 @@ async function ut(e) {
|
|
|
1185
1185
|
const n = await o.json();
|
|
1186
1186
|
if (n.error)
|
|
1187
1187
|
throw new Error(n.error.message);
|
|
1188
|
-
const a = (p = (c = (
|
|
1188
|
+
const a = (p = (c = (m = n.result) == null ? void 0 : m.content) == null ? void 0 : c[0]) == null ? void 0 : p.text;
|
|
1189
1189
|
if (a)
|
|
1190
1190
|
return JSON.parse(a);
|
|
1191
1191
|
throw new Error("Invalid response from whoami");
|
|
@@ -1194,25 +1194,25 @@ async function X() {
|
|
|
1194
1194
|
const e = A("Starting authentication...").start();
|
|
1195
1195
|
try {
|
|
1196
1196
|
e.text = "Registering OAuth client...";
|
|
1197
|
-
const n = (await lt()).client_id, a = at(),
|
|
1197
|
+
const n = (await lt()).client_id, a = at(), m = ct(a), c = ue.randomBytes(16).toString("hex");
|
|
1198
1198
|
e.text = "Waiting for authorization...";
|
|
1199
|
-
const p = dt(c), v = new
|
|
1200
|
-
v.searchParams.set("response_type", "code"), v.searchParams.set("client_id", n), v.searchParams.set("redirect_uri",
|
|
1199
|
+
const p = dt(c), v = new Oe(`${G}/oauth/authorize`);
|
|
1200
|
+
v.searchParams.set("response_type", "code"), v.searchParams.set("client_id", n), v.searchParams.set("redirect_uri", ye), v.searchParams.set("code_challenge", m), v.searchParams.set("code_challenge_method", "S256"), v.searchParams.set("state", c), e.stop(), console.log(`
|
|
1201
1201
|
🌐 Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${v.toString()}
|
|
1202
1202
|
`), await Ye(v.toString());
|
|
1203
|
-
const
|
|
1203
|
+
const S = await p;
|
|
1204
1204
|
e.start("Exchanging authorization code...");
|
|
1205
|
-
const
|
|
1205
|
+
const f = await pt(S, n, a);
|
|
1206
1206
|
e.text = "Getting user info...";
|
|
1207
|
-
const
|
|
1208
|
-
accessToken:
|
|
1209
|
-
refreshToken:
|
|
1210
|
-
expiresAt: new Date(Date.now() +
|
|
1207
|
+
const w = await ut(f.access_token), y = {
|
|
1208
|
+
accessToken: f.access_token,
|
|
1209
|
+
refreshToken: f.refresh_token,
|
|
1210
|
+
expiresAt: new Date(Date.now() + f.expires_in * 1e3).toISOString(),
|
|
1211
1211
|
clientId: n,
|
|
1212
|
-
userId:
|
|
1213
|
-
userEmail:
|
|
1212
|
+
userId: w.userId,
|
|
1213
|
+
userEmail: w.email
|
|
1214
1214
|
};
|
|
1215
|
-
return
|
|
1215
|
+
return Te(y), e.succeed(`Authenticated as ${w.email}`), y;
|
|
1216
1216
|
} catch (o) {
|
|
1217
1217
|
throw e.fail(`Authentication failed: ${o.message}`), o;
|
|
1218
1218
|
}
|
|
@@ -1223,7 +1223,7 @@ async function Fe() {
|
|
|
1223
1223
|
console.log("Not currently logged in.");
|
|
1224
1224
|
return;
|
|
1225
1225
|
}
|
|
1226
|
-
|
|
1226
|
+
Re(), console.log(`✅ Logged out (was: ${e.userEmail})`);
|
|
1227
1227
|
}
|
|
1228
1228
|
async function ft() {
|
|
1229
1229
|
let e = ge();
|
|
@@ -1244,9 +1244,9 @@ async function ft() {
|
|
|
1244
1244
|
accessToken: n.access_token,
|
|
1245
1245
|
refreshToken: n.refresh_token,
|
|
1246
1246
|
expiresAt: new Date(Date.now() + n.expires_in * 1e3).toISOString()
|
|
1247
|
-
},
|
|
1247
|
+
}, Te(e), o.succeed("Token refreshed"), e;
|
|
1248
1248
|
} catch {
|
|
1249
|
-
return o.warn("Token refresh failed, please log in again"),
|
|
1249
|
+
return o.warn("Token refresh failed, please log in again"), Re(), await X();
|
|
1250
1250
|
}
|
|
1251
1251
|
}
|
|
1252
1252
|
return console.log(`Session expired. Please log in again.
|
|
@@ -1266,8 +1266,8 @@ async function ht() {
|
|
|
1266
1266
|
}
|
|
1267
1267
|
function yt(e, o) {
|
|
1268
1268
|
const n = e.split(".").map(Number), a = o.split(".").map(Number);
|
|
1269
|
-
for (let
|
|
1270
|
-
const c = n[
|
|
1269
|
+
for (let m = 0; m < Math.max(n.length, a.length); m++) {
|
|
1270
|
+
const c = n[m] || 0, p = a[m] || 0;
|
|
1271
1271
|
if (c > p) return 1;
|
|
1272
1272
|
if (c < p) return -1;
|
|
1273
1273
|
}
|
|
@@ -1282,23 +1282,23 @@ async function wt(e) {
|
|
|
1282
1282
|
return !1;
|
|
1283
1283
|
if (console.log(`
|
|
1284
1284
|
📦 New version available: ${e} → ${n}
|
|
1285
|
-
`), await
|
|
1285
|
+
`), await Me({
|
|
1286
1286
|
message: "Would you like to update now?",
|
|
1287
1287
|
choices: [
|
|
1288
1288
|
{ name: "Yes, update now", value: !0 },
|
|
1289
1289
|
{ name: "No, continue with current version", value: !1 }
|
|
1290
1290
|
]
|
|
1291
1291
|
})) {
|
|
1292
|
-
const
|
|
1292
|
+
const m = A({
|
|
1293
1293
|
text: `Updating ${re} to v${n}...`,
|
|
1294
1294
|
color: "green"
|
|
1295
1295
|
}).start();
|
|
1296
1296
|
try {
|
|
1297
|
-
ne(`npm install -g ${re}@latest`, { stdio: "pipe" }),
|
|
1297
|
+
ne(`npm install -g ${re}@latest`, { stdio: "pipe" }), m.succeed(`Updated to v${n}`), console.log(`
|
|
1298
1298
|
Please restart the CLI to use the new version.
|
|
1299
1299
|
`), process.exit(0);
|
|
1300
1300
|
} catch {
|
|
1301
|
-
return
|
|
1301
|
+
return m.fail("Update failed"), console.log(`
|
|
1302
1302
|
You can manually update by running: npm install -g ${re}@latest
|
|
1303
1303
|
`), !1;
|
|
1304
1304
|
}
|
|
@@ -1307,7 +1307,7 @@ You can manually update by running: npm install -g ${re}@latest
|
|
|
1307
1307
|
}
|
|
1308
1308
|
const vt = (e) => new Promise((o) => setTimeout(o, e));
|
|
1309
1309
|
l.executionPath = process.cwd();
|
|
1310
|
-
const
|
|
1310
|
+
const ae = (e = !1) => {
|
|
1311
1311
|
const o = l.program.getOptionValue("verbose");
|
|
1312
1312
|
o || (console.info = () => {
|
|
1313
1313
|
}), console.info("📝 verbose mode on"), l.options = {
|
|
@@ -1334,22 +1334,23 @@ const ie = (e = !1) => {
|
|
|
1334
1334
|
}
|
|
1335
1335
|
};
|
|
1336
1336
|
[
|
|
1337
|
-
new
|
|
1337
|
+
new pe(),
|
|
1338
1338
|
...ot
|
|
1339
1339
|
];
|
|
1340
|
-
l.program = new
|
|
1340
|
+
l.program = new Be();
|
|
1341
1341
|
l.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version("0.1.10");
|
|
1342
|
-
l.program.addOption(new
|
|
1343
|
-
l.program.addOption(new
|
|
1344
|
-
l.program.addOption(new
|
|
1342
|
+
l.program.addOption(new ie("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
|
|
1343
|
+
l.program.addOption(new ie("-h, --help", "Show helpful information"));
|
|
1344
|
+
l.program.addOption(new ie("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
|
|
1345
|
+
l.program.addOption(new ie("--ci", "CI mode: print status info (version, config, auth) as JSON and exit without prompts"));
|
|
1345
1346
|
l.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((e, o) => {
|
|
1346
|
-
|
|
1347
|
+
ae(!0), console.info("adding ", e, o, l.options.configPath), e === "flow" && ke._action(o), process.exit();
|
|
1347
1348
|
});
|
|
1348
1349
|
l.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((e, o) => {
|
|
1349
|
-
|
|
1350
|
+
ae(), console.info("removing ", e, o, l.options.configPath), e === "flow" && Pe._action(o), process.exit();
|
|
1350
1351
|
});
|
|
1351
1352
|
l.program.command("install").description("Install Myop assets").action(async () => {
|
|
1352
|
-
|
|
1353
|
+
ae(), await Ie.action();
|
|
1353
1354
|
});
|
|
1354
1355
|
l.program.command("login").description("Authenticate with Myop platform").action(async () => {
|
|
1355
1356
|
try {
|
|
@@ -1363,30 +1364,30 @@ l.program.command("logout").description("Clear stored credentials").action(async
|
|
|
1363
1364
|
await Fe(), process.exit(0);
|
|
1364
1365
|
});
|
|
1365
1366
|
l.program.command("whoami").description("Show current authenticated user").action(async () => {
|
|
1366
|
-
const e =
|
|
1367
|
+
const e = he();
|
|
1367
1368
|
e && e.email ? console.log(`Logged in as: ${e.email}`) : console.log("Not logged in. Run `myop login` to authenticate."), process.exit(0);
|
|
1368
1369
|
});
|
|
1369
1370
|
l.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (e) => {
|
|
1370
|
-
var
|
|
1371
|
-
const o = l.program.getOptionValue("config") || "./myop.config.json", n = await import("fs"), { execSync: a } = await import("child_process"),
|
|
1371
|
+
var j, $, _, z, x, P;
|
|
1372
|
+
const o = l.program.getOptionValue("config") || "./myop.config.json", n = await import("fs"), { execSync: a } = await import("child_process"), m = await import("path");
|
|
1372
1373
|
let c = {};
|
|
1373
1374
|
if (n.existsSync(o))
|
|
1374
1375
|
try {
|
|
1375
|
-
const
|
|
1376
|
-
c = JSON.parse(
|
|
1376
|
+
const g = n.readFileSync(o, "utf-8");
|
|
1377
|
+
c = JSON.parse(g);
|
|
1377
1378
|
const b = c.name || c.componentName;
|
|
1378
1379
|
console.log(`📋 Found config: ${b || "Unnamed component"}`), c.componentId && console.log(` Component ID: ${c.componentId}`);
|
|
1379
|
-
} catch (
|
|
1380
|
-
console.error(`⚠️ Failed to parse ${o}:`,
|
|
1380
|
+
} catch (g) {
|
|
1381
|
+
console.error(`⚠️ Failed to parse ${o}:`, g.message);
|
|
1381
1382
|
}
|
|
1382
1383
|
else
|
|
1383
1384
|
console.log("⚠️ No myop.config.json found. A new component will be created.");
|
|
1384
1385
|
if (!e.skipBuild) {
|
|
1385
|
-
const
|
|
1386
|
+
const g = A("Building project...").start();
|
|
1386
1387
|
try {
|
|
1387
|
-
a("npm run build", { stdio: "pipe" }),
|
|
1388
|
+
a("npm run build", { stdio: "pipe" }), g.succeed("Build completed");
|
|
1388
1389
|
} catch (b) {
|
|
1389
|
-
|
|
1390
|
+
g.fail("Build failed"), console.error(b.message), process.exit(1);
|
|
1390
1391
|
}
|
|
1391
1392
|
}
|
|
1392
1393
|
const p = "./dist/index.html";
|
|
@@ -1394,13 +1395,13 @@ l.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1394
1395
|
let v;
|
|
1395
1396
|
try {
|
|
1396
1397
|
v = await ft();
|
|
1397
|
-
} catch (
|
|
1398
|
-
console.error("❌ Authentication failed:",
|
|
1398
|
+
} catch (g) {
|
|
1399
|
+
console.error("❌ Authentication failed:", g.message), process.exit(1);
|
|
1399
1400
|
}
|
|
1400
|
-
const
|
|
1401
|
-
let
|
|
1401
|
+
const S = gt();
|
|
1402
|
+
let f = A("Requesting upload URL...").start(), w;
|
|
1402
1403
|
try {
|
|
1403
|
-
const
|
|
1404
|
+
const g = await fetch(`${S}/mcp`, {
|
|
1404
1405
|
method: "POST",
|
|
1405
1406
|
headers: {
|
|
1406
1407
|
"Content-Type": "application/json",
|
|
@@ -1413,59 +1414,59 @@ l.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1413
1414
|
params: {
|
|
1414
1415
|
name: "upload_component",
|
|
1415
1416
|
arguments: {
|
|
1416
|
-
name: c.name || c.componentName ||
|
|
1417
|
+
name: c.name || c.componentName || m.default.basename(process.cwd()),
|
|
1417
1418
|
componentId: c.componentId || void 0,
|
|
1418
1419
|
organization: c.organization || void 0
|
|
1419
1420
|
}
|
|
1420
1421
|
}
|
|
1421
1422
|
})
|
|
1422
1423
|
});
|
|
1423
|
-
if (!
|
|
1424
|
-
throw new Error(`Server returned ${
|
|
1425
|
-
const b = await
|
|
1424
|
+
if (!g.ok)
|
|
1425
|
+
throw new Error(`Server returned ${g.status}`);
|
|
1426
|
+
const b = await g.json();
|
|
1426
1427
|
if (b.error)
|
|
1427
1428
|
throw new Error(b.error.message);
|
|
1428
|
-
const H = (_ = (
|
|
1429
|
-
if (
|
|
1430
|
-
throw new Error(
|
|
1431
|
-
|
|
1432
|
-
} catch (
|
|
1433
|
-
|
|
1429
|
+
const H = (_ = ($ = (j = b.result) == null ? void 0 : j.content) == null ? void 0 : $[0]) == null ? void 0 : _.text;
|
|
1430
|
+
if (w = JSON.parse(H), !w.success)
|
|
1431
|
+
throw new Error(w.error);
|
|
1432
|
+
f.succeed("Upload URL obtained");
|
|
1433
|
+
} catch (g) {
|
|
1434
|
+
f.fail("Failed to get upload URL"), console.error(" ", g.message), process.exit(1);
|
|
1434
1435
|
}
|
|
1435
|
-
|
|
1436
|
+
f = A("Uploading component...").start();
|
|
1436
1437
|
try {
|
|
1437
|
-
const
|
|
1438
|
+
const g = n.readFileSync(p, "utf-8");
|
|
1438
1439
|
let b;
|
|
1439
|
-
const H =
|
|
1440
|
+
const H = w.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
|
|
1440
1441
|
if (H)
|
|
1441
1442
|
b = H[1];
|
|
1442
1443
|
else {
|
|
1443
|
-
const F =
|
|
1444
|
+
const F = w.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
|
|
1444
1445
|
if (F)
|
|
1445
1446
|
b = F[1];
|
|
1446
1447
|
else
|
|
1447
|
-
throw new Error("Could not parse presigned URL from: " +
|
|
1448
|
+
throw new Error("Could not parse presigned URL from: " + w.curlCommand);
|
|
1448
1449
|
}
|
|
1449
1450
|
console.info("Uploading to:", b.substring(0, 100) + "...");
|
|
1450
|
-
const
|
|
1451
|
+
const M = await fetch(b, {
|
|
1451
1452
|
method: "PUT",
|
|
1452
1453
|
headers: {
|
|
1453
1454
|
"Content-Type": "text/html"
|
|
1454
1455
|
},
|
|
1455
|
-
body:
|
|
1456
|
+
body: g
|
|
1456
1457
|
});
|
|
1457
|
-
if (
|
|
1458
|
-
const F = await
|
|
1459
|
-
throw new Error(`Upload failed with status ${
|
|
1458
|
+
if (!M.ok) {
|
|
1459
|
+
const F = await M.text();
|
|
1460
|
+
throw new Error(`Upload failed with status ${M.status}: ${F}`);
|
|
1460
1461
|
}
|
|
1461
|
-
|
|
1462
|
-
} catch (
|
|
1463
|
-
|
|
1462
|
+
f.succeed("Component uploaded");
|
|
1463
|
+
} catch (g) {
|
|
1464
|
+
f.fail("Upload failed"), console.error(" ", g.message), g.cause && console.error(" Cause:", g.cause), process.exit(1);
|
|
1464
1465
|
}
|
|
1465
|
-
|
|
1466
|
-
let
|
|
1466
|
+
f = A("Confirming upload...").start();
|
|
1467
|
+
let y;
|
|
1467
1468
|
try {
|
|
1468
|
-
const
|
|
1469
|
+
const g = await fetch(`${S}/mcp`, {
|
|
1469
1470
|
method: "POST",
|
|
1470
1471
|
headers: {
|
|
1471
1472
|
"Content-Type": "application/json",
|
|
@@ -1478,37 +1479,37 @@ l.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1478
1479
|
params: {
|
|
1479
1480
|
name: "confirm_upload",
|
|
1480
1481
|
arguments: {
|
|
1481
|
-
uploadId:
|
|
1482
|
+
uploadId: w.uploadId
|
|
1482
1483
|
}
|
|
1483
1484
|
}
|
|
1484
1485
|
})
|
|
1485
1486
|
});
|
|
1486
|
-
if (!
|
|
1487
|
-
throw new Error(`Server returned ${
|
|
1488
|
-
const b = await
|
|
1487
|
+
if (!g.ok)
|
|
1488
|
+
throw new Error(`Server returned ${g.status}`);
|
|
1489
|
+
const b = await g.json();
|
|
1489
1490
|
if (b.error)
|
|
1490
1491
|
throw new Error(b.error.message);
|
|
1491
|
-
const H = (P = (
|
|
1492
|
-
if (
|
|
1493
|
-
throw new Error(
|
|
1494
|
-
|
|
1495
|
-
} catch (
|
|
1496
|
-
|
|
1492
|
+
const H = (P = (x = (z = b.result) == null ? void 0 : z.content) == null ? void 0 : x[0]) == null ? void 0 : P.text;
|
|
1493
|
+
if (y = JSON.parse(H), !y.success)
|
|
1494
|
+
throw new Error(y.error);
|
|
1495
|
+
f.succeed("Upload confirmed");
|
|
1496
|
+
} catch (g) {
|
|
1497
|
+
f.fail("Confirmation failed"), console.error(" ", g.message), process.exit(1);
|
|
1497
1498
|
}
|
|
1498
|
-
if (
|
|
1499
|
-
c.componentId =
|
|
1499
|
+
if (y.isNewComponent || !c.componentId) {
|
|
1500
|
+
c.componentId = y.componentId, c.organization = y.orgId, c.name || (c.name = y.componentName);
|
|
1500
1501
|
try {
|
|
1501
1502
|
n.writeFileSync(o, JSON.stringify(c, null, 2)), console.log(`
|
|
1502
1503
|
📝 Updated ${o} with componentId`);
|
|
1503
|
-
} catch (
|
|
1504
|
+
} catch (g) {
|
|
1504
1505
|
console.log(`
|
|
1505
|
-
⚠️ Could not update ${o}: ${
|
|
1506
|
+
⚠️ Could not update ${o}: ${g.message}`), console.log(` Please add componentId: "${y.componentId}" manually`);
|
|
1506
1507
|
}
|
|
1507
1508
|
}
|
|
1508
1509
|
console.log(`
|
|
1509
|
-
✅ Sync completed successfully!`), console.log(` Component: ${
|
|
1510
|
+
✅ Sync completed successfully!`), console.log(` Component: ${y.componentName}`), console.log(` Dashboard: ${y.dashboardUrl}`), process.exit(0);
|
|
1510
1511
|
});
|
|
1511
|
-
l.program.command("dev").description("Start development server with file watching").action(
|
|
1512
|
+
l.program.command("dev").description("Start development server with file watching").action(_e);
|
|
1512
1513
|
const St = () => {
|
|
1513
1514
|
try {
|
|
1514
1515
|
ne("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
@@ -1532,22 +1533,22 @@ const St = () => {
|
|
|
1532
1533
|
deletions: 0
|
|
1533
1534
|
};
|
|
1534
1535
|
const o = e.split(`
|
|
1535
|
-
`), n = o[o.length - 1], a = n.match(/(\d+) insertion/),
|
|
1536
|
+
`), n = o[o.length - 1], a = n.match(/(\d+) insertion/), m = n.match(/(\d+) deletion/), c = n.match(/(\d+) file/);
|
|
1536
1537
|
return {
|
|
1537
1538
|
files: c ? parseInt(c[1]) : 0,
|
|
1538
1539
|
insertions: a ? parseInt(a[1]) : 0,
|
|
1539
|
-
deletions:
|
|
1540
|
+
deletions: m ? parseInt(m[1]) : 0
|
|
1540
1541
|
};
|
|
1541
1542
|
} catch {
|
|
1542
1543
|
return null;
|
|
1543
1544
|
}
|
|
1544
1545
|
}, U = async (e = !1, o = !1) => {
|
|
1545
|
-
var
|
|
1546
|
-
const n =
|
|
1546
|
+
var w, y, j;
|
|
1547
|
+
const n = he(), a = !!(n != null && n.email), m = ((w = l.myopConfig) == null ? void 0 : w.name) || ((y = l.myopConfig) == null ? void 0 : y.componentName), c = (j = l.myopConfig) == null ? void 0 : j.componentId, p = St();
|
|
1547
1548
|
console.log(`
|
|
1548
1549
|
┌─────────────────────────────────────────────────┐`), console.log("│ │"), console.log("│ Welcome to Myop CLI - Remote UI Made Easy │"), console.log("│ │"), console.log(`└─────────────────────────────────────────────────┘
|
|
1549
|
-
`), e &&
|
|
1550
|
-
const
|
|
1550
|
+
`), e && m ? (console.log(` Component: ${m}`), c ? (console.log(` ID: ${c}`), console.log(` Dashboard: https://dashboard.myop.dev/dashboard/2.0/component/${c}`)) : console.log(" ID: (not yet pushed)")) : console.log(" Component: No myop.config.json found"), console.log(` User: ${a ? n.email : "Not logged in"}`), p != null && p.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")) : p != null && p.notARepo ? console.log(" Changes: Not a git repository") : p && (p.insertions > 0 || p.deletions > 0) ? console.log(` Changes: ${p.files} file${p.files !== 1 ? "s" : ""} | \x1B[32m+${p.insertions}\x1B[0m \x1B[31m-${p.deletions}\x1B[0m`) : p && console.log(" Changes: No uncommitted changes"), console.log("");
|
|
1551
|
+
const S = [
|
|
1551
1552
|
{
|
|
1552
1553
|
emoji: "🚀",
|
|
1553
1554
|
label: "Initialize new component",
|
|
@@ -1557,26 +1558,26 @@ const St = () => {
|
|
|
1557
1558
|
},
|
|
1558
1559
|
{
|
|
1559
1560
|
emoji: "📦",
|
|
1560
|
-
label:
|
|
1561
|
+
label: m ? `Push "${m}"` : "Push component",
|
|
1561
1562
|
value: "sync",
|
|
1562
1563
|
help: "Builds project & uploads dist/index.html to Myop",
|
|
1563
1564
|
disabled: e ? a ? !1 : "(login required)" : "(no config file)"
|
|
1564
1565
|
},
|
|
1565
1566
|
{
|
|
1566
1567
|
emoji: "🛠️ ",
|
|
1567
|
-
label:
|
|
1568
|
+
label: m ? `Start dev mode for "${m}"` : "Start dev mode",
|
|
1568
1569
|
value: "dev",
|
|
1569
1570
|
help: "Starts dev server with HMR for instant preview of changes",
|
|
1570
1571
|
disabled: e ? !1 : "(no config file)"
|
|
1571
1572
|
}
|
|
1572
|
-
].map((
|
|
1573
|
-
name: o &&
|
|
1574
|
-
${
|
|
1575
|
-
value:
|
|
1576
|
-
disabled:
|
|
1573
|
+
].map(($) => ({
|
|
1574
|
+
name: o && !$.disabled ? `${$.emoji} ${$.label}
|
|
1575
|
+
${$.help}` : `${$.emoji} ${$.label}`,
|
|
1576
|
+
value: $.value,
|
|
1577
|
+
disabled: $.disabled
|
|
1577
1578
|
}));
|
|
1578
|
-
switch (
|
|
1579
|
-
new
|
|
1579
|
+
switch (S.push(
|
|
1580
|
+
new pe(),
|
|
1580
1581
|
{
|
|
1581
1582
|
name: o && a ? `🔓 Logout (${n.email})
|
|
1582
1583
|
Clears stored credentials from this machine` : o && !a ? `🔐 Login to Myop
|
|
@@ -1587,31 +1588,31 @@ const St = () => {
|
|
|
1587
1588
|
name: o ? "📖 Hide help" : "📖 Show help",
|
|
1588
1589
|
value: "help"
|
|
1589
1590
|
},
|
|
1590
|
-
new
|
|
1591
|
+
new pe(),
|
|
1591
1592
|
{
|
|
1592
1593
|
name: "👋 Exit",
|
|
1593
1594
|
value: "exit"
|
|
1594
1595
|
}
|
|
1595
|
-
), await
|
|
1596
|
+
), await Me({
|
|
1596
1597
|
message: "What would you like to do?",
|
|
1597
|
-
choices:
|
|
1598
|
+
choices: S
|
|
1598
1599
|
})) {
|
|
1599
1600
|
case "init":
|
|
1600
|
-
await
|
|
1601
|
+
await xt();
|
|
1601
1602
|
break;
|
|
1602
1603
|
case "sync":
|
|
1603
1604
|
console.log(`
|
|
1604
1605
|
Running sync...
|
|
1605
1606
|
`);
|
|
1606
|
-
const { execSync:
|
|
1607
|
+
const { execSync: $ } = await import("child_process");
|
|
1607
1608
|
try {
|
|
1608
|
-
|
|
1609
|
+
$("node " + process.argv[1] + " sync", { stdio: "inherit" });
|
|
1609
1610
|
} catch {
|
|
1610
1611
|
}
|
|
1611
1612
|
await U(!0, o);
|
|
1612
1613
|
break;
|
|
1613
1614
|
case "dev":
|
|
1614
|
-
await
|
|
1615
|
+
await _e();
|
|
1615
1616
|
break;
|
|
1616
1617
|
case "login":
|
|
1617
1618
|
try {
|
|
@@ -1631,10 +1632,10 @@ Running sync...
|
|
|
1631
1632
|
case "exit":
|
|
1632
1633
|
process.exit(0);
|
|
1633
1634
|
}
|
|
1634
|
-
},
|
|
1635
|
-
const { input: e, select: o } = await import("@inquirer/prompts"), n = await import("fs"),
|
|
1635
|
+
}, xt = async () => {
|
|
1636
|
+
const { input: e, select: o } = await import("@inquirer/prompts"), n = await import("fs"), m = (await import("path")).default.basename(process.cwd()), c = await e({
|
|
1636
1637
|
message: "Component name:",
|
|
1637
|
-
default:
|
|
1638
|
+
default: m
|
|
1638
1639
|
}), p = await o({
|
|
1639
1640
|
message: "Component type:",
|
|
1640
1641
|
choices: [
|
|
@@ -1647,11 +1648,11 @@ Running sync...
|
|
|
1647
1648
|
name: c,
|
|
1648
1649
|
type: p,
|
|
1649
1650
|
author: "@myop-cli"
|
|
1650
|
-
},
|
|
1651
|
+
}, S = l.program.getOptionValue("config") || "./myop.config.json";
|
|
1651
1652
|
try {
|
|
1652
|
-
n.writeFileSync(
|
|
1653
|
-
✅ Created ${
|
|
1654
|
-
const
|
|
1653
|
+
n.writeFileSync(S, JSON.stringify(v, null, 2)), console.log(`
|
|
1654
|
+
✅ Created ${S}`);
|
|
1655
|
+
const f = {
|
|
1655
1656
|
name: c.toLowerCase().replace(/\s+/g, "-"),
|
|
1656
1657
|
version: "1.0.0",
|
|
1657
1658
|
type: "module",
|
|
@@ -1663,7 +1664,7 @@ Running sync...
|
|
|
1663
1664
|
esbuild: "^0.24.0"
|
|
1664
1665
|
}
|
|
1665
1666
|
};
|
|
1666
|
-
n.writeFileSync("package.json", JSON.stringify(
|
|
1667
|
+
n.writeFileSync("package.json", JSON.stringify(f, null, 2)), console.log("✅ Created package.json"), n.mkdirSync("src/modules", { recursive: !0 }), n.mkdirSync("src/styles", { recursive: !0 }), n.writeFileSync("build.js", `import * as esbuild from 'esbuild';
|
|
1667
1668
|
import fs from 'fs';
|
|
1668
1669
|
import path from 'path';
|
|
1669
1670
|
|
|
@@ -1743,7 +1744,7 @@ fs.writeFileSync('dist/index.html', html);
|
|
|
1743
1744
|
console.log('✅ Built dist/index.html');
|
|
1744
1745
|
console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS files\`);
|
|
1745
1746
|
`), console.log("✅ Created build.js");
|
|
1746
|
-
const
|
|
1747
|
+
const y = `<!DOCTYPE html>
|
|
1747
1748
|
<html lang="en">
|
|
1748
1749
|
<head>
|
|
1749
1750
|
<meta charset="UTF-8">
|
|
@@ -1760,8 +1761,8 @@ console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS
|
|
|
1760
1761
|
</body>
|
|
1761
1762
|
</html>
|
|
1762
1763
|
`;
|
|
1763
|
-
n.writeFileSync("index.html",
|
|
1764
|
-
const
|
|
1764
|
+
n.writeFileSync("index.html", y), console.log("✅ Created index.html");
|
|
1765
|
+
const j = `// ${c} - Entry Point
|
|
1765
1766
|
import { init } from './modules/app.js';
|
|
1766
1767
|
import { setupMyopInterface } from './modules/myop.js';
|
|
1767
1768
|
|
|
@@ -1770,8 +1771,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
1770
1771
|
setupMyopInterface();
|
|
1771
1772
|
});
|
|
1772
1773
|
`;
|
|
1773
|
-
n.writeFileSync("src/index.js",
|
|
1774
|
-
const
|
|
1774
|
+
n.writeFileSync("src/index.js", j), console.log("✅ Created src/index.js");
|
|
1775
|
+
const $ = `// ${c} - Main Application Logic
|
|
1775
1776
|
|
|
1776
1777
|
export function init() {
|
|
1777
1778
|
console.log('${c} loaded');
|
|
@@ -1779,7 +1780,7 @@ export function init() {
|
|
|
1779
1780
|
// Your component logic here
|
|
1780
1781
|
}
|
|
1781
1782
|
`;
|
|
1782
|
-
n.writeFileSync("src/modules/app.js",
|
|
1783
|
+
n.writeFileSync("src/modules/app.js", $), console.log("✅ Created src/modules/app.js"), n.writeFileSync("src/modules/myop.js", `// Myop Interface - Communication with host app
|
|
1783
1784
|
|
|
1784
1785
|
export function setupMyopInterface() {
|
|
1785
1786
|
// Called when host app sends data to this component
|
|
@@ -1795,12 +1796,12 @@ export function setupMyopInterface() {
|
|
|
1795
1796
|
};
|
|
1796
1797
|
}
|
|
1797
1798
|
`), console.log("✅ Created src/modules/myop.js");
|
|
1798
|
-
const
|
|
1799
|
+
const z = `/* ${c} - Styles Entry Point */
|
|
1799
1800
|
/* Add your CSS imports here - they will be auto-bundled */
|
|
1800
1801
|
@import './main.css';
|
|
1801
1802
|
`;
|
|
1802
|
-
n.writeFileSync("src/styles/index.css",
|
|
1803
|
-
const
|
|
1803
|
+
n.writeFileSync("src/styles/index.css", z), console.log("✅ Created src/styles/index.css");
|
|
1804
|
+
const x = `/* ${c} - Main Styles */
|
|
1804
1805
|
|
|
1805
1806
|
* {
|
|
1806
1807
|
box-sizing: border-box;
|
|
@@ -1829,23 +1830,49 @@ p {
|
|
|
1829
1830
|
line-height: 1.5;
|
|
1830
1831
|
}
|
|
1831
1832
|
`;
|
|
1832
|
-
n.writeFileSync("src/styles/main.css",
|
|
1833
|
+
n.writeFileSync("src/styles/main.css", x), console.log("✅ Created src/styles/main.css"), console.log(`
|
|
1833
1834
|
📦 Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
|
|
1834
1835
|
`), l.myopConfig = v, await U(!0);
|
|
1835
|
-
} catch (
|
|
1836
|
-
console.error(`Failed to initialize component: ${
|
|
1836
|
+
} catch (f) {
|
|
1837
|
+
console.error(`Failed to initialize component: ${f.message}`), process.exit(1);
|
|
1837
1838
|
}
|
|
1838
1839
|
};
|
|
1839
1840
|
l.program.command("default", { isDefault: !0 }).action(async () => {
|
|
1840
|
-
l.program.getOptionValue("help") && (console.log(Ve), process.exit())
|
|
1841
|
-
|
|
1841
|
+
if (l.program.getOptionValue("help") && (console.log(Ve), process.exit()), l.program.getOptionValue("ci")) {
|
|
1842
|
+
const c = await import("fs"), p = l.program.getOptionValue("config") || "./myop.config.json", v = l.program.version(), S = he();
|
|
1843
|
+
let f = { found: !1 };
|
|
1844
|
+
try {
|
|
1845
|
+
if (c.existsSync(p)) {
|
|
1846
|
+
const y = c.readFileSync(p, "utf-8"), j = JSON.parse(y);
|
|
1847
|
+
f = {
|
|
1848
|
+
found: !0,
|
|
1849
|
+
path: p,
|
|
1850
|
+
name: j.name || j.componentName || null,
|
|
1851
|
+
componentId: j.componentId || null,
|
|
1852
|
+
organization: j.organization || null
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
} catch (y) {
|
|
1856
|
+
f = { found: !1, error: y.message };
|
|
1857
|
+
}
|
|
1858
|
+
const w = {
|
|
1859
|
+
version: v,
|
|
1860
|
+
config: f,
|
|
1861
|
+
auth: {
|
|
1862
|
+
loggedIn: !!(S != null && S.email),
|
|
1863
|
+
email: (S == null ? void 0 : S.email) || null
|
|
1864
|
+
}
|
|
1865
|
+
};
|
|
1866
|
+
console.log(JSON.stringify(w, null, 2)), process.exit(0);
|
|
1867
|
+
}
|
|
1868
|
+
let n = A({
|
|
1842
1869
|
text: "Loading Myop CLI...",
|
|
1843
1870
|
color: "green"
|
|
1844
1871
|
}).start();
|
|
1845
|
-
const
|
|
1846
|
-
await vt(500),
|
|
1847
|
-
const
|
|
1848
|
-
await wt(
|
|
1872
|
+
const a = ae();
|
|
1873
|
+
await vt(500), n.stop();
|
|
1874
|
+
const m = l.program.version();
|
|
1875
|
+
await wt(m), await U(a.configFound);
|
|
1849
1876
|
});
|
|
1850
1877
|
l.program.parse(process.argv);
|
|
1851
1878
|
l.program.opts();
|