@myop/cli 0.1.16 β 0.1.17
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 +304 -299
- package/package.json +1 -1
package/dist/myop-cli.js
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
import F from "ora";
|
|
3
3
|
import { select as Ie, Separator as me } from "@inquirer/prompts";
|
|
4
4
|
import { Command as We, Option as ce } from "commander";
|
|
5
|
-
import { execSync as re } from "child_process";
|
|
5
|
+
import { execSync as re, spawn as Ge } from "child_process";
|
|
6
6
|
import Z from "path";
|
|
7
7
|
import A from "fs";
|
|
8
8
|
import fe from "crypto";
|
|
9
|
-
import
|
|
10
|
-
import { URL as je, URLSearchParams as
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
const
|
|
9
|
+
import Ye from "http";
|
|
10
|
+
import { URL as je, URLSearchParams as _e } from "url";
|
|
11
|
+
import Ke from "open";
|
|
12
|
+
import Xe from "os";
|
|
13
|
+
const Qe = `
|
|
14
14
|
Usage: myop [OPTIONS] COMMAND [ARGS]...
|
|
15
15
|
|
|
16
16
|
A powerful command-line interface for managing your Myop projects.
|
|
@@ -52,7 +52,7 @@ Examples:
|
|
|
52
52
|
verbose: !1
|
|
53
53
|
},
|
|
54
54
|
myopConfig: null
|
|
55
|
-
},
|
|
55
|
+
}, Pe = {
|
|
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.",
|
|
@@ -64,7 +64,7 @@ Examples:
|
|
|
64
64
|
}
|
|
65
65
|
process.exit();
|
|
66
66
|
}
|
|
67
|
-
},
|
|
67
|
+
}, Ze = (e) => {
|
|
68
68
|
const o = Z.join(d.executionPath, e);
|
|
69
69
|
console.info(`reading config file from: ${o}`);
|
|
70
70
|
const n = A.readFileSync(o, "utf8"), a = JSON.parse(n);
|
|
@@ -97,36 +97,36 @@ Examples:
|
|
|
97
97
|
},
|
|
98
98
|
action: () => {
|
|
99
99
|
}
|
|
100
|
-
},
|
|
100
|
+
}, qe = {
|
|
101
101
|
name: "π Quit",
|
|
102
102
|
value: "quit",
|
|
103
103
|
description: "Quit and continue coding.",
|
|
104
104
|
action: () => {
|
|
105
105
|
process.exit();
|
|
106
106
|
}
|
|
107
|
-
},
|
|
107
|
+
}, et = {
|
|
108
108
|
name: "π’ Create new component",
|
|
109
109
|
value: "-",
|
|
110
110
|
disabled: "(not available yet)"
|
|
111
|
-
},
|
|
111
|
+
}, tt = {
|
|
112
112
|
name: "π΅ Create new experience",
|
|
113
113
|
value: "-",
|
|
114
114
|
disabled: "(not available yet)"
|
|
115
|
-
},
|
|
115
|
+
}, ot = {
|
|
116
116
|
name: "π‘ Create new skin",
|
|
117
117
|
value: "-",
|
|
118
118
|
disabled: "(not available yet)"
|
|
119
|
-
},
|
|
119
|
+
}, nt = {
|
|
120
120
|
name: "π΄ Create new flow",
|
|
121
121
|
value: "-",
|
|
122
122
|
disabled: "(not available yet)"
|
|
123
|
-
},
|
|
123
|
+
}, st = {
|
|
124
124
|
name: "π Define new custom Myop message",
|
|
125
125
|
value: "generateMyopMessage",
|
|
126
126
|
description: "οΈHelp you creates the right structure for a new Myop message, including types and handlers.",
|
|
127
127
|
disabled: "(not available yet)"
|
|
128
|
-
},
|
|
129
|
-
function
|
|
128
|
+
}, rt = [st, et, tt, ot, nt];
|
|
129
|
+
function it(e, o, n, a) {
|
|
130
130
|
return `<!DOCTYPE html>
|
|
131
131
|
<html lang="en">
|
|
132
132
|
<head>
|
|
@@ -217,26 +217,26 @@ ${a}
|
|
|
217
217
|
</html>`;
|
|
218
218
|
}
|
|
219
219
|
async function ke() {
|
|
220
|
-
const e = await import("fs"), o = await import("path"), { exec: n } = await import("child_process"), a = await import("http"), { createHash:
|
|
220
|
+
const e = await import("fs"), o = await import("path"), { exec: n } = await import("child_process"), a = await import("http"), { createHash: f } = await import("node:crypto");
|
|
221
221
|
let c;
|
|
222
222
|
if (import.meta.url.startsWith("file://")) {
|
|
223
|
-
const
|
|
224
|
-
c = o.default.dirname(
|
|
223
|
+
const t = new URL(import.meta.url).pathname, r = process.platform === "win32" && t.startsWith("/") ? t.slice(1) : t;
|
|
224
|
+
c = o.default.dirname(r);
|
|
225
225
|
} else
|
|
226
226
|
c = o.default.dirname(import.meta.url);
|
|
227
|
-
const m = o.default.join(c, "commands", "dev", "management-website"),
|
|
228
|
-
let j = !1,
|
|
227
|
+
const m = o.default.join(c, "commands", "dev", "management-website"), w = e.default.readFileSync(o.default.join(m, "styles.css"), "utf-8"), I = e.default.readFileSync(o.default.join(m, "app.js"), "utf-8"), u = 9292, y = 9293, S = "./dist";
|
|
228
|
+
let j = !1, v = !1;
|
|
229
229
|
const k = /* @__PURE__ */ new Map(), z = d.program.getOptionValue("config") || "./myop.config.json";
|
|
230
|
-
let
|
|
230
|
+
let x, E, h = !1;
|
|
231
231
|
try {
|
|
232
232
|
const s = e.default.readFileSync(z, "utf-8"), t = JSON.parse(s);
|
|
233
|
-
|
|
233
|
+
x = t.componentId || "DEV", E = t.componentName || t.name || null, h = t.HMR === !0, h && console.log("π₯ HMR enabled");
|
|
234
234
|
} catch (s) {
|
|
235
235
|
console.error("β Error reading myop.config.json:", s.message), process.exit(1);
|
|
236
236
|
}
|
|
237
|
-
const
|
|
238
|
-
if (
|
|
239
|
-
return
|
|
237
|
+
const $ = async () => {
|
|
238
|
+
if (x !== "DEV" && x !== "NEW")
|
|
239
|
+
return x;
|
|
240
240
|
try {
|
|
241
241
|
const t = ((await new Promise((l, p) => {
|
|
242
242
|
const g = {
|
|
@@ -245,9 +245,9 @@ async function ke() {
|
|
|
245
245
|
path: "/_list",
|
|
246
246
|
method: "GET",
|
|
247
247
|
timeout: 1e3
|
|
248
|
-
},
|
|
248
|
+
}, M = a.default.request(g, (_) => {
|
|
249
249
|
let H = "";
|
|
250
|
-
|
|
250
|
+
_.on("data", (L) => H += L), _.on("end", () => {
|
|
251
251
|
try {
|
|
252
252
|
l(JSON.parse(H));
|
|
253
253
|
} catch {
|
|
@@ -255,9 +255,9 @@ async function ke() {
|
|
|
255
255
|
}
|
|
256
256
|
});
|
|
257
257
|
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}),
|
|
258
|
+
M.on("error", () => l({ components: [] })), M.on("timeout", () => {
|
|
259
|
+
M.destroy(), l({ components: [] });
|
|
260
|
+
}), M.end();
|
|
261
261
|
})).components || []).map(([l]) => l).filter((l) => l === "DEV" || l === "NEW" || /^DEV\d+$/.test(l) || /^NEW\d+$/.test(l));
|
|
262
262
|
if (t.length === 0)
|
|
263
263
|
return "DEV1";
|
|
@@ -283,9 +283,9 @@ async function ke() {
|
|
|
283
283
|
".svg": "image/svg+xml",
|
|
284
284
|
".ico": "image/x-icon"
|
|
285
285
|
}[t] || "application/octet-stream";
|
|
286
|
-
},
|
|
286
|
+
}, b = /* @__PURE__ */ new Map(), q = [], Ae = 50, D = [], V = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Map(), De = (s, t, r) => {
|
|
287
287
|
if (s.url.startsWith("/_hmr/")) {
|
|
288
|
-
const i = s.url.split("/_hmr/")[1], l = s.headers["sec-websocket-key"], p =
|
|
288
|
+
const i = s.url.split("/_hmr/")[1], l = s.headers["sec-websocket-key"], p = f("sha1").update(l + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
|
|
289
289
|
t.write(
|
|
290
290
|
`HTTP/1.1 101 Switching Protocols\r
|
|
291
291
|
Upgrade: websocket\r
|
|
@@ -307,19 +307,19 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
307
307
|
s.on("data", (i) => r += i), s.on("end", () => {
|
|
308
308
|
try {
|
|
309
309
|
const { componentId: i, distPath: l, componentName: p } = JSON.parse(r);
|
|
310
|
-
|
|
310
|
+
b.set(i, { path: l, name: p || null });
|
|
311
311
|
const g = p ? ` (${p})` : "";
|
|
312
|
-
console.log(`β
Registered: ${i}${g} -> ${l}`), t.writeHead(200), t.end(JSON.stringify({ success: !0, registered: Array.from(
|
|
313
|
-
const
|
|
314
|
-
id:
|
|
312
|
+
console.log(`β
Registered: ${i}${g} -> ${l}`), t.writeHead(200), t.end(JSON.stringify({ success: !0, registered: Array.from(b.keys()) }));
|
|
313
|
+
const M = Array.from(b.entries()).map(([_, H]) => ({
|
|
314
|
+
id: _,
|
|
315
315
|
path: H.path,
|
|
316
316
|
name: H.name
|
|
317
317
|
}));
|
|
318
|
-
D.forEach((
|
|
318
|
+
D.forEach((_) => {
|
|
319
319
|
try {
|
|
320
|
-
|
|
320
|
+
_.write(`data: ${JSON.stringify({
|
|
321
321
|
type: "components",
|
|
322
|
-
components:
|
|
322
|
+
components: M
|
|
323
323
|
})}
|
|
324
324
|
|
|
325
325
|
`);
|
|
@@ -335,8 +335,8 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
335
335
|
s.on("data", (i) => r += i), s.on("end", () => {
|
|
336
336
|
try {
|
|
337
337
|
const { componentId: i } = JSON.parse(r);
|
|
338
|
-
|
|
339
|
-
const l = Array.from(
|
|
338
|
+
b.delete(i), console.log(`β Unregistered: ${i}`), t.writeHead(200), t.end(JSON.stringify({ success: !0 }));
|
|
339
|
+
const l = Array.from(b.entries()).map(([p, g]) => ({
|
|
340
340
|
id: p,
|
|
341
341
|
path: g.path,
|
|
342
342
|
name: g.name
|
|
@@ -356,57 +356,57 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
356
356
|
t.writeHead(400), t.end(JSON.stringify({ error: i.message }));
|
|
357
357
|
}
|
|
358
358
|
});
|
|
359
|
-
} else s.method === "GET" && s.url === "/_list" ? (t.writeHead(200), t.end(JSON.stringify({ components: Array.from(
|
|
359
|
+
} else s.method === "GET" && s.url === "/_list" ? (t.writeHead(200), t.end(JSON.stringify({ components: Array.from(b.entries()) }))) : (t.writeHead(404), t.end(JSON.stringify({ error: "Not found" })));
|
|
360
360
|
}), ee = a.default.createServer((s, t) => {
|
|
361
361
|
if (s.url.includes("..")) {
|
|
362
362
|
t.writeHead(403, { "Content-Type": "text/plain" }), t.end("Forbidden");
|
|
363
363
|
return;
|
|
364
364
|
}
|
|
365
|
-
const r = new URL(s.url, `http://localhost:${
|
|
365
|
+
const r = new URL(s.url, `http://localhost:${u}`), i = r.pathname, l = i.split("/").filter((P) => P);
|
|
366
366
|
if (i.startsWith("/consume")) {
|
|
367
|
-
const
|
|
368
|
-
if (!
|
|
367
|
+
const P = r.searchParams.get("id");
|
|
368
|
+
if (!P) {
|
|
369
369
|
t.writeHead(400, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Component ID required. Use /consume?id=<componentId>" }));
|
|
370
370
|
return;
|
|
371
371
|
}
|
|
372
|
-
const R =
|
|
373
|
-
let
|
|
372
|
+
const R = b.get(P), J = R ? R.path : null, Oe = (W) => {
|
|
373
|
+
let C = "Unknown", T = "Unknown";
|
|
374
374
|
if (s.headers.referer || s.headers.referrer) {
|
|
375
|
-
const
|
|
375
|
+
const O = s.headers.referer || s.headers.referrer;
|
|
376
376
|
try {
|
|
377
|
-
const G = new URL(
|
|
378
|
-
|
|
377
|
+
const G = new URL(O);
|
|
378
|
+
C = G.origin, T = G.hostname || G.origin;
|
|
379
379
|
} catch {
|
|
380
|
-
|
|
380
|
+
C = O, T = O;
|
|
381
381
|
}
|
|
382
382
|
} else if (s.headers.origin)
|
|
383
383
|
try {
|
|
384
|
-
const
|
|
385
|
-
|
|
384
|
+
const O = new URL(s.headers.origin);
|
|
385
|
+
C = O.origin, T = O.hostname || O.origin;
|
|
386
386
|
} catch {
|
|
387
|
-
|
|
387
|
+
C = s.headers.origin, T = s.headers.origin;
|
|
388
388
|
}
|
|
389
389
|
else if (s.socket.remoteAddress) {
|
|
390
|
-
const
|
|
391
|
-
|
|
390
|
+
const O = s.socket.remoteAddress;
|
|
391
|
+
O === "::1" || O === "::ffff:127.0.0.1" ? (C = "localhost", T = "localhost (direct)") : (C = O, T = O.replace("::ffff:", ""));
|
|
392
392
|
}
|
|
393
|
-
const pe = s.headers.referer || s.headers.referrer ||
|
|
393
|
+
const pe = s.headers.referer || s.headers.referrer || C, ne = {
|
|
394
394
|
type: "request",
|
|
395
|
-
componentId:
|
|
395
|
+
componentId: P,
|
|
396
396
|
timestamp: Date.now(),
|
|
397
397
|
servedLocally: W,
|
|
398
398
|
referrer: pe,
|
|
399
|
-
origin:
|
|
399
|
+
origin: C,
|
|
400
400
|
originLabel: T
|
|
401
401
|
};
|
|
402
|
-
V.has(
|
|
403
|
-
url:
|
|
402
|
+
V.has(C) || (V.set(C, {
|
|
403
|
+
url: C,
|
|
404
404
|
label: T,
|
|
405
405
|
firstSeen: Date.now(),
|
|
406
406
|
requestCount: 0
|
|
407
|
-
}), D.forEach((
|
|
407
|
+
}), D.forEach((O) => {
|
|
408
408
|
try {
|
|
409
|
-
|
|
409
|
+
O.write(`data: ${JSON.stringify({
|
|
410
410
|
type: "origins",
|
|
411
411
|
origins: Array.from(V.values())
|
|
412
412
|
})}
|
|
@@ -415,10 +415,10 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
415
415
|
} catch {
|
|
416
416
|
}
|
|
417
417
|
}));
|
|
418
|
-
const Ve = V.get(
|
|
419
|
-
Ve.requestCount++, D.forEach((
|
|
418
|
+
const Ve = V.get(C);
|
|
419
|
+
Ve.requestCount++, D.forEach((O) => {
|
|
420
420
|
try {
|
|
421
|
-
|
|
421
|
+
O.write(`data: ${JSON.stringify({
|
|
422
422
|
type: "origins",
|
|
423
423
|
origins: Array.from(V.values())
|
|
424
424
|
})}
|
|
@@ -426,9 +426,9 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
426
426
|
`);
|
|
427
427
|
} catch {
|
|
428
428
|
}
|
|
429
|
-
}), q.push(ne), q.length > Ae && q.shift(), D.forEach((
|
|
429
|
+
}), q.push(ne), q.length > Ae && q.shift(), D.forEach((O) => {
|
|
430
430
|
try {
|
|
431
|
-
|
|
431
|
+
O.write(`data: ${JSON.stringify(ne)}
|
|
432
432
|
|
|
433
433
|
`);
|
|
434
434
|
} catch {
|
|
@@ -437,15 +437,15 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
437
437
|
};
|
|
438
438
|
if (J) {
|
|
439
439
|
const W = o.default.join(J, "index.html");
|
|
440
|
-
e.default.readFile(W, "utf-8", (
|
|
441
|
-
if (
|
|
440
|
+
e.default.readFile(W, "utf-8", (C, T) => {
|
|
441
|
+
if (C) {
|
|
442
442
|
console.log(`β File not found: ${W}`), t.writeHead(404, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "index.html not found" }));
|
|
443
443
|
return;
|
|
444
444
|
}
|
|
445
445
|
const pe = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, ne = {
|
|
446
446
|
item: {
|
|
447
|
-
name:
|
|
448
|
-
id:
|
|
447
|
+
name: P,
|
|
448
|
+
id: P,
|
|
449
449
|
consume_variant: [
|
|
450
450
|
{
|
|
451
451
|
id: pe,
|
|
@@ -459,21 +459,21 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
459
459
|
]
|
|
460
460
|
}
|
|
461
461
|
};
|
|
462
|
-
console.log(`β
Serving consume JSON for: ${
|
|
462
|
+
console.log(`β
Serving consume JSON for: ${P}`), Oe(!0), t.writeHead(200, {
|
|
463
463
|
"Content-Type": "application/json",
|
|
464
464
|
"Access-Control-Allow-Origin": "*"
|
|
465
465
|
}), t.end(JSON.stringify(ne, null, 2));
|
|
466
466
|
});
|
|
467
467
|
} else {
|
|
468
|
-
console.log(`π‘ Proxying consume request to cloud.myop.dev for: ${
|
|
468
|
+
console.log(`π‘ Proxying consume request to cloud.myop.dev for: ${P}`);
|
|
469
469
|
const W = `https://cloud.myop.dev/consume${r.search}`;
|
|
470
|
-
Oe(!1), fetch(W).then((
|
|
470
|
+
Oe(!1), fetch(W).then((C) => C.text()).then((C) => {
|
|
471
471
|
t.writeHead(200, {
|
|
472
472
|
"Content-Type": "application/json",
|
|
473
473
|
"Access-Control-Allow-Origin": "*"
|
|
474
|
-
}), t.end(
|
|
475
|
-
}).catch((
|
|
476
|
-
console.error(`β Proxy error: ${
|
|
474
|
+
}), t.end(C);
|
|
475
|
+
}).catch((C) => {
|
|
476
|
+
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" }));
|
|
477
477
|
});
|
|
478
478
|
}
|
|
479
479
|
return;
|
|
@@ -485,14 +485,14 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
485
485
|
Connection: "keep-alive",
|
|
486
486
|
"Access-Control-Allow-Origin": "*"
|
|
487
487
|
}), D.push(t);
|
|
488
|
-
const
|
|
488
|
+
const P = Array.from(b.entries()).map(([R, J]) => ({
|
|
489
489
|
id: R,
|
|
490
490
|
path: J.path,
|
|
491
491
|
name: J.name
|
|
492
492
|
}));
|
|
493
493
|
t.write(`data: ${JSON.stringify({
|
|
494
494
|
type: "components",
|
|
495
|
-
components:
|
|
495
|
+
components: P
|
|
496
496
|
})}
|
|
497
497
|
|
|
498
498
|
`), t.write(`data: ${JSON.stringify({
|
|
@@ -512,7 +512,7 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
512
512
|
return;
|
|
513
513
|
}
|
|
514
514
|
if (l.length === 0) {
|
|
515
|
-
t.writeHead(200, { "Content-Type": "text/html" }), t.end(
|
|
515
|
+
t.writeHead(200, { "Content-Type": "text/html" }), t.end(it(u, y, w, I));
|
|
516
516
|
return;
|
|
517
517
|
}
|
|
518
518
|
if (l[0] !== "view") {
|
|
@@ -523,14 +523,14 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
523
523
|
t.writeHead(400, { "Content-Type": "text/plain" }), t.end("Component ID required. Use /view/<componentId>/");
|
|
524
524
|
return;
|
|
525
525
|
}
|
|
526
|
-
const p = l[1], g =
|
|
526
|
+
const p = l[1], g = b.get(p);
|
|
527
527
|
if (!g) {
|
|
528
528
|
t.writeHead(404, { "Content-Type": "text/plain" }), t.end(`Component not found: ${p}`);
|
|
529
529
|
return;
|
|
530
530
|
}
|
|
531
|
-
const
|
|
532
|
-
console.log(`π₯ Request: ${s.url} -> ${L}`), e.default.readFile(L, (
|
|
533
|
-
if (
|
|
531
|
+
const M = g.path, _ = l.slice(2), H = _.length === 0 ? "index.html" : _.join("/"), L = o.default.join(M, H);
|
|
532
|
+
console.log(`π₯ Request: ${s.url} -> ${L}`), e.default.readFile(L, (P, R) => {
|
|
533
|
+
if (P) {
|
|
534
534
|
console.log(`β File not found: ${L}`), t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Not Found");
|
|
535
535
|
return;
|
|
536
536
|
}
|
|
@@ -542,8 +542,8 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
542
542
|
});
|
|
543
543
|
}), ve = () => new Promise((s, t) => {
|
|
544
544
|
const r = JSON.stringify({
|
|
545
|
-
componentId:
|
|
546
|
-
distPath: o.default.resolve(N,
|
|
545
|
+
componentId: x,
|
|
546
|
+
distPath: o.default.resolve(N, S),
|
|
547
547
|
componentName: E
|
|
548
548
|
}), i = {
|
|
549
549
|
hostname: "localhost",
|
|
@@ -556,13 +556,13 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
556
556
|
}
|
|
557
557
|
}, l = a.default.request(i, (p) => {
|
|
558
558
|
let g = "";
|
|
559
|
-
p.on("data", (
|
|
559
|
+
p.on("data", (M) => g += M), p.on("end", () => {
|
|
560
560
|
p.statusCode === 200 ? s(JSON.parse(g)) : t(new Error(`Registration failed: ${p.statusCode}`));
|
|
561
561
|
});
|
|
562
562
|
});
|
|
563
563
|
l.on("error", t), l.write(r), l.end();
|
|
564
564
|
}), He = () => new Promise((s, t) => {
|
|
565
|
-
const r = JSON.stringify({ componentId:
|
|
565
|
+
const r = JSON.stringify({ componentId: x }), i = {
|
|
566
566
|
hostname: "localhost",
|
|
567
567
|
port: y,
|
|
568
568
|
path: "/_unregister",
|
|
@@ -577,7 +577,7 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
577
577
|
l.on("error", () => s()), l.write(r), l.end();
|
|
578
578
|
}), Le = () => {
|
|
579
579
|
if (!h) return;
|
|
580
|
-
const s = o.default.join(
|
|
580
|
+
const s = o.default.join(S, "index.html");
|
|
581
581
|
try {
|
|
582
582
|
let t = e.default.readFileSync(s, "utf-8");
|
|
583
583
|
if (t.includes("<!-- MYOP HMR -->")) {
|
|
@@ -588,7 +588,7 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
588
588
|
<!-- MYOP HMR -->
|
|
589
589
|
<script>
|
|
590
590
|
(function() {
|
|
591
|
-
const componentId = '${
|
|
591
|
+
const componentId = '${x}';
|
|
592
592
|
const wsUrl = 'ws://localhost:${y}/_hmr/' + componentId;
|
|
593
593
|
let ws;
|
|
594
594
|
let reconnectAttempts = 0;
|
|
@@ -716,11 +716,11 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
716
716
|
]), i;
|
|
717
717
|
}, Ue = () => {
|
|
718
718
|
if (!h) return;
|
|
719
|
-
const s = U.get(
|
|
719
|
+
const s = U.get(x);
|
|
720
720
|
if (!s || s.size === 0)
|
|
721
721
|
return;
|
|
722
722
|
console.log(`π₯ Notifying ${s.size} HMR client(s)`);
|
|
723
|
-
const t = o.default.join(
|
|
723
|
+
const t = o.default.join(S, "index.html");
|
|
724
724
|
try {
|
|
725
725
|
let r = e.default.readFileSync(t, "utf-8");
|
|
726
726
|
if (r.includes("<!-- MYOP HMR -->")) {
|
|
@@ -745,7 +745,7 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
745
745
|
let xe = !1;
|
|
746
746
|
const te = () => {
|
|
747
747
|
if (j) {
|
|
748
|
-
|
|
748
|
+
v = !0;
|
|
749
749
|
return;
|
|
750
750
|
}
|
|
751
751
|
j = !0, console.log(`
|
|
@@ -761,7 +761,7 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
761
761
|
console.error("β Build failed:", s.message), r && console.error(r);
|
|
762
762
|
} else
|
|
763
763
|
console.log("β
Build completed"), t && console.log(t), Le(), Ue();
|
|
764
|
-
|
|
764
|
+
v && (v = !1, te());
|
|
765
765
|
});
|
|
766
766
|
}, Se = /* @__PURE__ */ new Set(), be = (s) => {
|
|
767
767
|
e.default.readdir(s, { withFileTypes: !0 }, (t, r) => {
|
|
@@ -785,8 +785,8 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
785
785
|
const g = o.default.join(s, l);
|
|
786
786
|
setTimeout(() => {
|
|
787
787
|
try {
|
|
788
|
-
const
|
|
789
|
-
|
|
788
|
+
const M = e.default.readFileSync(g, "utf-8"), _ = k.get(g);
|
|
789
|
+
M !== _ && (k.set(g, M), console.log(`π File changed: ${g}`), te());
|
|
790
790
|
} catch {
|
|
791
791
|
}
|
|
792
792
|
}, 50);
|
|
@@ -794,7 +794,7 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
794
794
|
});
|
|
795
795
|
}, Ce = () => {
|
|
796
796
|
console.log(`
|
|
797
|
-
π¨ Component: ${
|
|
797
|
+
π¨ Component: ${x}`), te(), be(N), console.log("π Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
|
|
798
798
|
`);
|
|
799
799
|
}, Be = () => new Promise((s) => {
|
|
800
800
|
const t = {
|
|
@@ -815,10 +815,10 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
815
815
|
let l = "";
|
|
816
816
|
r.on("data", (p) => l += p), r.on("end", () => {
|
|
817
817
|
try {
|
|
818
|
-
const { componentId: p, distPath: g, componentName:
|
|
819
|
-
|
|
820
|
-
const
|
|
821
|
-
console.log(`β
Registered: ${p}${
|
|
818
|
+
const { componentId: p, distPath: g, componentName: M } = JSON.parse(l);
|
|
819
|
+
b.set(p, { path: g, name: M || null });
|
|
820
|
+
const _ = M ? ` (${M})` : "";
|
|
821
|
+
console.log(`β
Registered: ${p}${_} -> ${g}`), i.writeHead(200), i.end(JSON.stringify({ success: !0, registered: Array.from(b.keys()) }));
|
|
822
822
|
} catch (p) {
|
|
823
823
|
i.writeHead(400), i.end(JSON.stringify({ error: p.message }));
|
|
824
824
|
}
|
|
@@ -828,12 +828,12 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
828
828
|
r.on("data", (p) => l += p), r.on("end", () => {
|
|
829
829
|
try {
|
|
830
830
|
const { componentId: p } = JSON.parse(l);
|
|
831
|
-
|
|
831
|
+
b.delete(p), console.log(`β Unregistered: ${p}`), i.writeHead(200), i.end(JSON.stringify({ success: !0 }));
|
|
832
832
|
} catch (p) {
|
|
833
833
|
i.writeHead(400), i.end(JSON.stringify({ error: p.message }));
|
|
834
834
|
}
|
|
835
835
|
});
|
|
836
|
-
} else r.method === "GET" && r.url === "/_list" ? (i.writeHead(200), i.end(JSON.stringify({ components: Array.from(
|
|
836
|
+
} else r.method === "GET" && r.url === "/_list" ? (i.writeHead(200), i.end(JSON.stringify({ components: Array.from(b.entries()) }))) : (i.writeHead(404), i.end(JSON.stringify({ error: "Not found" })));
|
|
837
837
|
});
|
|
838
838
|
t.on("error", () => {
|
|
839
839
|
s(!1);
|
|
@@ -841,13 +841,13 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
841
841
|
console.log(`
|
|
842
842
|
π Taking over as server...`), console.log(`π‘ Management server on port ${y}`), ee.on("error", () => {
|
|
843
843
|
t.close(), s(!1);
|
|
844
|
-
}), ee.listen(
|
|
845
|
-
console.log(`π‘ Main server running at http://localhost:${
|
|
846
|
-
path: o.default.resolve(N,
|
|
844
|
+
}), ee.listen(u, () => {
|
|
845
|
+
console.log(`π‘ Main server running at http://localhost:${u}`), b.set(x, {
|
|
846
|
+
path: o.default.resolve(N, S),
|
|
847
847
|
name: E
|
|
848
848
|
});
|
|
849
849
|
const r = E ? ` (${E})` : "";
|
|
850
|
-
console.log(`β
Registered component: ${
|
|
850
|
+
console.log(`β
Registered component: ${x}${r}`), console.log(`π‘ Access at: http://localhost:${u}/view/${x}/`), s(!0);
|
|
851
851
|
});
|
|
852
852
|
});
|
|
853
853
|
});
|
|
@@ -857,7 +857,7 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
857
857
|
await Be() || (clearInterval(oe), console.log(`
|
|
858
858
|
β οΈ Server appears to be down, attempting to take over...`), await ze() ? console.log("β
Successfully took over as server") : (console.log("βΉοΈ Another instance took over, re-registering..."), setTimeout(async () => {
|
|
859
859
|
try {
|
|
860
|
-
await ve(), console.log(`β
Re-registered component: ${
|
|
860
|
+
await ve(), console.log(`β
Re-registered component: ${x}`), $e();
|
|
861
861
|
} catch (r) {
|
|
862
862
|
console.error("β Failed to re-register:", r.message);
|
|
863
863
|
}
|
|
@@ -873,9 +873,9 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
873
873
|
console.log(`
|
|
874
874
|
π Connecting to existing dev server...`);
|
|
875
875
|
try {
|
|
876
|
-
|
|
876
|
+
x = await $();
|
|
877
877
|
const t = await ve();
|
|
878
|
-
console.log(`β
Registered component: ${
|
|
878
|
+
console.log(`β
Registered component: ${x}`), console.log(`π‘ Access at: http://localhost:${u}/view/${x}/`), console.log(`π All registered components: ${t.registered.join(", ")}`), Ce(), $e();
|
|
879
879
|
} catch (t) {
|
|
880
880
|
console.error("β Failed to register component:", t.message), process.exit(1);
|
|
881
881
|
}
|
|
@@ -885,18 +885,18 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
885
885
|
console.log(`
|
|
886
886
|
π Starting shared dev server...`), console.log(`π‘ Management server on port ${y}`), ee.on("error", (s) => {
|
|
887
887
|
console.error("β Main server error:", s.message), process.exit(1);
|
|
888
|
-
}), ee.listen(
|
|
889
|
-
console.log(`π‘ Main server running at http://localhost:${
|
|
890
|
-
path: o.default.resolve(N,
|
|
888
|
+
}), ee.listen(u, async () => {
|
|
889
|
+
console.log(`π‘ Main server running at http://localhost:${u}`), (x === "DEV" || x === "NEW") && (x = "DEV1"), b.set(x, {
|
|
890
|
+
path: o.default.resolve(N, S),
|
|
891
891
|
name: E
|
|
892
892
|
});
|
|
893
893
|
const s = E ? ` (${E})` : "";
|
|
894
|
-
console.log(`β
Registered component: ${
|
|
894
|
+
console.log(`β
Registered component: ${x}${s}`), console.log(`π‘ Access at: http://localhost:${u}/view/${x}/`), Ce();
|
|
895
895
|
});
|
|
896
896
|
});
|
|
897
897
|
}
|
|
898
|
-
const ue = Z.join(
|
|
899
|
-
function
|
|
898
|
+
const ue = Z.join(Xe.homedir(), ".myop"), Q = Z.join(ue, "credentials.json");
|
|
899
|
+
function at() {
|
|
900
900
|
A.existsSync(ue) || A.mkdirSync(ue, { recursive: !0, mode: 448 });
|
|
901
901
|
}
|
|
902
902
|
function he() {
|
|
@@ -910,7 +910,7 @@ function he() {
|
|
|
910
910
|
}
|
|
911
911
|
}
|
|
912
912
|
function Te(e) {
|
|
913
|
-
|
|
913
|
+
at();
|
|
914
914
|
const o = {
|
|
915
915
|
...e,
|
|
916
916
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -927,7 +927,7 @@ function Re() {
|
|
|
927
927
|
return console.error("Failed to clear credentials:", e.message), !1;
|
|
928
928
|
}
|
|
929
929
|
}
|
|
930
|
-
function
|
|
930
|
+
function ct(e) {
|
|
931
931
|
if (!e || !e.expiresAt)
|
|
932
932
|
return !0;
|
|
933
933
|
const o = 5 * 60 * 1e3, n = new Date(e.expiresAt).getTime();
|
|
@@ -940,19 +940,19 @@ function ye() {
|
|
|
940
940
|
userId: e.userId
|
|
941
941
|
} : null;
|
|
942
942
|
}
|
|
943
|
-
const Y = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", ie = 19284, we = `http://localhost:${ie}/callback`,
|
|
944
|
-
function
|
|
943
|
+
const Y = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", ie = 19284, we = `http://localhost:${ie}/callback`, lt = "myop-cli";
|
|
944
|
+
function dt() {
|
|
945
945
|
return fe.randomBytes(32).toString("base64url");
|
|
946
946
|
}
|
|
947
|
-
function
|
|
947
|
+
function pt(e) {
|
|
948
948
|
return fe.createHash("sha256").update(e).digest("base64url");
|
|
949
949
|
}
|
|
950
|
-
async function
|
|
950
|
+
async function mt() {
|
|
951
951
|
const e = await fetch(`${Y}/oauth/register`, {
|
|
952
952
|
method: "POST",
|
|
953
953
|
headers: { "Content-Type": "application/json" },
|
|
954
954
|
body: JSON.stringify({
|
|
955
|
-
client_name:
|
|
955
|
+
client_name: lt,
|
|
956
956
|
redirect_uris: [we],
|
|
957
957
|
grant_types: ["authorization_code", "refresh_token"],
|
|
958
958
|
response_types: ["code"]
|
|
@@ -965,7 +965,7 @@ async function pt() {
|
|
|
965
965
|
return e.json();
|
|
966
966
|
}
|
|
967
967
|
function se(e, o, n, a = null) {
|
|
968
|
-
const
|
|
968
|
+
const f = {
|
|
969
969
|
success: `<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#4ade80" stroke-width="2">
|
|
970
970
|
<circle cx="12" cy="12" r="10"/>
|
|
971
971
|
<path d="M8 12l2.5 2.5L16 9"/>
|
|
@@ -982,7 +982,7 @@ function se(e, o, n, a = null) {
|
|
|
982
982
|
success: { accent: "#4ade80", glow: "rgba(74, 222, 128, 0.1)" },
|
|
983
983
|
error: { accent: "#f87171", glow: "rgba(248, 113, 113, 0.1)" },
|
|
984
984
|
warning: { accent: "#fbbf24", glow: "rgba(251, 191, 36, 0.1)" }
|
|
985
|
-
}, { accent: m, glow:
|
|
985
|
+
}, { accent: m, glow: w } = c[e] || c.error;
|
|
986
986
|
return `<!DOCTYPE html>
|
|
987
987
|
<html lang="en">
|
|
988
988
|
<head>
|
|
@@ -1075,7 +1075,7 @@ function se(e, o, n, a = null) {
|
|
|
1075
1075
|
display: inline-flex;
|
|
1076
1076
|
align-items: center;
|
|
1077
1077
|
gap: 8px;
|
|
1078
|
-
background: ${
|
|
1078
|
+
background: ${w};
|
|
1079
1079
|
border: 1px solid ${m}33;
|
|
1080
1080
|
border-radius: 4px;
|
|
1081
1081
|
padding: 10px 16px;
|
|
@@ -1113,7 +1113,7 @@ function se(e, o, n, a = null) {
|
|
|
1113
1113
|
<body>
|
|
1114
1114
|
<div class="container">
|
|
1115
1115
|
<div class="icon">
|
|
1116
|
-
${
|
|
1116
|
+
${f[e] || f.error}
|
|
1117
1117
|
</div>
|
|
1118
1118
|
<h1>${o}</h1>
|
|
1119
1119
|
<p class="message">${n}</p>
|
|
@@ -1130,22 +1130,22 @@ function se(e, o, n, a = null) {
|
|
|
1130
1130
|
</body>
|
|
1131
1131
|
</html>`;
|
|
1132
1132
|
}
|
|
1133
|
-
function
|
|
1133
|
+
function ut(e) {
|
|
1134
1134
|
return new Promise((o, n) => {
|
|
1135
|
-
const a =
|
|
1136
|
-
const m = new je(
|
|
1135
|
+
const a = Ye.createServer((f, c) => {
|
|
1136
|
+
const m = new je(f.url, `http://localhost:${ie}`);
|
|
1137
1137
|
if (m.pathname === "/callback") {
|
|
1138
|
-
const
|
|
1139
|
-
if (
|
|
1138
|
+
const w = m.searchParams.get("code"), I = m.searchParams.get("state"), u = m.searchParams.get("error");
|
|
1139
|
+
if (u) {
|
|
1140
1140
|
c.writeHead(200, { "Content-Type": "text/html" }), c.end(se(
|
|
1141
1141
|
"error",
|
|
1142
1142
|
"Authentication Failed",
|
|
1143
1143
|
"Unable to complete the authentication process.",
|
|
1144
|
-
|
|
1145
|
-
)), a.close(), n(new Error(`OAuth error: ${
|
|
1144
|
+
u
|
|
1145
|
+
)), a.close(), n(new Error(`OAuth error: ${u}`));
|
|
1146
1146
|
return;
|
|
1147
1147
|
}
|
|
1148
|
-
if (
|
|
1148
|
+
if (I !== e) {
|
|
1149
1149
|
c.writeHead(400, { "Content-Type": "text/html" }), c.end(se(
|
|
1150
1150
|
"warning",
|
|
1151
1151
|
"Security Error",
|
|
@@ -1154,7 +1154,7 @@ function mt(e) {
|
|
|
1154
1154
|
)), a.close(), n(new Error("State mismatch"));
|
|
1155
1155
|
return;
|
|
1156
1156
|
}
|
|
1157
|
-
if (!
|
|
1157
|
+
if (!w) {
|
|
1158
1158
|
c.writeHead(400, { "Content-Type": "text/html" }), c.end(se(
|
|
1159
1159
|
"error",
|
|
1160
1160
|
"Missing Authorization Code",
|
|
@@ -1167,7 +1167,7 @@ function mt(e) {
|
|
|
1167
1167
|
"success",
|
|
1168
1168
|
"Authentication Successful",
|
|
1169
1169
|
"You have been authenticated successfully. Return to the terminal to continue."
|
|
1170
|
-
)), a.close(), o(
|
|
1170
|
+
)), a.close(), o(w);
|
|
1171
1171
|
} else
|
|
1172
1172
|
c.writeHead(404), c.end("Not found");
|
|
1173
1173
|
});
|
|
@@ -1178,11 +1178,11 @@ function mt(e) {
|
|
|
1178
1178
|
}, 5 * 60 * 1e3);
|
|
1179
1179
|
});
|
|
1180
1180
|
}
|
|
1181
|
-
async function
|
|
1181
|
+
async function ft(e, o, n) {
|
|
1182
1182
|
const a = await fetch(`${Y}/oauth/token`, {
|
|
1183
1183
|
method: "POST",
|
|
1184
1184
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1185
|
-
body: new
|
|
1185
|
+
body: new _e({
|
|
1186
1186
|
grant_type: "authorization_code",
|
|
1187
1187
|
code: e,
|
|
1188
1188
|
client_id: o,
|
|
@@ -1191,16 +1191,16 @@ async function ut(e, o, n) {
|
|
|
1191
1191
|
})
|
|
1192
1192
|
});
|
|
1193
1193
|
if (!a.ok) {
|
|
1194
|
-
const
|
|
1195
|
-
throw new Error(
|
|
1194
|
+
const f = await a.json();
|
|
1195
|
+
throw new Error(f.error_description || f.error || "Token exchange failed");
|
|
1196
1196
|
}
|
|
1197
1197
|
return a.json();
|
|
1198
1198
|
}
|
|
1199
|
-
async function
|
|
1199
|
+
async function gt(e, o) {
|
|
1200
1200
|
const n = await fetch(`${Y}/oauth/token`, {
|
|
1201
1201
|
method: "POST",
|
|
1202
1202
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1203
|
-
body: new
|
|
1203
|
+
body: new _e({
|
|
1204
1204
|
grant_type: "refresh_token",
|
|
1205
1205
|
refresh_token: e,
|
|
1206
1206
|
client_id: o
|
|
@@ -1212,8 +1212,8 @@ async function ft(e, o) {
|
|
|
1212
1212
|
}
|
|
1213
1213
|
return n.json();
|
|
1214
1214
|
}
|
|
1215
|
-
async function
|
|
1216
|
-
var
|
|
1215
|
+
async function ht(e) {
|
|
1216
|
+
var f, c, m;
|
|
1217
1217
|
const o = await fetch(`${Y}/mcp`, {
|
|
1218
1218
|
method: "POST",
|
|
1219
1219
|
headers: {
|
|
@@ -1235,7 +1235,7 @@ async function gt(e) {
|
|
|
1235
1235
|
const n = await o.json();
|
|
1236
1236
|
if (n.error)
|
|
1237
1237
|
throw new Error(n.error.message);
|
|
1238
|
-
const a = (m = (c = (
|
|
1238
|
+
const a = (m = (c = (f = n.result) == null ? void 0 : f.content) == null ? void 0 : c[0]) == null ? void 0 : m.text;
|
|
1239
1239
|
if (a)
|
|
1240
1240
|
return JSON.parse(a);
|
|
1241
1241
|
throw new Error("Invalid response from whoami");
|
|
@@ -1244,25 +1244,25 @@ async function X() {
|
|
|
1244
1244
|
const e = F("Starting authentication...").start();
|
|
1245
1245
|
try {
|
|
1246
1246
|
e.text = "Registering OAuth client...";
|
|
1247
|
-
const n = (await
|
|
1247
|
+
const n = (await mt()).client_id, a = dt(), f = pt(a), c = fe.randomBytes(16).toString("hex");
|
|
1248
1248
|
e.text = "Waiting for authorization...";
|
|
1249
|
-
const m =
|
|
1250
|
-
|
|
1251
|
-
π Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${
|
|
1252
|
-
`), await
|
|
1253
|
-
const
|
|
1249
|
+
const m = ut(c), w = new je(`${Y}/oauth/authorize`);
|
|
1250
|
+
w.searchParams.set("response_type", "code"), w.searchParams.set("client_id", n), w.searchParams.set("redirect_uri", we), w.searchParams.set("code_challenge", f), w.searchParams.set("code_challenge_method", "S256"), w.searchParams.set("state", c), e.stop(), console.log(`
|
|
1251
|
+
π Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${w.toString()}
|
|
1252
|
+
`), await Ke(w.toString());
|
|
1253
|
+
const I = await m;
|
|
1254
1254
|
e.start("Exchanging authorization code...");
|
|
1255
|
-
const
|
|
1255
|
+
const u = await ft(I, n, a);
|
|
1256
1256
|
e.text = "Getting user info...";
|
|
1257
|
-
const y = await
|
|
1258
|
-
accessToken:
|
|
1259
|
-
refreshToken:
|
|
1260
|
-
expiresAt: new Date(Date.now() +
|
|
1257
|
+
const y = await ht(u.access_token), S = {
|
|
1258
|
+
accessToken: u.access_token,
|
|
1259
|
+
refreshToken: u.refresh_token,
|
|
1260
|
+
expiresAt: new Date(Date.now() + u.expires_in * 1e3).toISOString(),
|
|
1261
1261
|
clientId: n,
|
|
1262
1262
|
userId: y.userId,
|
|
1263
1263
|
userEmail: y.email
|
|
1264
1264
|
};
|
|
1265
|
-
return Te(
|
|
1265
|
+
return Te(S), e.succeed(`Authenticated as ${y.email}`), S;
|
|
1266
1266
|
} catch (o) {
|
|
1267
1267
|
throw e.fail(`Authentication failed: ${o.message}`), o;
|
|
1268
1268
|
}
|
|
@@ -1275,17 +1275,17 @@ async function Fe() {
|
|
|
1275
1275
|
}
|
|
1276
1276
|
Re(), console.log(`β
Logged out (was: ${e.userEmail})`);
|
|
1277
1277
|
}
|
|
1278
|
-
async function
|
|
1278
|
+
async function yt() {
|
|
1279
1279
|
let e = he();
|
|
1280
1280
|
if (!e)
|
|
1281
1281
|
return console.log(`Not logged in. Starting authentication...
|
|
1282
1282
|
`), await X();
|
|
1283
|
-
if (!
|
|
1283
|
+
if (!ct(e))
|
|
1284
1284
|
return e;
|
|
1285
1285
|
if (e.refreshToken) {
|
|
1286
1286
|
const o = F("Refreshing access token...").start();
|
|
1287
1287
|
try {
|
|
1288
|
-
const n = await
|
|
1288
|
+
const n = await gt(
|
|
1289
1289
|
e.refreshToken,
|
|
1290
1290
|
e.clientId
|
|
1291
1291
|
);
|
|
@@ -1302,11 +1302,11 @@ async function ht() {
|
|
|
1302
1302
|
return console.log(`Session expired. Please log in again.
|
|
1303
1303
|
`), await X();
|
|
1304
1304
|
}
|
|
1305
|
-
function
|
|
1305
|
+
function wt() {
|
|
1306
1306
|
return Y;
|
|
1307
1307
|
}
|
|
1308
1308
|
const ae = "@myop/cli";
|
|
1309
|
-
async function
|
|
1309
|
+
async function vt() {
|
|
1310
1310
|
try {
|
|
1311
1311
|
const e = await fetch(`https://registry.npmjs.org/${ae}/latest`);
|
|
1312
1312
|
return e.ok ? (await e.json()).version : null;
|
|
@@ -1314,21 +1314,21 @@ async function wt() {
|
|
|
1314
1314
|
return null;
|
|
1315
1315
|
}
|
|
1316
1316
|
}
|
|
1317
|
-
function
|
|
1317
|
+
function xt(e, o) {
|
|
1318
1318
|
const n = e.split(".").map(Number), a = o.split(".").map(Number);
|
|
1319
|
-
for (let
|
|
1320
|
-
const c = n[
|
|
1319
|
+
for (let f = 0; f < Math.max(n.length, a.length); f++) {
|
|
1320
|
+
const c = n[f] || 0, m = a[f] || 0;
|
|
1321
1321
|
if (c > m) return 1;
|
|
1322
1322
|
if (c < m) return -1;
|
|
1323
1323
|
}
|
|
1324
1324
|
return 0;
|
|
1325
1325
|
}
|
|
1326
|
-
async function
|
|
1326
|
+
async function St(e) {
|
|
1327
1327
|
const o = F({
|
|
1328
1328
|
text: "Checking for updates...",
|
|
1329
1329
|
color: "cyan"
|
|
1330
|
-
}).start(), n = await
|
|
1331
|
-
if (o.stop(), !n ||
|
|
1330
|
+
}).start(), n = await vt();
|
|
1331
|
+
if (o.stop(), !n || xt(n, e) <= 0)
|
|
1332
1332
|
return !1;
|
|
1333
1333
|
console.log(`
|
|
1334
1334
|
π¦ New version available: ${e} β ${n}
|
|
@@ -1342,30 +1342,35 @@ async function xt(e) {
|
|
|
1342
1342
|
{ name: "No, continue with current version", value: !1 }
|
|
1343
1343
|
]
|
|
1344
1344
|
});
|
|
1345
|
-
} catch (
|
|
1346
|
-
throw
|
|
1345
|
+
} catch (f) {
|
|
1346
|
+
throw f.name === "ExitPromptError" && (console.log(`
|
|
1347
1347
|
|
|
1348
1348
|
π Goodbye!
|
|
1349
|
-
`), process.exit(0)),
|
|
1349
|
+
`), process.exit(0)), f;
|
|
1350
1350
|
}
|
|
1351
1351
|
if (a) {
|
|
1352
|
-
const
|
|
1352
|
+
const f = F({
|
|
1353
1353
|
text: `Updating ${ae} to v${n}...`,
|
|
1354
1354
|
color: "green"
|
|
1355
1355
|
}).start();
|
|
1356
1356
|
try {
|
|
1357
|
-
re(`npm install -g ${ae}@latest`, { stdio: "pipe" }),
|
|
1358
|
-
|
|
1359
|
-
`), process.
|
|
1357
|
+
return re(`npm install -g ${ae}@latest`, { stdio: "pipe" }), f.succeed(`Updated to v${n}`), console.log(`
|
|
1358
|
+
π Restarting with new version...
|
|
1359
|
+
`), Ge("myop", process.argv.slice(2), {
|
|
1360
|
+
stdio: "inherit",
|
|
1361
|
+
shell: !0
|
|
1362
|
+
}).on("close", (m) => {
|
|
1363
|
+
process.exit(m || 0);
|
|
1364
|
+
}), !0;
|
|
1360
1365
|
} catch {
|
|
1361
|
-
return
|
|
1366
|
+
return f.fail("Update failed"), console.log(`
|
|
1362
1367
|
You can manually update by running: npm install -g ${ae}@latest
|
|
1363
1368
|
`), !1;
|
|
1364
1369
|
}
|
|
1365
1370
|
}
|
|
1366
1371
|
return !1;
|
|
1367
1372
|
}
|
|
1368
|
-
const
|
|
1373
|
+
const bt = (e) => new Promise((o) => setTimeout(o, e));
|
|
1369
1374
|
d.executionPath = process.cwd();
|
|
1370
1375
|
const le = (e = !1) => {
|
|
1371
1376
|
const o = d.program.getOptionValue("verbose");
|
|
@@ -1375,7 +1380,7 @@ const le = (e = !1) => {
|
|
|
1375
1380
|
verbose: o
|
|
1376
1381
|
};
|
|
1377
1382
|
try {
|
|
1378
|
-
return d.myopConfig =
|
|
1383
|
+
return d.myopConfig = Ze(d.options.configPath), { configFound: !0 };
|
|
1379
1384
|
} catch (n) {
|
|
1380
1385
|
if (e) {
|
|
1381
1386
|
console.info(`
|
|
@@ -1395,11 +1400,11 @@ const le = (e = !1) => {
|
|
|
1395
1400
|
};
|
|
1396
1401
|
[
|
|
1397
1402
|
new me(),
|
|
1398
|
-
...
|
|
1403
|
+
...rt
|
|
1399
1404
|
];
|
|
1400
|
-
const
|
|
1405
|
+
const Ct = "0.1.17";
|
|
1401
1406
|
d.program = new We();
|
|
1402
|
-
d.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(
|
|
1407
|
+
d.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(Ct);
|
|
1403
1408
|
d.program.addOption(new ce("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
|
|
1404
1409
|
d.program.addOption(new ce("-h, --help", "Show helpful information"));
|
|
1405
1410
|
d.program.addOption(new ce("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
|
|
@@ -1411,7 +1416,7 @@ d.program.command("remove").description("Remove Myop asset").argument("<type>",
|
|
|
1411
1416
|
le(), console.info("removing ", e, o, d.options.configPath), e === "flow" && Ne._action(o), process.exit();
|
|
1412
1417
|
});
|
|
1413
1418
|
d.program.command("install").description("Install Myop assets").action(async () => {
|
|
1414
|
-
le(), await
|
|
1419
|
+
le(), await Pe.action();
|
|
1415
1420
|
});
|
|
1416
1421
|
d.program.command("login").description("Authenticate with Myop platform").action(async () => {
|
|
1417
1422
|
try {
|
|
@@ -1429,15 +1434,15 @@ d.program.command("whoami").description("Show current authenticated user").actio
|
|
|
1429
1434
|
e && e.email ? console.log(`Logged in as: ${e.email}`) : console.log("Not logged in. Run `myop login` to authenticate."), process.exit(0);
|
|
1430
1435
|
});
|
|
1431
1436
|
d.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (e) => {
|
|
1432
|
-
var j,
|
|
1433
|
-
const o = d.program.getOptionValue("config") || "./myop.config.json", n = await import("fs"), { execSync: a } = await import("child_process"),
|
|
1437
|
+
var j, v, k, z, x, E;
|
|
1438
|
+
const o = d.program.getOptionValue("config") || "./myop.config.json", n = await import("fs"), { execSync: a } = await import("child_process"), f = await import("path");
|
|
1434
1439
|
let c = {};
|
|
1435
1440
|
if (n.existsSync(o))
|
|
1436
1441
|
try {
|
|
1437
1442
|
const h = n.readFileSync(o, "utf-8");
|
|
1438
1443
|
c = JSON.parse(h);
|
|
1439
|
-
const
|
|
1440
|
-
console.log(`π Found config: ${
|
|
1444
|
+
const $ = c.name || c.componentName;
|
|
1445
|
+
console.log(`π Found config: ${$ || "Unnamed component"}`), c.componentId && console.log(` Component ID: ${c.componentId}`);
|
|
1441
1446
|
} catch (h) {
|
|
1442
1447
|
console.error(`β οΈ Failed to parse ${o}:`, h.message);
|
|
1443
1448
|
}
|
|
@@ -1447,26 +1452,26 @@ d.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1447
1452
|
const h = F("Building project...").start();
|
|
1448
1453
|
try {
|
|
1449
1454
|
a("npm run build", { stdio: "pipe" }), h.succeed("Build completed");
|
|
1450
|
-
} catch (
|
|
1451
|
-
h.fail("Build failed"), console.error(
|
|
1455
|
+
} catch ($) {
|
|
1456
|
+
h.fail("Build failed"), console.error($.message), process.exit(1);
|
|
1452
1457
|
}
|
|
1453
1458
|
}
|
|
1454
1459
|
const m = "./dist/index.html";
|
|
1455
1460
|
n.existsSync(m) || (console.error("β Error: ./dist/index.html not found"), console.log(" Make sure your build outputs to ./dist/index.html"), process.exit(1));
|
|
1456
|
-
let
|
|
1461
|
+
let w;
|
|
1457
1462
|
try {
|
|
1458
|
-
|
|
1463
|
+
w = await yt();
|
|
1459
1464
|
} catch (h) {
|
|
1460
1465
|
console.error("β Authentication failed:", h.message), process.exit(1);
|
|
1461
1466
|
}
|
|
1462
|
-
const
|
|
1463
|
-
let
|
|
1467
|
+
const I = wt();
|
|
1468
|
+
let u = F("Requesting upload URL...").start(), y;
|
|
1464
1469
|
try {
|
|
1465
|
-
const h = await fetch(`${
|
|
1470
|
+
const h = await fetch(`${I}/mcp`, {
|
|
1466
1471
|
method: "POST",
|
|
1467
1472
|
headers: {
|
|
1468
1473
|
"Content-Type": "application/json",
|
|
1469
|
-
Authorization: `Bearer ${
|
|
1474
|
+
Authorization: `Bearer ${w.accessToken}`
|
|
1470
1475
|
},
|
|
1471
1476
|
body: JSON.stringify({
|
|
1472
1477
|
jsonrpc: "2.0",
|
|
@@ -1475,7 +1480,7 @@ d.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1475
1480
|
params: {
|
|
1476
1481
|
name: "upload_component",
|
|
1477
1482
|
arguments: {
|
|
1478
|
-
name: c.name || c.componentName ||
|
|
1483
|
+
name: c.name || c.componentName || f.default.basename(process.cwd()),
|
|
1479
1484
|
componentId: c.componentId || void 0,
|
|
1480
1485
|
organization: c.organization || void 0
|
|
1481
1486
|
}
|
|
@@ -1484,32 +1489,32 @@ d.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1484
1489
|
});
|
|
1485
1490
|
if (!h.ok)
|
|
1486
1491
|
throw new Error(`Server returned ${h.status}`);
|
|
1487
|
-
const
|
|
1488
|
-
if (
|
|
1489
|
-
throw new Error(
|
|
1490
|
-
const N = (k = (
|
|
1492
|
+
const $ = await h.json();
|
|
1493
|
+
if ($.error)
|
|
1494
|
+
throw new Error($.error.message);
|
|
1495
|
+
const N = (k = (v = (j = $.result) == null ? void 0 : j.content) == null ? void 0 : v[0]) == null ? void 0 : k.text;
|
|
1491
1496
|
if (y = JSON.parse(N), !y.success)
|
|
1492
1497
|
throw new Error(y.error);
|
|
1493
|
-
|
|
1498
|
+
u.succeed("Upload URL obtained");
|
|
1494
1499
|
} catch (h) {
|
|
1495
|
-
|
|
1500
|
+
u.fail("Failed to get upload URL"), console.error(" ", h.message), process.exit(1);
|
|
1496
1501
|
}
|
|
1497
|
-
|
|
1502
|
+
u = F("Uploading component...").start();
|
|
1498
1503
|
try {
|
|
1499
1504
|
const h = n.readFileSync(m, "utf-8");
|
|
1500
|
-
let
|
|
1505
|
+
let $;
|
|
1501
1506
|
const N = y.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
|
|
1502
1507
|
if (N)
|
|
1503
|
-
|
|
1508
|
+
$ = N[1];
|
|
1504
1509
|
else {
|
|
1505
|
-
const
|
|
1506
|
-
if (
|
|
1507
|
-
|
|
1510
|
+
const b = y.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
|
|
1511
|
+
if (b)
|
|
1512
|
+
$ = b[1];
|
|
1508
1513
|
else
|
|
1509
1514
|
throw new Error("Could not parse presigned URL from: " + y.curlCommand);
|
|
1510
1515
|
}
|
|
1511
|
-
console.info("Uploading to:",
|
|
1512
|
-
const K = await fetch(
|
|
1516
|
+
console.info("Uploading to:", $.substring(0, 100) + "...");
|
|
1517
|
+
const K = await fetch($, {
|
|
1513
1518
|
method: "PUT",
|
|
1514
1519
|
headers: {
|
|
1515
1520
|
"Content-Type": "text/html"
|
|
@@ -1517,21 +1522,21 @@ d.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1517
1522
|
body: h
|
|
1518
1523
|
});
|
|
1519
1524
|
if (!K.ok) {
|
|
1520
|
-
const
|
|
1521
|
-
throw new Error(`Upload failed with status ${K.status}: ${
|
|
1525
|
+
const b = await K.text();
|
|
1526
|
+
throw new Error(`Upload failed with status ${K.status}: ${b}`);
|
|
1522
1527
|
}
|
|
1523
|
-
|
|
1528
|
+
u.succeed("Component uploaded");
|
|
1524
1529
|
} catch (h) {
|
|
1525
|
-
|
|
1530
|
+
u.fail("Upload failed"), console.error(" ", h.message), h.cause && console.error(" Cause:", h.cause), process.exit(1);
|
|
1526
1531
|
}
|
|
1527
|
-
|
|
1528
|
-
let
|
|
1532
|
+
u = F("Confirming upload...").start();
|
|
1533
|
+
let S;
|
|
1529
1534
|
try {
|
|
1530
|
-
const h = await fetch(`${
|
|
1535
|
+
const h = await fetch(`${I}/mcp`, {
|
|
1531
1536
|
method: "POST",
|
|
1532
1537
|
headers: {
|
|
1533
1538
|
"Content-Type": "application/json",
|
|
1534
|
-
Authorization: `Bearer ${
|
|
1539
|
+
Authorization: `Bearer ${w.accessToken}`
|
|
1535
1540
|
},
|
|
1536
1541
|
body: JSON.stringify({
|
|
1537
1542
|
jsonrpc: "2.0",
|
|
@@ -1547,31 +1552,31 @@ d.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1547
1552
|
});
|
|
1548
1553
|
if (!h.ok)
|
|
1549
1554
|
throw new Error(`Server returned ${h.status}`);
|
|
1550
|
-
const
|
|
1551
|
-
if (
|
|
1552
|
-
throw new Error(
|
|
1553
|
-
const N = (E = (
|
|
1554
|
-
if (
|
|
1555
|
-
throw new Error(
|
|
1556
|
-
|
|
1555
|
+
const $ = await h.json();
|
|
1556
|
+
if ($.error)
|
|
1557
|
+
throw new Error($.error.message);
|
|
1558
|
+
const N = (E = (x = (z = $.result) == null ? void 0 : z.content) == null ? void 0 : x[0]) == null ? void 0 : E.text;
|
|
1559
|
+
if (S = JSON.parse(N), !S.success)
|
|
1560
|
+
throw new Error(S.error);
|
|
1561
|
+
u.succeed("Upload confirmed");
|
|
1557
1562
|
} catch (h) {
|
|
1558
|
-
|
|
1563
|
+
u.fail("Confirmation failed"), console.error(" ", h.message), process.exit(1);
|
|
1559
1564
|
}
|
|
1560
|
-
if (
|
|
1561
|
-
c.componentId =
|
|
1565
|
+
if (S.isNewComponent || !c.componentId) {
|
|
1566
|
+
c.componentId = S.componentId, c.organization = S.orgId, c.name || (c.name = S.componentName);
|
|
1562
1567
|
try {
|
|
1563
1568
|
n.writeFileSync(o, JSON.stringify(c, null, 2)), console.log(`
|
|
1564
1569
|
π Updated ${o} with componentId`);
|
|
1565
1570
|
} catch (h) {
|
|
1566
1571
|
console.log(`
|
|
1567
|
-
β οΈ Could not update ${o}: ${h.message}`), console.log(` Please add componentId: "${
|
|
1572
|
+
β οΈ Could not update ${o}: ${h.message}`), console.log(` Please add componentId: "${S.componentId}" manually`);
|
|
1568
1573
|
}
|
|
1569
1574
|
}
|
|
1570
1575
|
console.log(`
|
|
1571
|
-
β
Sync completed successfully!`), console.log(` Component: ${
|
|
1576
|
+
β
Sync completed successfully!`), console.log(` Component: ${S.componentName}`), console.log(` Dashboard: ${S.dashboardUrl}`), process.exit(0);
|
|
1572
1577
|
});
|
|
1573
1578
|
d.program.command("dev").description("Start development server with file watching").action(ke);
|
|
1574
|
-
const
|
|
1579
|
+
const $t = () => {
|
|
1575
1580
|
try {
|
|
1576
1581
|
re("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
1577
1582
|
} catch {
|
|
@@ -1594,22 +1599,22 @@ const Ct = () => {
|
|
|
1594
1599
|
deletions: 0
|
|
1595
1600
|
};
|
|
1596
1601
|
const o = e.split(`
|
|
1597
|
-
`), n = o[o.length - 1], a = n.match(/(\d+) insertion/),
|
|
1602
|
+
`), n = o[o.length - 1], a = n.match(/(\d+) insertion/), f = n.match(/(\d+) deletion/), c = n.match(/(\d+) file/);
|
|
1598
1603
|
return {
|
|
1599
1604
|
files: c ? parseInt(c[1]) : 0,
|
|
1600
1605
|
insertions: a ? parseInt(a[1]) : 0,
|
|
1601
|
-
deletions:
|
|
1606
|
+
deletions: f ? parseInt(f[1]) : 0
|
|
1602
1607
|
};
|
|
1603
1608
|
} catch {
|
|
1604
1609
|
return null;
|
|
1605
1610
|
}
|
|
1606
1611
|
}, B = async (e = !1, o = !1) => {
|
|
1607
|
-
var y,
|
|
1608
|
-
const n = ye(), a = !!(n != null && n.email),
|
|
1612
|
+
var y, S, j;
|
|
1613
|
+
const n = ye(), a = !!(n != null && n.email), f = ((y = d.myopConfig) == null ? void 0 : y.name) || ((S = d.myopConfig) == null ? void 0 : S.componentName), c = (j = d.myopConfig) == null ? void 0 : j.componentId, m = $t();
|
|
1609
1614
|
console.log(`
|
|
1610
1615
|
βββββββββββββββββββββββββββββββββββββββββββββββββββ`), console.log("β β"), console.log("β Welcome to Myop CLI - Remote UI Made Easy β"), console.log("β β"), console.log(`βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
1611
|
-
`), e &&
|
|
1612
|
-
const
|
|
1616
|
+
`), e && f ? (console.log(` Component: ${f}`), 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"}`), m != null && m.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")) : m != null && m.notARepo ? console.log(" Changes: Not a git repository") : m && (m.insertions > 0 || m.deletions > 0) ? console.log(` Changes: ${m.files} file${m.files !== 1 ? "s" : ""} | \x1B[32m+${m.insertions}\x1B[0m \x1B[31m-${m.deletions}\x1B[0m`) : m && console.log(" Changes: No uncommitted changes"), console.log("");
|
|
1617
|
+
const I = [
|
|
1613
1618
|
{
|
|
1614
1619
|
emoji: "π",
|
|
1615
1620
|
label: "Initialize new component",
|
|
@@ -1619,25 +1624,25 @@ const Ct = () => {
|
|
|
1619
1624
|
},
|
|
1620
1625
|
{
|
|
1621
1626
|
emoji: "π¦",
|
|
1622
|
-
label:
|
|
1627
|
+
label: f ? `Push "${f}"` : "Push component",
|
|
1623
1628
|
value: "sync",
|
|
1624
1629
|
help: "Builds project & uploads dist/index.html to Myop",
|
|
1625
1630
|
disabled: e ? a ? !1 : "(login required)" : "(no config file)"
|
|
1626
1631
|
},
|
|
1627
1632
|
{
|
|
1628
1633
|
emoji: "π οΈ ",
|
|
1629
|
-
label:
|
|
1634
|
+
label: f ? `Start dev mode for "${f}"` : "Start dev mode",
|
|
1630
1635
|
value: "dev",
|
|
1631
1636
|
help: "Starts dev server with HMR for instant preview of changes",
|
|
1632
1637
|
disabled: e ? !1 : "(no config file)"
|
|
1633
1638
|
}
|
|
1634
|
-
].map((
|
|
1635
|
-
name: o && !
|
|
1636
|
-
${
|
|
1637
|
-
value:
|
|
1638
|
-
disabled:
|
|
1639
|
+
].map((v) => ({
|
|
1640
|
+
name: o && !v.disabled ? `${v.emoji} ${v.label}
|
|
1641
|
+
${v.help}` : `${v.emoji} ${v.label}`,
|
|
1642
|
+
value: v.value,
|
|
1643
|
+
disabled: v.disabled
|
|
1639
1644
|
}));
|
|
1640
|
-
|
|
1645
|
+
I.push(
|
|
1641
1646
|
new me(),
|
|
1642
1647
|
{
|
|
1643
1648
|
name: o && a ? `π Logout (${n.email})
|
|
@@ -1655,29 +1660,29 @@ const Ct = () => {
|
|
|
1655
1660
|
value: "exit"
|
|
1656
1661
|
}
|
|
1657
1662
|
);
|
|
1658
|
-
let
|
|
1663
|
+
let u;
|
|
1659
1664
|
try {
|
|
1660
|
-
|
|
1665
|
+
u = await Ie({
|
|
1661
1666
|
message: "What would you like to do?",
|
|
1662
|
-
choices:
|
|
1667
|
+
choices: I
|
|
1663
1668
|
});
|
|
1664
|
-
} catch (
|
|
1665
|
-
throw
|
|
1669
|
+
} catch (v) {
|
|
1670
|
+
throw v.name === "ExitPromptError" && (console.log(`
|
|
1666
1671
|
|
|
1667
1672
|
π Goodbye!
|
|
1668
|
-
`), process.exit(0)),
|
|
1673
|
+
`), process.exit(0)), v;
|
|
1669
1674
|
}
|
|
1670
|
-
switch (
|
|
1675
|
+
switch (u) {
|
|
1671
1676
|
case "init":
|
|
1672
|
-
await
|
|
1677
|
+
await Mt();
|
|
1673
1678
|
break;
|
|
1674
1679
|
case "sync":
|
|
1675
1680
|
console.log(`
|
|
1676
1681
|
Running sync...
|
|
1677
1682
|
`);
|
|
1678
|
-
const { execSync:
|
|
1683
|
+
const { execSync: v } = await import("child_process");
|
|
1679
1684
|
try {
|
|
1680
|
-
|
|
1685
|
+
v("node " + process.argv[1] + " sync", { stdio: "inherit" });
|
|
1681
1686
|
} catch {
|
|
1682
1687
|
}
|
|
1683
1688
|
await B(!0, o);
|
|
@@ -1703,13 +1708,13 @@ Running sync...
|
|
|
1703
1708
|
case "exit":
|
|
1704
1709
|
process.exit(0);
|
|
1705
1710
|
}
|
|
1706
|
-
},
|
|
1707
|
-
const { input: e, select: o } = await import("@inquirer/prompts"), n = await import("fs"),
|
|
1711
|
+
}, Mt = async () => {
|
|
1712
|
+
const { input: e, select: o } = await import("@inquirer/prompts"), n = await import("fs"), f = (await import("path")).default.basename(process.cwd());
|
|
1708
1713
|
let c, m;
|
|
1709
1714
|
try {
|
|
1710
1715
|
c = await e({
|
|
1711
1716
|
message: "Component name:",
|
|
1712
|
-
default:
|
|
1717
|
+
default: f
|
|
1713
1718
|
}), m = await o({
|
|
1714
1719
|
message: "Component type:",
|
|
1715
1720
|
choices: [
|
|
@@ -1719,21 +1724,21 @@ Running sync...
|
|
|
1719
1724
|
{ name: "π
°οΈ Angular", value: "angular", disabled: "(coming soon)" }
|
|
1720
1725
|
]
|
|
1721
1726
|
});
|
|
1722
|
-
} catch (
|
|
1723
|
-
throw
|
|
1727
|
+
} catch (u) {
|
|
1728
|
+
throw u.name === "ExitPromptError" && (console.log(`
|
|
1724
1729
|
|
|
1725
1730
|
π Goodbye!
|
|
1726
|
-
`), process.exit(0)),
|
|
1731
|
+
`), process.exit(0)), u;
|
|
1727
1732
|
}
|
|
1728
|
-
const
|
|
1733
|
+
const w = {
|
|
1729
1734
|
name: c,
|
|
1730
1735
|
type: m,
|
|
1731
1736
|
author: "@myop-cli"
|
|
1732
|
-
},
|
|
1737
|
+
}, I = d.program.getOptionValue("config") || "./myop.config.json";
|
|
1733
1738
|
try {
|
|
1734
|
-
n.writeFileSync(
|
|
1735
|
-
β
Created ${
|
|
1736
|
-
const
|
|
1739
|
+
n.writeFileSync(I, JSON.stringify(w, null, 2)), console.log(`
|
|
1740
|
+
β
Created ${I}`);
|
|
1741
|
+
const u = {
|
|
1737
1742
|
name: c.toLowerCase().replace(/\s+/g, "-"),
|
|
1738
1743
|
version: "1.0.0",
|
|
1739
1744
|
type: "module",
|
|
@@ -1745,7 +1750,7 @@ Running sync...
|
|
|
1745
1750
|
esbuild: "^0.24.0"
|
|
1746
1751
|
}
|
|
1747
1752
|
};
|
|
1748
|
-
n.writeFileSync("package.json", JSON.stringify(
|
|
1753
|
+
n.writeFileSync("package.json", JSON.stringify(u, 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';
|
|
1749
1754
|
import fs from 'fs';
|
|
1750
1755
|
import path from 'path';
|
|
1751
1756
|
|
|
@@ -1825,7 +1830,7 @@ fs.writeFileSync('dist/index.html', html);
|
|
|
1825
1830
|
console.log('β
Built dist/index.html');
|
|
1826
1831
|
console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS files\`);
|
|
1827
1832
|
`), console.log("β
Created build.js");
|
|
1828
|
-
const
|
|
1833
|
+
const S = `<!DOCTYPE html>
|
|
1829
1834
|
<html lang="en">
|
|
1830
1835
|
<head>
|
|
1831
1836
|
<meta charset="UTF-8">
|
|
@@ -1842,7 +1847,7 @@ console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS
|
|
|
1842
1847
|
</body>
|
|
1843
1848
|
</html>
|
|
1844
1849
|
`;
|
|
1845
|
-
n.writeFileSync("index.html",
|
|
1850
|
+
n.writeFileSync("index.html", S), console.log("β
Created index.html");
|
|
1846
1851
|
const j = `// ${c} - Entry Point
|
|
1847
1852
|
import { init } from './modules/app.js';
|
|
1848
1853
|
import { setupMyopInterface } from './modules/myop.js';
|
|
@@ -1853,7 +1858,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
1853
1858
|
});
|
|
1854
1859
|
`;
|
|
1855
1860
|
n.writeFileSync("src/index.js", j), console.log("β
Created src/index.js");
|
|
1856
|
-
const
|
|
1861
|
+
const v = `// ${c} - Main Application Logic
|
|
1857
1862
|
|
|
1858
1863
|
export function init() {
|
|
1859
1864
|
console.log('${c} loaded');
|
|
@@ -1861,7 +1866,7 @@ export function init() {
|
|
|
1861
1866
|
// Your component logic here
|
|
1862
1867
|
}
|
|
1863
1868
|
`;
|
|
1864
|
-
n.writeFileSync("src/modules/app.js",
|
|
1869
|
+
n.writeFileSync("src/modules/app.js", v), console.log("β
Created src/modules/app.js"), n.writeFileSync("src/modules/myop.js", `// Myop Interface - Communication with host app
|
|
1865
1870
|
|
|
1866
1871
|
export function setupMyopInterface() {
|
|
1867
1872
|
// Called when host app sends data to this component
|
|
@@ -1882,7 +1887,7 @@ export function setupMyopInterface() {
|
|
|
1882
1887
|
@import './main.css';
|
|
1883
1888
|
`;
|
|
1884
1889
|
n.writeFileSync("src/styles/index.css", z), console.log("β
Created src/styles/index.css");
|
|
1885
|
-
const
|
|
1890
|
+
const x = `/* ${c} - Main Styles */
|
|
1886
1891
|
|
|
1887
1892
|
* {
|
|
1888
1893
|
box-sizing: border-box;
|
|
@@ -1911,49 +1916,49 @@ p {
|
|
|
1911
1916
|
line-height: 1.5;
|
|
1912
1917
|
}
|
|
1913
1918
|
`;
|
|
1914
|
-
n.writeFileSync("src/styles/main.css",
|
|
1919
|
+
n.writeFileSync("src/styles/main.css", x), console.log("β
Created src/styles/main.css"), console.log(`
|
|
1915
1920
|
π¦ Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
|
|
1916
|
-
`), d.myopConfig =
|
|
1917
|
-
} catch (
|
|
1918
|
-
console.error(`Failed to initialize component: ${
|
|
1921
|
+
`), d.myopConfig = w, await B(!0);
|
|
1922
|
+
} catch (u) {
|
|
1923
|
+
console.error(`Failed to initialize component: ${u.message}`), process.exit(1);
|
|
1919
1924
|
}
|
|
1920
1925
|
};
|
|
1921
1926
|
d.program.command("default", { isDefault: !0 }).action(async () => {
|
|
1922
|
-
if (d.program.getOptionValue("help") && (console.log(
|
|
1923
|
-
const
|
|
1924
|
-
let
|
|
1927
|
+
if (d.program.getOptionValue("help") && (console.log(Qe), process.exit()), d.program.getOptionValue("ci")) {
|
|
1928
|
+
const m = await import("fs"), w = d.program.getOptionValue("config") || "./myop.config.json", I = d.program.version(), u = ye();
|
|
1929
|
+
let y = { found: !1 };
|
|
1925
1930
|
try {
|
|
1926
|
-
if (
|
|
1927
|
-
const
|
|
1928
|
-
|
|
1931
|
+
if (m.existsSync(w)) {
|
|
1932
|
+
const j = m.readFileSync(w, "utf-8"), v = JSON.parse(j);
|
|
1933
|
+
y = {
|
|
1929
1934
|
found: !0,
|
|
1930
|
-
path:
|
|
1931
|
-
name:
|
|
1932
|
-
componentId:
|
|
1933
|
-
organization:
|
|
1935
|
+
path: w,
|
|
1936
|
+
name: v.name || v.componentName || null,
|
|
1937
|
+
componentId: v.componentId || null,
|
|
1938
|
+
organization: v.organization || null
|
|
1934
1939
|
};
|
|
1935
1940
|
}
|
|
1936
|
-
} catch (
|
|
1937
|
-
|
|
1941
|
+
} catch (j) {
|
|
1942
|
+
y = { found: !1, error: j.message };
|
|
1938
1943
|
}
|
|
1939
|
-
const
|
|
1940
|
-
version:
|
|
1941
|
-
config:
|
|
1944
|
+
const S = {
|
|
1945
|
+
version: I,
|
|
1946
|
+
config: y,
|
|
1942
1947
|
auth: {
|
|
1943
|
-
loggedIn: !!(
|
|
1944
|
-
email: (
|
|
1948
|
+
loggedIn: !!(u != null && u.email),
|
|
1949
|
+
email: (u == null ? void 0 : u.email) || null
|
|
1945
1950
|
}
|
|
1946
1951
|
};
|
|
1947
|
-
console.log(JSON.stringify(
|
|
1952
|
+
console.log(JSON.stringify(S, null, 2)), process.exit(0);
|
|
1948
1953
|
}
|
|
1949
1954
|
let n = F({
|
|
1950
1955
|
text: "Loading Myop CLI...",
|
|
1951
1956
|
color: "green"
|
|
1952
1957
|
}).start();
|
|
1953
1958
|
const a = le();
|
|
1954
|
-
await
|
|
1955
|
-
const
|
|
1956
|
-
await
|
|
1959
|
+
await bt(500), n.stop();
|
|
1960
|
+
const f = d.program.version();
|
|
1961
|
+
await St(f) || await B(a.configFound);
|
|
1957
1962
|
});
|
|
1958
1963
|
d.program.parse(process.argv);
|
|
1959
1964
|
d.program.opts();
|