@myop/cli 0.1.12 β†’ 0.1.14

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.
Files changed (2) hide show
  1. package/dist/myop-cli.js +534 -496
  2. package/package.json +2 -1
package/dist/myop-cli.js CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import A from "ora";
3
- import { select as Me, Separator as pe } from "@inquirer/prompts";
4
- import { Command as Be, Option as ie } from "commander";
5
- import { execSync as ne } from "child_process";
2
+ import F from "ora";
3
+ import { select as Oe, Separator as me } from "@inquirer/prompts";
4
+ import { Command as Ve, Option as ae } from "commander";
5
+ import { execSync as se } from "child_process";
6
6
  import Z from "path";
7
- import E from "fs";
8
- import ue from "crypto";
7
+ import A from "fs";
8
+ import fe from "crypto";
9
9
  import We from "http";
10
- import { URL as Oe, URLSearchParams as je } from "url";
11
- import Ye from "open";
12
- import Ge from "os";
13
- const Ve = `
10
+ import { URL as Ie, URLSearchParams as je } from "url";
11
+ import Ge from "open";
12
+ import Ye from "os";
13
+ const Ke = `
14
14
  Usage: myop [OPTIONS] COMMAND [ARGS]...
15
15
 
16
16
  A powerful command-line interface for managing your Myop projects.
@@ -44,7 +44,7 @@ Examples:
44
44
 
45
45
 
46
46
 
47
- `, l = {
47
+ `, d = {
48
48
  program: null,
49
49
  executionPath: "",
50
50
  options: {
@@ -52,81 +52,81 @@ Examples:
52
52
  verbose: !1
53
53
  },
54
54
  myopConfig: null
55
- }, Ie = {
55
+ }, ke = {
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.",
59
59
  action: async () => {
60
60
  console.info("installing... ");
61
- for (const e of l.myopConfig.flows) {
62
- const o = Z.join(l.executionPath, "/node_modules/@myop/flow-types/");
61
+ for (const e of d.myopConfig.flows) {
62
+ const o = Z.join(d.executionPath, "/node_modules/@myop/flow-types/");
63
63
  console.info(`Generate flow at ${o}`), console.info(`Generated flow at ${o}`);
64
64
  }
65
65
  process.exit();
66
66
  }
67
- }, Ke = (e) => {
68
- const o = Z.join(l.executionPath, e);
67
+ }, Xe = (e) => {
68
+ const o = Z.join(d.executionPath, e);
69
69
  console.info(`reading config file from: ${o}`);
70
- const n = E.readFileSync(o, "utf8"), a = JSON.parse(n);
70
+ const n = A.readFileSync(o, "utf8"), a = JSON.parse(n);
71
71
  return console.info("config file loaded, ", a), a;
72
- }, fe = (e, o) => {
73
- const n = Z.join(l.executionPath, e);
72
+ }, ge = (e, o) => {
73
+ const n = Z.join(d.executionPath, e);
74
74
  console.info(`writing config file to: ${n}`);
75
75
  try {
76
76
  const a = JSON.stringify(o, null, 2);
77
- E.writeFileSync(n, a), console.info(`config file updated ${a}`);
77
+ A.writeFileSync(n, a), console.info(`config file updated ${a}`);
78
78
  } catch (a) {
79
79
  throw console.info(`error ${a} while writing to ${n}, JSON: ${o}`), console.log(`
80
80
  ⚠️ Failed write config file to ${n}, for more info use verbose flag`), a;
81
81
  }
82
- }, ke = {
82
+ }, Pe = {
83
83
  name: "🌟 Add flow definition to your project",
84
84
  value: "addFlow",
85
85
  description: "Adds flow to yours myop.config.json",
86
86
  _action: (e) => {
87
- l.myopConfig.flows.includes(e) || l.myopConfig.flows.push(e), fe(l.options.configPath, l.myopConfig);
87
+ d.myopConfig.flows.includes(e) || d.myopConfig.flows.push(e), ge(d.options.configPath, d.myopConfig);
88
88
  },
89
89
  action: async () => {
90
90
  }
91
- }, Pe = {
91
+ }, _e = {
92
92
  name: "🚫 Remove flow definition from your project",
93
93
  value: "removeFlow",
94
94
  description: "Removes flow to yours myop.config.json",
95
95
  _action: (e) => {
96
- l.myopConfig.flows = l.myopConfig.flows.filter((o) => o !== e), fe(l.options.configPath, l.myopConfig);
96
+ d.myopConfig.flows = d.myopConfig.flows.filter((o) => o !== e), ge(d.options.configPath, d.myopConfig);
97
97
  },
98
98
  action: () => {
99
99
  }
100
- }, Xe = {
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
- }, Qe = {
107
+ }, Ze = {
108
108
  name: "🟒 Create new component",
109
109
  value: "-",
110
110
  disabled: "(not available yet)"
111
- }, Ze = {
111
+ }, qe = {
112
112
  name: "πŸ”΅ Create new experience",
113
113
  value: "-",
114
114
  disabled: "(not available yet)"
115
- }, qe = {
115
+ }, et = {
116
116
  name: "🟑 Create new skin",
117
117
  value: "-",
118
118
  disabled: "(not available yet)"
119
- }, et = {
119
+ }, tt = {
120
120
  name: "πŸ”΄ Create new flow",
121
121
  value: "-",
122
122
  disabled: "(not available yet)"
123
- }, tt = {
123
+ }, ot = {
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
- }, ot = [tt, Qe, Ze, qe, et];
129
- function nt(e, o, n, a) {
128
+ }, nt = [ot, Ze, qe, et, tt];
129
+ function st(e, o, n, a) {
130
130
  return `<!DOCTYPE html>
131
131
  <html lang="en">
132
132
  <head>
@@ -216,25 +216,61 @@ ${a}
216
216
  </body>
217
217
  </html>`;
218
218
  }
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");
219
+ async function Ne() {
220
+ const e = await import("fs"), o = await import("path"), { exec: n } = await import("child_process"), a = await import("http"), { createHash: u } = 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"), S = e.default.readFileSync(o.default.join(p, "app.js"), "utf-8"), f = 9292, w = 9293, y = "./dist";
227
+ const m = o.default.join(c, "commands", "dev", "management-website"), S = e.default.readFileSync(o.default.join(m, "styles.css"), "utf-8"), x = e.default.readFileSync(o.default.join(m, "app.js"), "utf-8"), g = 9292, y = 9293, w = "./dist";
228
228
  let j = !1, $ = !1;
229
- const _ = /* @__PURE__ */ new Map(), z = l.program.getOptionValue("config") || "./myop.config.json";
230
- let x, P, g = !1;
229
+ const T = /* @__PURE__ */ new Map(), z = d.program.getOptionValue("config") || "./myop.config.json";
230
+ let v, _, h = !1;
231
231
  try {
232
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");
233
+ v = t.componentId || "DEV", _ = 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 b = process.cwd(), H = (s) => {
237
+ const M = async () => {
238
+ if (v !== "DEV" && v !== "NEW")
239
+ return v;
240
+ try {
241
+ const t = ((await new Promise((l, p) => {
242
+ const f = {
243
+ hostname: "localhost",
244
+ port: y,
245
+ path: "/_list",
246
+ method: "GET",
247
+ timeout: 1e3
248
+ }, O = a.default.request(f, (k) => {
249
+ let H = "";
250
+ k.on("data", (J) => H += J), k.on("end", () => {
251
+ try {
252
+ l(JSON.parse(H));
253
+ } catch {
254
+ l({ components: [] });
255
+ }
256
+ });
257
+ });
258
+ O.on("error", () => l({ components: [] })), O.on("timeout", () => {
259
+ O.destroy(), l({ components: [] });
260
+ }), O.end();
261
+ })).components || []).map(([l]) => l).filter((l) => l === "DEV" || l === "NEW" || /^DEV\d+$/.test(l) || /^NEW\d+$/.test(l));
262
+ if (t.length === 0)
263
+ return "DEV1";
264
+ const r = t.map((l) => {
265
+ if (l === "DEV" || l === "NEW") return 1;
266
+ const p = l.match(/^DEV(\d+)$/), f = l.match(/^NEW(\d+)$/);
267
+ return p ? parseInt(p[1], 10) : f ? parseInt(f[1], 10) : 0;
268
+ }).filter((l) => l > 0);
269
+ return `DEV${Math.max(...r, 0) + 1}`;
270
+ } catch {
271
+ return "DEV1";
272
+ }
273
+ }, N = process.cwd(), K = (s) => {
238
274
  const t = o.default.extname(s).toLowerCase();
239
275
  return {
240
276
  ".html": "text/html",
@@ -247,43 +283,43 @@ async function _e() {
247
283
  ".svg": "image/svg+xml",
248
284
  ".ico": "image/x-icon"
249
285
  }[t] || "application/octet-stream";
250
- }, M = /* @__PURE__ */ new Map(), F = [], Ne = 50, J = [], B = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map(), Ae = (s, t, r) => {
286
+ }, b = /* @__PURE__ */ new Map(), q = [], Fe = 50, D = [], V = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Map(), Ae = (s, t, r) => {
251
287
  if (s.url.startsWith("/_hmr/")) {
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");
288
+ const i = s.url.split("/_hmr/")[1], l = s.headers["sec-websocket-key"], p = u("sha1").update(l + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
253
289
  t.write(
254
290
  `HTTP/1.1 101 Switching Protocols\r
255
291
  Upgrade: websocket\r
256
292
  Connection: Upgrade\r
257
- Sec-WebSocket-Accept: ${d}\r
293
+ Sec-WebSocket-Accept: ${p}\r
258
294
  \r
259
295
  `
260
- ), D.has(i) || D.set(i, /* @__PURE__ */ new Set()), D.get(i).add(t), console.log(`πŸ”Œ HMR client connected: ${i}`), t.on("close", () => {
261
- const h = D.get(i);
262
- h && (h.delete(t), h.size === 0 && D.delete(i)), console.log(`πŸ”Œ HMR client disconnected: ${i}`);
296
+ ), U.has(i) || U.set(i, /* @__PURE__ */ new Set()), U.get(i).add(t), console.log(`πŸ”Œ HMR client connected: ${i}`), t.on("close", () => {
297
+ const f = U.get(i);
298
+ f && (f.delete(t), f.size === 0 && U.delete(i)), console.log(`πŸ”Œ HMR client disconnected: ${i}`);
263
299
  }), t.on("error", () => {
264
- const h = D.get(i);
265
- h && h.delete(t);
300
+ const f = U.get(i);
301
+ f && f.delete(t);
266
302
  });
267
303
  }
268
- }, ce = a.default.createServer((s, t) => {
304
+ }, le = a.default.createServer((s, t) => {
269
305
  if (t.setHeader("Content-Type", "application/json"), s.method === "POST" && s.url === "/_register") {
270
306
  let r = "";
271
307
  s.on("data", (i) => r += i), s.on("end", () => {
272
308
  try {
273
- const { componentId: i, distPath: u, componentName: d } = JSON.parse(r);
274
- M.set(i, { path: u, name: d || null });
275
- const h = d ? ` (${d})` : "";
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
- id: T,
279
- path: V.path,
280
- name: V.name
309
+ const { componentId: i, distPath: l, componentName: p } = JSON.parse(r);
310
+ b.set(i, { path: l, name: p || null });
311
+ const f = p ? ` (${p})` : "";
312
+ console.log(`βœ… Registered: ${i}${f} -> ${l}`), t.writeHead(200), t.end(JSON.stringify({ success: !0, registered: Array.from(b.keys()) }));
313
+ const O = Array.from(b.entries()).map(([k, H]) => ({
314
+ id: k,
315
+ path: H.path,
316
+ name: H.name
281
317
  }));
282
- J.forEach((T) => {
318
+ D.forEach((k) => {
283
319
  try {
284
- T.write(`data: ${JSON.stringify({
320
+ k.write(`data: ${JSON.stringify({
285
321
  type: "components",
286
- components: I
322
+ components: O
287
323
  })}
288
324
 
289
325
  `);
@@ -299,17 +335,17 @@ Sec-WebSocket-Accept: ${d}\r
299
335
  s.on("data", (i) => r += i), s.on("end", () => {
300
336
  try {
301
337
  const { componentId: i } = JSON.parse(r);
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
- id: d,
305
- path: h.path,
306
- name: h.name
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, f]) => ({
340
+ id: p,
341
+ path: f.path,
342
+ name: f.name
307
343
  }));
308
- J.forEach((d) => {
344
+ D.forEach((p) => {
309
345
  try {
310
- d.write(`data: ${JSON.stringify({
346
+ p.write(`data: ${JSON.stringify({
311
347
  type: "components",
312
- components: u
348
+ components: l
313
349
  })}
314
350
 
315
351
  `);
@@ -320,79 +356,79 @@ Sec-WebSocket-Accept: ${d}\r
320
356
  t.writeHead(400), t.end(JSON.stringify({ error: i.message }));
321
357
  }
322
358
  });
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
- }), q = a.default.createServer((s, t) => {
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
+ }), ee = a.default.createServer((s, t) => {
325
361
  if (s.url.includes("..")) {
326
362
  t.writeHead(403, { "Content-Type": "text/plain" }), t.end("Forbidden");
327
363
  return;
328
364
  }
329
- const r = new URL(s.url, `http://localhost:${f}`), i = r.pathname, u = i.split("/").filter((k) => k);
365
+ const r = new URL(s.url, `http://localhost:${g}`), i = r.pathname, l = i.split("/").filter((P) => P);
330
366
  if (i.startsWith("/consume")) {
331
- const k = r.searchParams.get("id");
332
- if (!k) {
367
+ const P = r.searchParams.get("id");
368
+ if (!P) {
333
369
  t.writeHead(400, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Component ID required. Use /consume?id=<componentId>" }));
334
370
  return;
335
371
  }
336
- const N = M.get(k), L = N ? N.path : null, $e = (W) => {
337
- let C = "Unknown", R = "Unknown";
372
+ const R = b.get(P), L = R ? R.path : null, Me = (W) => {
373
+ let C = "Unknown", E = "Unknown";
338
374
  if (s.headers.referer || s.headers.referrer) {
339
- const O = s.headers.referer || s.headers.referrer;
375
+ const I = s.headers.referer || s.headers.referrer;
340
376
  try {
341
- const Y = new URL(O);
342
- C = Y.origin, R = Y.hostname || Y.origin;
377
+ const G = new URL(I);
378
+ C = G.origin, E = G.hostname || G.origin;
343
379
  } catch {
344
- C = O, R = O;
380
+ C = I, E = I;
345
381
  }
346
382
  } else if (s.headers.origin)
347
383
  try {
348
- const O = new URL(s.headers.origin);
349
- C = O.origin, R = O.hostname || O.origin;
384
+ const I = new URL(s.headers.origin);
385
+ C = I.origin, E = I.hostname || I.origin;
350
386
  } catch {
351
- C = s.headers.origin, R = s.headers.origin;
387
+ C = s.headers.origin, E = s.headers.origin;
352
388
  }
353
389
  else if (s.socket.remoteAddress) {
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:", ""));
390
+ const I = s.socket.remoteAddress;
391
+ I === "::1" || I === "::ffff:127.0.0.1" ? (C = "localhost", E = "localhost (direct)") : (C = I, E = I.replace("::ffff:", ""));
356
392
  }
357
- const de = s.headers.referer || s.headers.referrer || C, te = {
393
+ const pe = s.headers.referer || s.headers.referrer || C, oe = {
358
394
  type: "request",
359
- componentId: k,
395
+ componentId: P,
360
396
  timestamp: Date.now(),
361
397
  servedLocally: W,
362
- referrer: de,
398
+ referrer: pe,
363
399
  origin: C,
364
- originLabel: R
400
+ originLabel: E
365
401
  };
366
- B.has(C) || (B.set(C, {
402
+ V.has(C) || (V.set(C, {
367
403
  url: C,
368
- label: R,
404
+ label: E,
369
405
  firstSeen: Date.now(),
370
406
  requestCount: 0
371
- }), J.forEach((O) => {
407
+ }), D.forEach((I) => {
372
408
  try {
373
- O.write(`data: ${JSON.stringify({
409
+ I.write(`data: ${JSON.stringify({
374
410
  type: "origins",
375
- origins: Array.from(B.values())
411
+ origins: Array.from(V.values())
376
412
  })}
377
413
 
378
414
  `);
379
415
  } catch {
380
416
  }
381
417
  }));
382
- const ze = B.get(C);
383
- ze.requestCount++, J.forEach((O) => {
418
+ const ze = V.get(C);
419
+ ze.requestCount++, D.forEach((I) => {
384
420
  try {
385
- O.write(`data: ${JSON.stringify({
421
+ I.write(`data: ${JSON.stringify({
386
422
  type: "origins",
387
- origins: Array.from(B.values())
423
+ origins: Array.from(V.values())
388
424
  })}
389
425
 
390
426
  `);
391
427
  } catch {
392
428
  }
393
- }), F.push(te), F.length > Ne && F.shift(), J.forEach((O) => {
429
+ }), q.push(oe), q.length > Fe && q.shift(), D.forEach((I) => {
394
430
  try {
395
- O.write(`data: ${JSON.stringify(te)}
431
+ I.write(`data: ${JSON.stringify(oe)}
396
432
 
397
433
  `);
398
434
  } catch {
@@ -401,37 +437,37 @@ Sec-WebSocket-Accept: ${d}\r
401
437
  };
402
438
  if (L) {
403
439
  const W = o.default.join(L, "index.html");
404
- e.default.readFile(W, "utf-8", (C, R) => {
440
+ e.default.readFile(W, "utf-8", (C, E) => {
405
441
  if (C) {
406
442
  console.log(`❌ File not found: ${W}`), t.writeHead(404, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "index.html not found" }));
407
443
  return;
408
444
  }
409
- const de = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, te = {
445
+ const pe = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, oe = {
410
446
  item: {
411
- name: k,
412
- id: k,
447
+ name: P,
448
+ id: P,
413
449
  consume_variant: [
414
450
  {
415
- id: de,
451
+ id: pe,
416
452
  name: "dev version",
417
453
  loader: {
418
454
  type: "HTMLLoader",
419
455
  shadowRootMode: "localFrame",
420
- HTML: R
456
+ HTML: E
421
457
  }
422
458
  }
423
459
  ]
424
460
  }
425
461
  };
426
- console.log(`βœ… Serving consume JSON for: ${k}`), $e(!0), t.writeHead(200, {
462
+ console.log(`βœ… Serving consume JSON for: ${P}`), Me(!0), t.writeHead(200, {
427
463
  "Content-Type": "application/json",
428
464
  "Access-Control-Allow-Origin": "*"
429
- }), t.end(JSON.stringify(te, null, 2));
465
+ }), t.end(JSON.stringify(oe, null, 2));
430
466
  });
431
467
  } else {
432
- console.log(`πŸ“‘ Proxying consume request to cloud.myop.dev for: ${k}`);
468
+ console.log(`πŸ“‘ Proxying consume request to cloud.myop.dev for: ${P}`);
433
469
  const W = `https://cloud.myop.dev/consume${r.search}`;
434
- $e(!1), fetch(W).then((C) => C.text()).then((C) => {
470
+ Me(!1), fetch(W).then((C) => C.text()).then((C) => {
435
471
  t.writeHead(200, {
436
472
  "Content-Type": "application/json",
437
473
  "Access-Control-Allow-Origin": "*"
@@ -448,112 +484,112 @@ Sec-WebSocket-Accept: ${d}\r
448
484
  "Cache-Control": "no-cache",
449
485
  Connection: "keep-alive",
450
486
  "Access-Control-Allow-Origin": "*"
451
- }), J.push(t);
452
- const k = Array.from(M.entries()).map(([N, L]) => ({
453
- id: N,
487
+ }), D.push(t);
488
+ const P = Array.from(b.entries()).map(([R, L]) => ({
489
+ id: R,
454
490
  path: L.path,
455
491
  name: L.name
456
492
  }));
457
493
  t.write(`data: ${JSON.stringify({
458
494
  type: "components",
459
- components: k
495
+ components: P
460
496
  })}
461
497
 
462
498
  `), t.write(`data: ${JSON.stringify({
463
499
  type: "origins",
464
- origins: Array.from(B.values())
500
+ origins: Array.from(V.values())
465
501
  })}
466
502
 
467
503
  `), t.write(`data: ${JSON.stringify({
468
504
  type: "requestLog",
469
- log: F
505
+ log: q
470
506
  })}
471
507
 
472
508
  `), s.on("close", () => {
473
- const N = J.indexOf(t);
474
- N !== -1 && J.splice(N, 1);
509
+ const R = D.indexOf(t);
510
+ R !== -1 && D.splice(R, 1);
475
511
  });
476
512
  return;
477
513
  }
478
- if (u.length === 0) {
479
- t.writeHead(200, { "Content-Type": "text/html" }), t.end(nt(f, w, v, S));
514
+ if (l.length === 0) {
515
+ t.writeHead(200, { "Content-Type": "text/html" }), t.end(st(g, y, S, x));
480
516
  return;
481
517
  }
482
- if (u[0] !== "view") {
518
+ if (l[0] !== "view") {
483
519
  t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Not found. Use /view/<componentId>/ to access components.");
484
520
  return;
485
521
  }
486
- if (u.length < 2) {
522
+ if (l.length < 2) {
487
523
  t.writeHead(400, { "Content-Type": "text/plain" }), t.end("Component ID required. Use /view/<componentId>/");
488
524
  return;
489
525
  }
490
- const d = u[1], h = M.get(d);
491
- if (!h) {
492
- t.writeHead(404, { "Content-Type": "text/plain" }), t.end(`Component not found: ${d}`);
526
+ const p = l[1], f = b.get(p);
527
+ if (!f) {
528
+ t.writeHead(404, { "Content-Type": "text/plain" }), t.end(`Component not found: ${p}`);
493
529
  return;
494
530
  }
495
- const I = h.path, T = u.slice(2), V = T.length === 0 ? "index.html" : T.join("/"), K = o.default.join(I, V);
496
- console.log(`πŸ“₯ Request: ${s.url} -> ${K}`), e.default.readFile(K, (k, N) => {
497
- if (k) {
498
- console.log(`❌ File not found: ${K}`), t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Not Found");
531
+ const O = f.path, k = l.slice(2), H = k.length === 0 ? "index.html" : k.join("/"), J = o.default.join(O, H);
532
+ console.log(`πŸ“₯ Request: ${s.url} -> ${J}`), e.default.readFile(J, (P, R) => {
533
+ if (P) {
534
+ console.log(`❌ File not found: ${J}`), t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Not Found");
499
535
  return;
500
536
  }
501
- const L = H(K);
502
- console.log(`βœ… Serving: ${K} (${L})`), t.writeHead(200, {
537
+ const L = K(J);
538
+ console.log(`βœ… Serving: ${J} (${L})`), t.writeHead(200, {
503
539
  "Content-Type": L,
504
540
  "Access-Control-Allow-Origin": "*"
505
- }), t.end(N);
541
+ }), t.end(R);
506
542
  });
507
- }), we = () => new Promise((s, t) => {
543
+ }), ve = () => new Promise((s, t) => {
508
544
  const r = JSON.stringify({
509
- componentId: x,
510
- distPath: o.default.resolve(b, y),
511
- componentName: P
545
+ componentId: v,
546
+ distPath: o.default.resolve(N, w),
547
+ componentName: _
512
548
  }), i = {
513
549
  hostname: "localhost",
514
- port: w,
550
+ port: y,
515
551
  path: "/_register",
516
552
  method: "POST",
517
553
  headers: {
518
554
  "Content-Type": "application/json",
519
555
  "Content-Length": Buffer.byteLength(r)
520
556
  }
521
- }, u = a.default.request(i, (d) => {
522
- let h = "";
523
- d.on("data", (I) => h += I), d.on("end", () => {
524
- d.statusCode === 200 ? s(JSON.parse(h)) : t(new Error(`Registration failed: ${d.statusCode}`));
557
+ }, l = a.default.request(i, (p) => {
558
+ let f = "";
559
+ p.on("data", (O) => f += O), p.on("end", () => {
560
+ p.statusCode === 200 ? s(JSON.parse(f)) : t(new Error(`Registration failed: ${p.statusCode}`));
525
561
  });
526
562
  });
527
- u.on("error", t), u.write(r), u.end();
528
- }), Ee = () => new Promise((s, t) => {
529
- const r = JSON.stringify({ componentId: x }), i = {
563
+ l.on("error", t), l.write(r), l.end();
564
+ }), De = () => new Promise((s, t) => {
565
+ const r = JSON.stringify({ componentId: v }), i = {
530
566
  hostname: "localhost",
531
- port: w,
567
+ port: y,
532
568
  path: "/_unregister",
533
569
  method: "POST",
534
570
  headers: {
535
571
  "Content-Type": "application/json",
536
572
  "Content-Length": Buffer.byteLength(r)
537
573
  }
538
- }, u = a.default.request(i, (d) => {
574
+ }, l = a.default.request(i, (p) => {
539
575
  s();
540
576
  });
541
- u.on("error", () => s()), u.write(r), u.end();
577
+ l.on("error", () => s()), l.write(r), l.end();
542
578
  }), He = () => {
543
- if (!g) return;
544
- const s = o.default.join(y, "index.html");
579
+ if (!h) return;
580
+ const s = o.default.join(w, "index.html");
545
581
  try {
546
582
  let t = e.default.readFileSync(s, "utf-8");
547
583
  if (t.includes("<!-- MYOP HMR -->")) {
548
- const i = t.indexOf("<!-- MYOP HMR -->"), u = t.indexOf("<\/script>", i) + 9;
549
- t = t.slice(0, i) + t.slice(u);
584
+ const i = t.indexOf("<!-- MYOP HMR -->"), l = t.indexOf("<\/script>", i) + 9;
585
+ t = t.slice(0, i) + t.slice(l);
550
586
  }
551
587
  const r = `
552
588
  <!-- MYOP HMR -->
553
589
  <script>
554
590
  (function() {
555
- const componentId = '${x}';
556
- const wsUrl = 'ws://localhost:${w}/_hmr/' + componentId;
591
+ const componentId = '${v}';
592
+ const wsUrl = 'ws://localhost:${y}/_hmr/' + componentId;
557
593
  let ws;
558
594
  let reconnectAttempts = 0;
559
595
  const maxReconnectAttempts = 10;
@@ -679,78 +715,78 @@ Sec-WebSocket-Accept: ${d}\r
679
715
  t
680
716
  ]), i;
681
717
  }, Le = () => {
682
- if (!g) return;
683
- const s = D.get(x);
718
+ if (!h) return;
719
+ const s = U.get(v);
684
720
  if (!s || s.size === 0)
685
721
  return;
686
722
  console.log(`πŸ”₯ Notifying ${s.size} HMR client(s)`);
687
- const t = o.default.join(y, "index.html");
723
+ const t = o.default.join(w, "index.html");
688
724
  try {
689
725
  let r = e.default.readFileSync(t, "utf-8");
690
726
  if (r.includes("<!-- MYOP HMR -->")) {
691
- const d = r.indexOf("<!-- MYOP HMR -->"), h = r.indexOf("<\/script>", d) + 9;
692
- r = r.slice(0, d) + r.slice(h);
727
+ const p = r.indexOf("<!-- MYOP HMR -->"), f = r.indexOf("<\/script>", p) + 9;
728
+ r = r.slice(0, p) + r.slice(f);
693
729
  }
694
730
  const i = JSON.stringify({
695
731
  type: "update",
696
732
  html: r
697
- }), u = Je(i);
698
- s.forEach((d) => {
733
+ }), l = Je(i);
734
+ s.forEach((p) => {
699
735
  try {
700
- d.write(u);
736
+ p.write(l);
701
737
  } catch {
702
- s.delete(d);
738
+ s.delete(p);
703
739
  }
704
740
  });
705
741
  } catch (r) {
706
742
  console.error("❌ Failed to read HTML for HMR:", r.message);
707
743
  }
708
- }, le = () => {
744
+ }, de = () => {
709
745
  if (j) {
710
746
  $ = !0;
711
747
  return;
712
748
  }
713
749
  j = !0, console.log(`
714
750
  πŸ”¨ Building...`), n("npm run build", (s, t, r) => {
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());
751
+ j = !1, s ? (console.error("❌ Build failed:", s.message), r && console.error(r)) : (console.log("βœ… Build completed"), t && console.log(t), He(), Le()), $ && ($ = !1, de());
716
752
  });
717
- }, ve = /* @__PURE__ */ new Set(), Se = (s) => {
753
+ }, Se = /* @__PURE__ */ new Set(), xe = (s) => {
718
754
  e.default.readdir(s, { withFileTypes: !0 }, (t, r) => {
719
755
  t || (r.forEach((i) => {
720
- const u = o.default.join(s, i.name);
756
+ const l = o.default.join(s, i.name);
721
757
  if (i.isDirectory())
722
- i.name !== "node_modules" && i.name !== "dist" && !i.name.startsWith(".") && Se(u);
758
+ i.name !== "node_modules" && i.name !== "dist" && !i.name.startsWith(".") && xe(l);
723
759
  else if (i.isFile()) {
724
- const d = o.default.extname(i.name);
725
- if (d === ".js" || d === ".css" || d === ".html")
760
+ const p = o.default.extname(i.name);
761
+ if (p === ".js" || p === ".css" || p === ".html")
726
762
  try {
727
- const h = e.default.readFileSync(u, "utf-8");
728
- _.set(u, h);
763
+ const f = e.default.readFileSync(l, "utf-8");
764
+ T.set(l, f);
729
765
  } catch {
730
766
  }
731
767
  }
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
- if (d !== ".js" && d !== ".css" && d !== ".html") return;
736
- const h = o.default.join(s, u);
768
+ }), Se.has(s) || (Se.add(s), e.default.watch(s, (i, l) => {
769
+ if (!l) return;
770
+ const p = o.default.extname(l);
771
+ if (p !== ".js" && p !== ".css" && p !== ".html") return;
772
+ const f = o.default.join(s, l);
737
773
  setTimeout(() => {
738
774
  try {
739
- const I = e.default.readFileSync(h, "utf-8"), T = _.get(h);
740
- I !== T && (_.set(h, I), console.log(`πŸ“ File changed: ${h}`), le());
775
+ const O = e.default.readFileSync(f, "utf-8"), k = T.get(f);
776
+ O !== k && (T.set(f, O), console.log(`πŸ“ File changed: ${f}`), de());
741
777
  } catch {
742
778
  }
743
779
  }, 50);
744
780
  })));
745
781
  });
746
- }, xe = () => {
782
+ }, be = () => {
747
783
  console.log(`
748
- πŸ”¨ Component: ${x}`), le(), Se(b), console.log("πŸ‘€ Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
784
+ πŸ”¨ Component: ${v}`), de(), xe(N), console.log("πŸ‘€ Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
749
785
  `);
750
- }, De = () => new Promise((s) => {
786
+ }, Ue = () => new Promise((s) => {
751
787
  const t = {
752
788
  hostname: "localhost",
753
- port: w,
789
+ port: y,
754
790
  path: "/_list",
755
791
  method: "GET",
756
792
  timeout: 1e3
@@ -760,150 +796,151 @@ Sec-WebSocket-Accept: ${d}\r
760
796
  r.on("error", () => s(!1)), r.on("timeout", () => {
761
797
  r.destroy(), s(!1);
762
798
  }), r.end();
763
- }), Ue = () => new Promise((s) => {
799
+ }), Be = () => new Promise((s) => {
764
800
  const t = a.default.createServer((r, i) => {
765
801
  if (i.setHeader("Content-Type", "application/json"), r.method === "POST" && r.url === "/_register") {
766
- let u = "";
767
- r.on("data", (d) => u += d), r.on("end", () => {
802
+ let l = "";
803
+ r.on("data", (p) => l += p), r.on("end", () => {
768
804
  try {
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
- } catch (d) {
774
- i.writeHead(400), i.end(JSON.stringify({ error: d.message }));
805
+ const { componentId: p, distPath: f, componentName: O } = JSON.parse(l);
806
+ b.set(p, { path: f, name: O || null });
807
+ const k = O ? ` (${O})` : "";
808
+ console.log(`βœ… Registered: ${p}${k} -> ${f}`), i.writeHead(200), i.end(JSON.stringify({ success: !0, registered: Array.from(b.keys()) }));
809
+ } catch (p) {
810
+ i.writeHead(400), i.end(JSON.stringify({ error: p.message }));
775
811
  }
776
812
  });
777
813
  } else if (r.method === "POST" && r.url === "/_unregister") {
778
- let u = "";
779
- r.on("data", (d) => u += d), r.on("end", () => {
814
+ let l = "";
815
+ r.on("data", (p) => l += p), r.on("end", () => {
780
816
  try {
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
- } catch (d) {
784
- i.writeHead(400), i.end(JSON.stringify({ error: d.message }));
817
+ const { componentId: p } = JSON.parse(l);
818
+ b.delete(p), console.log(`❌ Unregistered: ${p}`), i.writeHead(200), i.end(JSON.stringify({ success: !0 }));
819
+ } catch (p) {
820
+ i.writeHead(400), i.end(JSON.stringify({ error: p.message }));
785
821
  }
786
822
  });
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" })));
823
+ } 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" })));
788
824
  });
789
825
  t.on("error", () => {
790
826
  s(!1);
791
- }), t.listen(w, () => {
827
+ }), t.listen(y, () => {
792
828
  console.log(`
793
- πŸ”„ Taking over as server...`), console.log(`πŸ“‘ Management server on port ${w}`), q.on("error", () => {
829
+ πŸ”„ Taking over as server...`), console.log(`πŸ“‘ Management server on port ${y}`), ee.on("error", () => {
794
830
  t.close(), s(!1);
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
- name: P
831
+ }), ee.listen(g, () => {
832
+ console.log(`πŸ“‘ Main server running at http://localhost:${g}`), b.set(v, {
833
+ path: o.default.resolve(N, w),
834
+ name: _
799
835
  });
800
- const r = P ? ` (${P})` : "";
801
- console.log(`βœ… Registered component: ${x}${r}`), console.log(`πŸ“‘ Access at: http://localhost:${f}/view/${x}/`), s(!0);
836
+ const r = _ ? ` (${_})` : "";
837
+ console.log(`βœ… Registered component: ${v}${r}`), console.log(`πŸ“‘ Access at: http://localhost:${g}/view/${v}/`), s(!0);
802
838
  });
803
839
  });
804
840
  });
805
- let ee;
806
- const be = () => {
807
- ee = setInterval(async () => {
808
- await De() || (clearInterval(ee), console.log(`
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 () => {
841
+ let te;
842
+ const Ce = () => {
843
+ te = setInterval(async () => {
844
+ await Ue() || (clearInterval(te), console.log(`
845
+ ⚠️ Server appears to be down, attempting to take over...`), await Be() ? console.log("βœ… Successfully took over as server") : (console.log("ℹ️ Another instance took over, re-registering..."), setTimeout(async () => {
810
846
  try {
811
- await we(), console.log(`βœ… Re-registered component: ${x}`), be();
847
+ await ve(), console.log(`βœ… Re-registered component: ${v}`), Ce();
812
848
  } catch (r) {
813
849
  console.error("❌ Failed to re-register:", r.message);
814
850
  }
815
851
  }, 2e3)));
816
852
  }, 3e3);
817
- }, Ce = async () => {
853
+ }, $e = async () => {
818
854
  console.log(`
819
855
 
820
- πŸ›‘ Shutting down...`), ee && clearInterval(ee), await Ee(), process.exit(0);
856
+ πŸ›‘ Shutting down...`), te && clearInterval(te), await De(), process.exit(0);
821
857
  };
822
- process.on("SIGINT", Ce), process.on("SIGTERM", Ce), ce.on("error", async (s) => {
858
+ process.on("SIGINT", $e), process.on("SIGTERM", $e), le.on("error", async (s) => {
823
859
  if (s.code === "EADDRINUSE") {
824
860
  console.log(`
825
861
  πŸ”— Connecting to existing dev server...`);
826
862
  try {
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();
863
+ v = await M();
864
+ const t = await ve();
865
+ console.log(`βœ… Registered component: ${v}`), console.log(`πŸ“‘ Access at: http://localhost:${g}/view/${v}/`), console.log(`πŸ“‹ All registered components: ${t.registered.join(", ")}`), be(), Ce();
829
866
  } catch (t) {
830
867
  console.error("❌ Failed to register component:", t.message), process.exit(1);
831
868
  }
832
869
  } else
833
870
  console.error("❌ Management server error:", s.message), process.exit(1);
834
- }), ce.on("upgrade", Ae), ce.listen(w, async () => {
871
+ }), le.on("upgrade", Ae), le.listen(y, async () => {
835
872
  console.log(`
836
- πŸš€ Starting shared dev server...`), console.log(`πŸ“‘ Management server on port ${w}`), q.on("error", (s) => {
873
+ πŸš€ Starting shared dev server...`), console.log(`πŸ“‘ Management server on port ${y}`), ee.on("error", (s) => {
837
874
  console.error("❌ Main server error:", s.message), process.exit(1);
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
- name: P
875
+ }), ee.listen(g, async () => {
876
+ console.log(`πŸ“‘ Main server running at http://localhost:${g}`), (v === "DEV" || v === "NEW") && (v = "DEV1"), b.set(v, {
877
+ path: o.default.resolve(N, w),
878
+ name: _
842
879
  });
843
- const s = P ? ` (${P})` : "";
844
- console.log(`βœ… Registered component: ${x}${s}`), console.log(`πŸ“‘ Access at: http://localhost:${f}/view/${x}/`), xe();
880
+ const s = _ ? ` (${_})` : "";
881
+ console.log(`βœ… Registered component: ${v}${s}`), console.log(`πŸ“‘ Access at: http://localhost:${g}/view/${v}/`), be();
845
882
  });
846
883
  });
847
884
  }
848
- const me = Z.join(Ge.homedir(), ".myop"), Q = Z.join(me, "credentials.json");
849
- function st() {
850
- E.existsSync(me) || E.mkdirSync(me, { recursive: !0, mode: 448 });
885
+ const ue = Z.join(Ye.homedir(), ".myop"), Q = Z.join(ue, "credentials.json");
886
+ function rt() {
887
+ A.existsSync(ue) || A.mkdirSync(ue, { recursive: !0, mode: 448 });
851
888
  }
852
- function ge() {
889
+ function he() {
853
890
  try {
854
- if (!E.existsSync(Q))
891
+ if (!A.existsSync(Q))
855
892
  return null;
856
- const e = E.readFileSync(Q, "utf8");
893
+ const e = A.readFileSync(Q, "utf8");
857
894
  return JSON.parse(e);
858
895
  } catch (e) {
859
896
  return console.info("Failed to read credentials:", e.message), null;
860
897
  }
861
898
  }
862
899
  function Te(e) {
863
- st();
900
+ rt();
864
901
  const o = {
865
902
  ...e,
866
903
  savedAt: (/* @__PURE__ */ new Date()).toISOString()
867
904
  };
868
- E.writeFileSync(Q, JSON.stringify(o, null, 2), {
905
+ A.writeFileSync(Q, JSON.stringify(o, null, 2), {
869
906
  mode: 384
870
907
  // Read/write for owner only
871
908
  });
872
909
  }
873
- function Re() {
910
+ function Ee() {
874
911
  try {
875
- return E.existsSync(Q) && E.unlinkSync(Q), !0;
912
+ return A.existsSync(Q) && A.unlinkSync(Q), !0;
876
913
  } catch (e) {
877
914
  return console.error("Failed to clear credentials:", e.message), !1;
878
915
  }
879
916
  }
880
- function rt(e) {
917
+ function it(e) {
881
918
  if (!e || !e.expiresAt)
882
919
  return !0;
883
920
  const o = 5 * 60 * 1e3, n = new Date(e.expiresAt).getTime();
884
921
  return Date.now() > n - o;
885
922
  }
886
- function he() {
887
- const e = ge();
923
+ function ye() {
924
+ const e = he();
888
925
  return e ? {
889
926
  email: e.userEmail,
890
927
  userId: e.userId
891
928
  } : null;
892
929
  }
893
- const G = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", se = 19284, ye = `http://localhost:${se}/callback`, it = "myop-cli";
894
- function at() {
895
- return ue.randomBytes(32).toString("base64url");
930
+ const Y = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", re = 19284, we = `http://localhost:${re}/callback`, at = "myop-cli";
931
+ function ct() {
932
+ return fe.randomBytes(32).toString("base64url");
896
933
  }
897
- function ct(e) {
898
- return ue.createHash("sha256").update(e).digest("base64url");
934
+ function lt(e) {
935
+ return fe.createHash("sha256").update(e).digest("base64url");
899
936
  }
900
- async function lt() {
901
- const e = await fetch(`${G}/oauth/register`, {
937
+ async function dt() {
938
+ const e = await fetch(`${Y}/oauth/register`, {
902
939
  method: "POST",
903
940
  headers: { "Content-Type": "application/json" },
904
941
  body: JSON.stringify({
905
- client_name: it,
906
- redirect_uris: [ye],
942
+ client_name: at,
943
+ redirect_uris: [we],
907
944
  grant_types: ["authorization_code", "refresh_token"],
908
945
  response_types: ["code"]
909
946
  })
@@ -914,8 +951,8 @@ async function lt() {
914
951
  }
915
952
  return e.json();
916
953
  }
917
- function oe(e, o, n, a = null) {
918
- const m = {
954
+ function ne(e, o, n, a = null) {
955
+ const u = {
919
956
  success: `<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#4ade80" stroke-width="2">
920
957
  <circle cx="12" cy="12" r="10"/>
921
958
  <path d="M8 12l2.5 2.5L16 9"/>
@@ -932,7 +969,7 @@ function oe(e, o, n, a = null) {
932
969
  success: { accent: "#4ade80", glow: "rgba(74, 222, 128, 0.1)" },
933
970
  error: { accent: "#f87171", glow: "rgba(248, 113, 113, 0.1)" },
934
971
  warning: { accent: "#fbbf24", glow: "rgba(251, 191, 36, 0.1)" }
935
- }, { accent: p, glow: v } = c[e] || c.error;
972
+ }, { accent: m, glow: S } = c[e] || c.error;
936
973
  return `<!DOCTYPE html>
937
974
  <html lang="en">
938
975
  <head>
@@ -993,7 +1030,7 @@ function oe(e, o, n, a = null) {
993
1030
  h1 {
994
1031
  font-size: 20px;
995
1032
  font-weight: 500;
996
- color: ${p};
1033
+ color: ${m};
997
1034
  margin-bottom: 12px;
998
1035
  letter-spacing: -0.5px;
999
1036
  }
@@ -1025,8 +1062,8 @@ function oe(e, o, n, a = null) {
1025
1062
  display: inline-flex;
1026
1063
  align-items: center;
1027
1064
  gap: 8px;
1028
- background: ${v};
1029
- border: 1px solid ${p}33;
1065
+ background: ${S};
1066
+ border: 1px solid ${m}33;
1030
1067
  border-radius: 4px;
1031
1068
  padding: 10px 16px;
1032
1069
  font-size: 12px;
@@ -1063,7 +1100,7 @@ function oe(e, o, n, a = null) {
1063
1100
  <body>
1064
1101
  <div class="container">
1065
1102
  <div class="icon">
1066
- ${m[e] || m.error}
1103
+ ${u[e] || u.error}
1067
1104
  </div>
1068
1105
  <h1>${o}</h1>
1069
1106
  <p class="message">${n}</p>
@@ -1080,23 +1117,23 @@ function oe(e, o, n, a = null) {
1080
1117
  </body>
1081
1118
  </html>`;
1082
1119
  }
1083
- function dt(e) {
1120
+ function pt(e) {
1084
1121
  return new Promise((o, n) => {
1085
- const a = We.createServer((m, c) => {
1086
- const p = new Oe(m.url, `http://localhost:${se}`);
1087
- if (p.pathname === "/callback") {
1088
- const v = p.searchParams.get("code"), S = p.searchParams.get("state"), f = p.searchParams.get("error");
1089
- if (f) {
1090
- c.writeHead(200, { "Content-Type": "text/html" }), c.end(oe(
1122
+ const a = We.createServer((u, c) => {
1123
+ const m = new Ie(u.url, `http://localhost:${re}`);
1124
+ if (m.pathname === "/callback") {
1125
+ const S = m.searchParams.get("code"), x = m.searchParams.get("state"), g = m.searchParams.get("error");
1126
+ if (g) {
1127
+ c.writeHead(200, { "Content-Type": "text/html" }), c.end(ne(
1091
1128
  "error",
1092
1129
  "Authentication Failed",
1093
1130
  "Unable to complete the authentication process.",
1094
- f
1095
- )), a.close(), n(new Error(`OAuth error: ${f}`));
1131
+ g
1132
+ )), a.close(), n(new Error(`OAuth error: ${g}`));
1096
1133
  return;
1097
1134
  }
1098
- if (S !== e) {
1099
- c.writeHead(400, { "Content-Type": "text/html" }), c.end(oe(
1135
+ if (x !== e) {
1136
+ c.writeHead(400, { "Content-Type": "text/html" }), c.end(ne(
1100
1137
  "warning",
1101
1138
  "Security Error",
1102
1139
  "State mismatch detected. This could indicate a CSRF attack. Please try authenticating again.",
@@ -1104,8 +1141,8 @@ function dt(e) {
1104
1141
  )), a.close(), n(new Error("State mismatch"));
1105
1142
  return;
1106
1143
  }
1107
- if (!v) {
1108
- c.writeHead(400, { "Content-Type": "text/html" }), c.end(oe(
1144
+ if (!S) {
1145
+ c.writeHead(400, { "Content-Type": "text/html" }), c.end(ne(
1109
1146
  "error",
1110
1147
  "Missing Authorization Code",
1111
1148
  "No authorization code was received from the server.",
@@ -1113,41 +1150,41 @@ function dt(e) {
1113
1150
  )), a.close(), n(new Error("No authorization code"));
1114
1151
  return;
1115
1152
  }
1116
- c.writeHead(200, { "Content-Type": "text/html" }), c.end(oe(
1153
+ c.writeHead(200, { "Content-Type": "text/html" }), c.end(ne(
1117
1154
  "success",
1118
1155
  "Authentication Successful",
1119
1156
  "You have been authenticated successfully. Return to the terminal to continue."
1120
- )), a.close(), o(v);
1157
+ )), a.close(), o(S);
1121
1158
  } else
1122
1159
  c.writeHead(404), c.end("Not found");
1123
1160
  });
1124
- a.listen(se, () => {
1125
- console.info(`OAuth callback server listening on port ${se}`);
1161
+ a.listen(re, () => {
1162
+ console.info(`OAuth callback server listening on port ${re}`);
1126
1163
  }), setTimeout(() => {
1127
1164
  a.close(), n(new Error("Authentication timed out"));
1128
1165
  }, 5 * 60 * 1e3);
1129
1166
  });
1130
1167
  }
1131
- async function pt(e, o, n) {
1132
- const a = await fetch(`${G}/oauth/token`, {
1168
+ async function mt(e, o, n) {
1169
+ const a = await fetch(`${Y}/oauth/token`, {
1133
1170
  method: "POST",
1134
1171
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
1135
1172
  body: new je({
1136
1173
  grant_type: "authorization_code",
1137
1174
  code: e,
1138
1175
  client_id: o,
1139
- redirect_uri: ye,
1176
+ redirect_uri: we,
1140
1177
  code_verifier: n
1141
1178
  })
1142
1179
  });
1143
1180
  if (!a.ok) {
1144
- const m = await a.json();
1145
- throw new Error(m.error_description || m.error || "Token exchange failed");
1181
+ const u = await a.json();
1182
+ throw new Error(u.error_description || u.error || "Token exchange failed");
1146
1183
  }
1147
1184
  return a.json();
1148
1185
  }
1149
- async function mt(e, o) {
1150
- const n = await fetch(`${G}/oauth/token`, {
1186
+ async function ut(e, o) {
1187
+ const n = await fetch(`${Y}/oauth/token`, {
1151
1188
  method: "POST",
1152
1189
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
1153
1190
  body: new je({
@@ -1162,9 +1199,9 @@ async function mt(e, o) {
1162
1199
  }
1163
1200
  return n.json();
1164
1201
  }
1165
- async function ut(e) {
1166
- var m, c, p;
1167
- const o = await fetch(`${G}/mcp`, {
1202
+ async function ft(e) {
1203
+ var u, c, m;
1204
+ const o = await fetch(`${Y}/mcp`, {
1168
1205
  method: "POST",
1169
1206
  headers: {
1170
1207
  "Content-Type": "application/json",
@@ -1185,57 +1222,57 @@ async function ut(e) {
1185
1222
  const n = await o.json();
1186
1223
  if (n.error)
1187
1224
  throw new Error(n.error.message);
1188
- const a = (p = (c = (m = n.result) == null ? void 0 : m.content) == null ? void 0 : c[0]) == null ? void 0 : p.text;
1225
+ const a = (m = (c = (u = n.result) == null ? void 0 : u.content) == null ? void 0 : c[0]) == null ? void 0 : m.text;
1189
1226
  if (a)
1190
1227
  return JSON.parse(a);
1191
1228
  throw new Error("Invalid response from whoami");
1192
1229
  }
1193
1230
  async function X() {
1194
- const e = A("Starting authentication...").start();
1231
+ const e = F("Starting authentication...").start();
1195
1232
  try {
1196
1233
  e.text = "Registering OAuth client...";
1197
- const n = (await lt()).client_id, a = at(), m = ct(a), c = ue.randomBytes(16).toString("hex");
1234
+ const n = (await dt()).client_id, a = ct(), u = lt(a), c = fe.randomBytes(16).toString("hex");
1198
1235
  e.text = "Waiting for authorization...";
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
- 🌐 Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${v.toString()}
1202
- `), await Ye(v.toString());
1203
- const S = await p;
1236
+ const m = pt(c), S = new Ie(`${Y}/oauth/authorize`);
1237
+ S.searchParams.set("response_type", "code"), S.searchParams.set("client_id", n), S.searchParams.set("redirect_uri", we), S.searchParams.set("code_challenge", u), S.searchParams.set("code_challenge_method", "S256"), S.searchParams.set("state", c), e.stop(), console.log(`
1238
+ 🌐 Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${S.toString()}
1239
+ `), await Ge(S.toString());
1240
+ const x = await m;
1204
1241
  e.start("Exchanging authorization code...");
1205
- const f = await pt(S, n, a);
1242
+ const g = await mt(x, n, a);
1206
1243
  e.text = "Getting user info...";
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(),
1244
+ const y = await ft(g.access_token), w = {
1245
+ accessToken: g.access_token,
1246
+ refreshToken: g.refresh_token,
1247
+ expiresAt: new Date(Date.now() + g.expires_in * 1e3).toISOString(),
1211
1248
  clientId: n,
1212
- userId: w.userId,
1213
- userEmail: w.email
1249
+ userId: y.userId,
1250
+ userEmail: y.email
1214
1251
  };
1215
- return Te(y), e.succeed(`Authenticated as ${w.email}`), y;
1252
+ return Te(w), e.succeed(`Authenticated as ${y.email}`), w;
1216
1253
  } catch (o) {
1217
1254
  throw e.fail(`Authentication failed: ${o.message}`), o;
1218
1255
  }
1219
1256
  }
1220
- async function Fe() {
1221
- const e = ge();
1257
+ async function Re() {
1258
+ const e = he();
1222
1259
  if (!e) {
1223
1260
  console.log("Not currently logged in.");
1224
1261
  return;
1225
1262
  }
1226
- Re(), console.log(`βœ… Logged out (was: ${e.userEmail})`);
1263
+ Ee(), console.log(`βœ… Logged out (was: ${e.userEmail})`);
1227
1264
  }
1228
- async function ft() {
1229
- let e = ge();
1265
+ async function gt() {
1266
+ let e = he();
1230
1267
  if (!e)
1231
1268
  return console.log(`Not logged in. Starting authentication...
1232
1269
  `), await X();
1233
- if (!rt(e))
1270
+ if (!it(e))
1234
1271
  return e;
1235
1272
  if (e.refreshToken) {
1236
- const o = A("Refreshing access token...").start();
1273
+ const o = F("Refreshing access token...").start();
1237
1274
  try {
1238
- const n = await mt(
1275
+ const n = await ut(
1239
1276
  e.refreshToken,
1240
1277
  e.clientId
1241
1278
  );
@@ -1246,86 +1283,86 @@ async function ft() {
1246
1283
  expiresAt: new Date(Date.now() + n.expires_in * 1e3).toISOString()
1247
1284
  }, Te(e), o.succeed("Token refreshed"), e;
1248
1285
  } catch {
1249
- return o.warn("Token refresh failed, please log in again"), Re(), await X();
1286
+ return o.warn("Token refresh failed, please log in again"), Ee(), await X();
1250
1287
  }
1251
1288
  }
1252
1289
  return console.log(`Session expired. Please log in again.
1253
1290
  `), await X();
1254
1291
  }
1255
- function gt() {
1256
- return G;
1292
+ function ht() {
1293
+ return Y;
1257
1294
  }
1258
- const re = "@myop/cli";
1259
- async function ht() {
1295
+ const ie = "@myop/cli";
1296
+ async function yt() {
1260
1297
  try {
1261
- const e = await fetch(`https://registry.npmjs.org/${re}/latest`);
1298
+ const e = await fetch(`https://registry.npmjs.org/${ie}/latest`);
1262
1299
  return e.ok ? (await e.json()).version : null;
1263
1300
  } catch {
1264
1301
  return null;
1265
1302
  }
1266
1303
  }
1267
- function yt(e, o) {
1304
+ function wt(e, o) {
1268
1305
  const n = e.split(".").map(Number), a = o.split(".").map(Number);
1269
- for (let m = 0; m < Math.max(n.length, a.length); m++) {
1270
- const c = n[m] || 0, p = a[m] || 0;
1271
- if (c > p) return 1;
1272
- if (c < p) return -1;
1306
+ for (let u = 0; u < Math.max(n.length, a.length); u++) {
1307
+ const c = n[u] || 0, m = a[u] || 0;
1308
+ if (c > m) return 1;
1309
+ if (c < m) return -1;
1273
1310
  }
1274
1311
  return 0;
1275
1312
  }
1276
- async function wt(e) {
1277
- const o = A({
1313
+ async function vt(e) {
1314
+ const o = F({
1278
1315
  text: "Checking for updates...",
1279
1316
  color: "cyan"
1280
- }).start(), n = await ht();
1281
- if (o.stop(), !n || yt(n, e) <= 0)
1317
+ }).start(), n = await yt();
1318
+ if (o.stop(), !n || wt(n, e) <= 0)
1282
1319
  return !1;
1283
1320
  if (console.log(`
1284
1321
  πŸ“¦ New version available: ${e} β†’ ${n}
1285
- `), await Me({
1322
+ `), await Oe({
1286
1323
  message: "Would you like to update now?",
1287
1324
  choices: [
1288
1325
  { name: "Yes, update now", value: !0 },
1289
1326
  { name: "No, continue with current version", value: !1 }
1290
1327
  ]
1291
1328
  })) {
1292
- const m = A({
1293
- text: `Updating ${re} to v${n}...`,
1329
+ const u = F({
1330
+ text: `Updating ${ie} to v${n}...`,
1294
1331
  color: "green"
1295
1332
  }).start();
1296
1333
  try {
1297
- ne(`npm install -g ${re}@latest`, { stdio: "pipe" }), m.succeed(`Updated to v${n}`), console.log(`
1334
+ se(`npm install -g ${ie}@latest`, { stdio: "pipe" }), u.succeed(`Updated to v${n}`), console.log(`
1298
1335
  Please restart the CLI to use the new version.
1299
1336
  `), process.exit(0);
1300
1337
  } catch {
1301
- return m.fail("Update failed"), console.log(`
1302
- You can manually update by running: npm install -g ${re}@latest
1338
+ return u.fail("Update failed"), console.log(`
1339
+ You can manually update by running: npm install -g ${ie}@latest
1303
1340
  `), !1;
1304
1341
  }
1305
1342
  }
1306
1343
  return !1;
1307
1344
  }
1308
- const vt = (e) => new Promise((o) => setTimeout(o, e));
1309
- l.executionPath = process.cwd();
1310
- const ae = (e = !1) => {
1311
- const o = l.program.getOptionValue("verbose");
1345
+ const St = (e) => new Promise((o) => setTimeout(o, e));
1346
+ d.executionPath = process.cwd();
1347
+ const ce = (e = !1) => {
1348
+ const o = d.program.getOptionValue("verbose");
1312
1349
  o || (console.info = () => {
1313
- }), console.info("πŸ“ verbose mode on"), l.options = {
1314
- configPath: l.program.getOptionValue("config"),
1350
+ }), console.info("πŸ“ verbose mode on"), d.options = {
1351
+ configPath: d.program.getOptionValue("config"),
1315
1352
  verbose: o
1316
1353
  };
1317
1354
  try {
1318
- return l.myopConfig = Ke(l.options.configPath), { configFound: !0 };
1355
+ return d.myopConfig = Xe(d.options.configPath), { configFound: !0 };
1319
1356
  } catch (n) {
1320
1357
  if (e) {
1321
1358
  console.info(`
1322
- ⚠️ failed read config file from ${l.options.configPath}, trying to create new one`);
1359
+ ⚠️ failed read config file from ${d.options.configPath}, trying to create new one`);
1323
1360
  try {
1324
1361
  const a = {
1325
1362
  author: "@myop-cli",
1326
1363
  flows: []
1327
1364
  };
1328
- return fe(l.options.configPath, a), l.myopConfig = a, { configFound: !0 };
1365
+ return ge(d.options.configPath, a), d.myopConfig = a, { configFound: !0 };
1329
1366
  } catch {
1330
1367
  return console.info("Error details :", n), { configFound: !1, error: n };
1331
1368
  }
@@ -1334,25 +1371,26 @@ const ae = (e = !1) => {
1334
1371
  }
1335
1372
  };
1336
1373
  [
1337
- new pe(),
1338
- ...ot
1374
+ new me(),
1375
+ ...nt
1339
1376
  ];
1340
- l.program = new Be();
1341
- l.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version("0.1.10");
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"));
1346
- l.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((e, o) => {
1347
- ae(!0), console.info("adding ", e, o, l.options.configPath), e === "flow" && ke._action(o), process.exit();
1377
+ const xt = "0.1.14";
1378
+ d.program = new Ve();
1379
+ d.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(xt);
1380
+ d.program.addOption(new ae("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
1381
+ d.program.addOption(new ae("-h, --help", "Show helpful information"));
1382
+ d.program.addOption(new ae("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
1383
+ d.program.addOption(new ae("--ci", "CI mode: print status info (version, config, auth) as JSON and exit without prompts"));
1384
+ d.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((e, o) => {
1385
+ ce(!0), console.info("adding ", e, o, d.options.configPath), e === "flow" && Pe._action(o), process.exit();
1348
1386
  });
1349
- l.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((e, o) => {
1350
- ae(), console.info("removing ", e, o, l.options.configPath), e === "flow" && Pe._action(o), process.exit();
1387
+ d.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((e, o) => {
1388
+ ce(), console.info("removing ", e, o, d.options.configPath), e === "flow" && _e._action(o), process.exit();
1351
1389
  });
1352
- l.program.command("install").description("Install Myop assets").action(async () => {
1353
- ae(), await Ie.action();
1390
+ d.program.command("install").description("Install Myop assets").action(async () => {
1391
+ ce(), await ke.action();
1354
1392
  });
1355
- l.program.command("login").description("Authenticate with Myop platform").action(async () => {
1393
+ d.program.command("login").description("Authenticate with Myop platform").action(async () => {
1356
1394
  try {
1357
1395
  await X();
1358
1396
  } catch (e) {
@@ -1360,52 +1398,52 @@ l.program.command("login").description("Authenticate with Myop platform").action
1360
1398
  }
1361
1399
  process.exit(0);
1362
1400
  });
1363
- l.program.command("logout").description("Clear stored credentials").action(async () => {
1364
- await Fe(), process.exit(0);
1401
+ d.program.command("logout").description("Clear stored credentials").action(async () => {
1402
+ await Re(), process.exit(0);
1365
1403
  });
1366
- l.program.command("whoami").description("Show current authenticated user").action(async () => {
1367
- const e = he();
1404
+ d.program.command("whoami").description("Show current authenticated user").action(async () => {
1405
+ const e = ye();
1368
1406
  e && e.email ? console.log(`Logged in as: ${e.email}`) : console.log("Not logged in. Run `myop login` to authenticate."), process.exit(0);
1369
1407
  });
1370
- l.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (e) => {
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");
1408
+ d.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (e) => {
1409
+ var j, $, T, z, v, _;
1410
+ const o = d.program.getOptionValue("config") || "./myop.config.json", n = await import("fs"), { execSync: a } = await import("child_process"), u = await import("path");
1373
1411
  let c = {};
1374
1412
  if (n.existsSync(o))
1375
1413
  try {
1376
- const g = n.readFileSync(o, "utf-8");
1377
- c = JSON.parse(g);
1378
- const b = c.name || c.componentName;
1379
- console.log(`πŸ“‹ Found config: ${b || "Unnamed component"}`), c.componentId && console.log(` Component ID: ${c.componentId}`);
1380
- } catch (g) {
1381
- console.error(`⚠️ Failed to parse ${o}:`, g.message);
1414
+ const h = n.readFileSync(o, "utf-8");
1415
+ c = JSON.parse(h);
1416
+ const M = c.name || c.componentName;
1417
+ console.log(`πŸ“‹ Found config: ${M || "Unnamed component"}`), c.componentId && console.log(` Component ID: ${c.componentId}`);
1418
+ } catch (h) {
1419
+ console.error(`⚠️ Failed to parse ${o}:`, h.message);
1382
1420
  }
1383
1421
  else
1384
1422
  console.log("⚠️ No myop.config.json found. A new component will be created.");
1385
1423
  if (!e.skipBuild) {
1386
- const g = A("Building project...").start();
1424
+ const h = F("Building project...").start();
1387
1425
  try {
1388
- a("npm run build", { stdio: "pipe" }), g.succeed("Build completed");
1389
- } catch (b) {
1390
- g.fail("Build failed"), console.error(b.message), process.exit(1);
1426
+ a("npm run build", { stdio: "pipe" }), h.succeed("Build completed");
1427
+ } catch (M) {
1428
+ h.fail("Build failed"), console.error(M.message), process.exit(1);
1391
1429
  }
1392
1430
  }
1393
- const p = "./dist/index.html";
1394
- n.existsSync(p) || (console.error("❌ Error: ./dist/index.html not found"), console.log(" Make sure your build outputs to ./dist/index.html"), process.exit(1));
1395
- let v;
1431
+ const m = "./dist/index.html";
1432
+ 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));
1433
+ let S;
1396
1434
  try {
1397
- v = await ft();
1398
- } catch (g) {
1399
- console.error("❌ Authentication failed:", g.message), process.exit(1);
1435
+ S = await gt();
1436
+ } catch (h) {
1437
+ console.error("❌ Authentication failed:", h.message), process.exit(1);
1400
1438
  }
1401
- const S = gt();
1402
- let f = A("Requesting upload URL...").start(), w;
1439
+ const x = ht();
1440
+ let g = F("Requesting upload URL...").start(), y;
1403
1441
  try {
1404
- const g = await fetch(`${S}/mcp`, {
1442
+ const h = await fetch(`${x}/mcp`, {
1405
1443
  method: "POST",
1406
1444
  headers: {
1407
1445
  "Content-Type": "application/json",
1408
- Authorization: `Bearer ${v.accessToken}`
1446
+ Authorization: `Bearer ${S.accessToken}`
1409
1447
  },
1410
1448
  body: JSON.stringify({
1411
1449
  jsonrpc: "2.0",
@@ -1414,63 +1452,63 @@ l.program.command("sync").description("Build and upload component to Myop platfo
1414
1452
  params: {
1415
1453
  name: "upload_component",
1416
1454
  arguments: {
1417
- name: c.name || c.componentName || m.default.basename(process.cwd()),
1455
+ name: c.name || c.componentName || u.default.basename(process.cwd()),
1418
1456
  componentId: c.componentId || void 0,
1419
1457
  organization: c.organization || void 0
1420
1458
  }
1421
1459
  }
1422
1460
  })
1423
1461
  });
1424
- if (!g.ok)
1425
- throw new Error(`Server returned ${g.status}`);
1426
- const b = await g.json();
1427
- if (b.error)
1428
- throw new Error(b.error.message);
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);
1462
+ if (!h.ok)
1463
+ throw new Error(`Server returned ${h.status}`);
1464
+ const M = await h.json();
1465
+ if (M.error)
1466
+ throw new Error(M.error.message);
1467
+ const N = (T = ($ = (j = M.result) == null ? void 0 : j.content) == null ? void 0 : $[0]) == null ? void 0 : T.text;
1468
+ if (y = JSON.parse(N), !y.success)
1469
+ throw new Error(y.error);
1470
+ g.succeed("Upload URL obtained");
1471
+ } catch (h) {
1472
+ g.fail("Failed to get upload URL"), console.error(" ", h.message), process.exit(1);
1435
1473
  }
1436
- f = A("Uploading component...").start();
1474
+ g = F("Uploading component...").start();
1437
1475
  try {
1438
- const g = n.readFileSync(p, "utf-8");
1439
- let b;
1440
- const H = w.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
1441
- if (H)
1442
- b = H[1];
1476
+ const h = n.readFileSync(m, "utf-8");
1477
+ let M;
1478
+ const N = y.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
1479
+ if (N)
1480
+ M = N[1];
1443
1481
  else {
1444
- const F = w.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
1445
- if (F)
1446
- b = F[1];
1482
+ const b = y.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
1483
+ if (b)
1484
+ M = b[1];
1447
1485
  else
1448
- throw new Error("Could not parse presigned URL from: " + w.curlCommand);
1486
+ throw new Error("Could not parse presigned URL from: " + y.curlCommand);
1449
1487
  }
1450
- console.info("Uploading to:", b.substring(0, 100) + "...");
1451
- const M = await fetch(b, {
1488
+ console.info("Uploading to:", M.substring(0, 100) + "...");
1489
+ const K = await fetch(M, {
1452
1490
  method: "PUT",
1453
1491
  headers: {
1454
1492
  "Content-Type": "text/html"
1455
1493
  },
1456
- body: g
1494
+ body: h
1457
1495
  });
1458
- if (!M.ok) {
1459
- const F = await M.text();
1460
- throw new Error(`Upload failed with status ${M.status}: ${F}`);
1496
+ if (!K.ok) {
1497
+ const b = await K.text();
1498
+ throw new Error(`Upload failed with status ${K.status}: ${b}`);
1461
1499
  }
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);
1500
+ g.succeed("Component uploaded");
1501
+ } catch (h) {
1502
+ g.fail("Upload failed"), console.error(" ", h.message), h.cause && console.error(" Cause:", h.cause), process.exit(1);
1465
1503
  }
1466
- f = A("Confirming upload...").start();
1467
- let y;
1504
+ g = F("Confirming upload...").start();
1505
+ let w;
1468
1506
  try {
1469
- const g = await fetch(`${S}/mcp`, {
1507
+ const h = await fetch(`${x}/mcp`, {
1470
1508
  method: "POST",
1471
1509
  headers: {
1472
1510
  "Content-Type": "application/json",
1473
- Authorization: `Bearer ${v.accessToken}`
1511
+ Authorization: `Bearer ${S.accessToken}`
1474
1512
  },
1475
1513
  body: JSON.stringify({
1476
1514
  jsonrpc: "2.0",
@@ -1479,50 +1517,50 @@ l.program.command("sync").description("Build and upload component to Myop platfo
1479
1517
  params: {
1480
1518
  name: "confirm_upload",
1481
1519
  arguments: {
1482
- uploadId: w.uploadId
1520
+ uploadId: y.uploadId
1483
1521
  }
1484
1522
  }
1485
1523
  })
1486
1524
  });
1487
- if (!g.ok)
1488
- throw new Error(`Server returned ${g.status}`);
1489
- const b = await g.json();
1490
- if (b.error)
1491
- throw new Error(b.error.message);
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);
1525
+ if (!h.ok)
1526
+ throw new Error(`Server returned ${h.status}`);
1527
+ const M = await h.json();
1528
+ if (M.error)
1529
+ throw new Error(M.error.message);
1530
+ const N = (_ = (v = (z = M.result) == null ? void 0 : z.content) == null ? void 0 : v[0]) == null ? void 0 : _.text;
1531
+ if (w = JSON.parse(N), !w.success)
1532
+ throw new Error(w.error);
1533
+ g.succeed("Upload confirmed");
1534
+ } catch (h) {
1535
+ g.fail("Confirmation failed"), console.error(" ", h.message), process.exit(1);
1498
1536
  }
1499
- if (y.isNewComponent || !c.componentId) {
1500
- c.componentId = y.componentId, c.organization = y.orgId, c.name || (c.name = y.componentName);
1537
+ if (w.isNewComponent || !c.componentId) {
1538
+ c.componentId = w.componentId, c.organization = w.orgId, c.name || (c.name = w.componentName);
1501
1539
  try {
1502
1540
  n.writeFileSync(o, JSON.stringify(c, null, 2)), console.log(`
1503
1541
  πŸ“ Updated ${o} with componentId`);
1504
- } catch (g) {
1542
+ } catch (h) {
1505
1543
  console.log(`
1506
- ⚠️ Could not update ${o}: ${g.message}`), console.log(` Please add componentId: "${y.componentId}" manually`);
1544
+ ⚠️ Could not update ${o}: ${h.message}`), console.log(` Please add componentId: "${w.componentId}" manually`);
1507
1545
  }
1508
1546
  }
1509
1547
  console.log(`
1510
- βœ… Sync completed successfully!`), console.log(` Component: ${y.componentName}`), console.log(` Dashboard: ${y.dashboardUrl}`), process.exit(0);
1548
+ βœ… Sync completed successfully!`), console.log(` Component: ${w.componentName}`), console.log(` Dashboard: ${w.dashboardUrl}`), process.exit(0);
1511
1549
  });
1512
- l.program.command("dev").description("Start development server with file watching").action(_e);
1513
- const St = () => {
1550
+ d.program.command("dev").description("Start development server with file watching").action(Ne);
1551
+ const bt = () => {
1514
1552
  try {
1515
- ne("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1553
+ se("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1516
1554
  } catch {
1517
1555
  return { gitNotInstalled: !0 };
1518
1556
  }
1519
1557
  try {
1520
- ne("git rev-parse --git-dir", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1558
+ se("git rev-parse --git-dir", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1521
1559
  } catch {
1522
1560
  return { notARepo: !0 };
1523
1561
  }
1524
1562
  try {
1525
- const e = ne("git diff --stat HEAD -- . 2>/dev/null || git diff --stat -- . 2>/dev/null", {
1563
+ const e = se("git diff --stat HEAD -- . 2>/dev/null || git diff --stat -- . 2>/dev/null", {
1526
1564
  encoding: "utf-8",
1527
1565
  stdio: ["pipe", "pipe", "pipe"]
1528
1566
  }).trim();
@@ -1533,22 +1571,22 @@ const St = () => {
1533
1571
  deletions: 0
1534
1572
  };
1535
1573
  const o = e.split(`
1536
- `), n = o[o.length - 1], a = n.match(/(\d+) insertion/), m = n.match(/(\d+) deletion/), c = n.match(/(\d+) file/);
1574
+ `), n = o[o.length - 1], a = n.match(/(\d+) insertion/), u = n.match(/(\d+) deletion/), c = n.match(/(\d+) file/);
1537
1575
  return {
1538
1576
  files: c ? parseInt(c[1]) : 0,
1539
1577
  insertions: a ? parseInt(a[1]) : 0,
1540
- deletions: m ? parseInt(m[1]) : 0
1578
+ deletions: u ? parseInt(u[1]) : 0
1541
1579
  };
1542
1580
  } catch {
1543
1581
  return null;
1544
1582
  }
1545
- }, U = async (e = !1, o = !1) => {
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();
1583
+ }, B = async (e = !1, o = !1) => {
1584
+ var y, w, j;
1585
+ const n = ye(), a = !!(n != null && n.email), u = ((y = d.myopConfig) == null ? void 0 : y.name) || ((w = d.myopConfig) == null ? void 0 : w.componentName), c = (j = d.myopConfig) == null ? void 0 : j.componentId, m = bt();
1548
1586
  console.log(`
1549
1587
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”`), console.log("β”‚ β”‚"), console.log("β”‚ Welcome to Myop CLI - Remote UI Made Easy β”‚"), console.log("β”‚ β”‚"), console.log(`β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
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 = [
1588
+ `), e && u ? (console.log(` Component: ${u}`), 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("");
1589
+ const x = [
1552
1590
  {
1553
1591
  emoji: "πŸš€",
1554
1592
  label: "Initialize new component",
@@ -1558,14 +1596,14 @@ const St = () => {
1558
1596
  },
1559
1597
  {
1560
1598
  emoji: "πŸ“¦",
1561
- label: m ? `Push "${m}"` : "Push component",
1599
+ label: u ? `Push "${u}"` : "Push component",
1562
1600
  value: "sync",
1563
1601
  help: "Builds project & uploads dist/index.html to Myop",
1564
1602
  disabled: e ? a ? !1 : "(login required)" : "(no config file)"
1565
1603
  },
1566
1604
  {
1567
1605
  emoji: "πŸ› οΈ ",
1568
- label: m ? `Start dev mode for "${m}"` : "Start dev mode",
1606
+ label: u ? `Start dev mode for "${u}"` : "Start dev mode",
1569
1607
  value: "dev",
1570
1608
  help: "Starts dev server with HMR for instant preview of changes",
1571
1609
  disabled: e ? !1 : "(no config file)"
@@ -1576,8 +1614,8 @@ const St = () => {
1576
1614
  value: $.value,
1577
1615
  disabled: $.disabled
1578
1616
  }));
1579
- switch (S.push(
1580
- new pe(),
1617
+ switch (x.push(
1618
+ new me(),
1581
1619
  {
1582
1620
  name: o && a ? `πŸ”“ Logout (${n.email})
1583
1621
  Clears stored credentials from this machine` : o && !a ? `πŸ” Login to Myop
@@ -1588,17 +1626,17 @@ const St = () => {
1588
1626
  name: o ? "πŸ“– Hide help" : "πŸ“– Show help",
1589
1627
  value: "help"
1590
1628
  },
1591
- new pe(),
1629
+ new me(),
1592
1630
  {
1593
1631
  name: "πŸ‘‹ Exit",
1594
1632
  value: "exit"
1595
1633
  }
1596
- ), await Me({
1634
+ ), await Oe({
1597
1635
  message: "What would you like to do?",
1598
- choices: S
1636
+ choices: x
1599
1637
  })) {
1600
1638
  case "init":
1601
- await xt();
1639
+ await Ct();
1602
1640
  break;
1603
1641
  case "sync":
1604
1642
  console.log(`
@@ -1609,34 +1647,34 @@ Running sync...
1609
1647
  $("node " + process.argv[1] + " sync", { stdio: "inherit" });
1610
1648
  } catch {
1611
1649
  }
1612
- await U(!0, o);
1650
+ await B(!0, o);
1613
1651
  break;
1614
1652
  case "dev":
1615
- await _e();
1653
+ await Ne();
1616
1654
  break;
1617
1655
  case "login":
1618
1656
  try {
1619
1657
  await X(), console.log(`
1620
- `), await U(e, o);
1621
- } catch (_) {
1622
- console.error("Login failed:", _.message), await U(e, o);
1658
+ `), await B(e, o);
1659
+ } catch (T) {
1660
+ console.error("Login failed:", T.message), await B(e, o);
1623
1661
  }
1624
1662
  break;
1625
1663
  case "logout":
1626
- await Fe(), console.log(`
1627
- `), await U(e, o);
1664
+ await Re(), console.log(`
1665
+ `), await B(e, o);
1628
1666
  break;
1629
1667
  case "help":
1630
- await U(e, !o);
1668
+ await B(e, !o);
1631
1669
  break;
1632
1670
  case "exit":
1633
1671
  process.exit(0);
1634
1672
  }
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({
1673
+ }, Ct = async () => {
1674
+ const { input: e, select: o } = await import("@inquirer/prompts"), n = await import("fs"), u = (await import("path")).default.basename(process.cwd()), c = await e({
1637
1675
  message: "Component name:",
1638
- default: m
1639
- }), p = await o({
1676
+ default: u
1677
+ }), m = await o({
1640
1678
  message: "Component type:",
1641
1679
  choices: [
1642
1680
  { name: "πŸ“„ HTML", value: "html", description: "Plain HTML/JS/CSS component" },
@@ -1644,15 +1682,15 @@ Running sync...
1644
1682
  { name: "πŸ’š Vue", value: "vue", disabled: "(coming soon)" },
1645
1683
  { name: "πŸ…°οΈ Angular", value: "angular", disabled: "(coming soon)" }
1646
1684
  ]
1647
- }), v = {
1685
+ }), S = {
1648
1686
  name: c,
1649
- type: p,
1687
+ type: m,
1650
1688
  author: "@myop-cli"
1651
- }, S = l.program.getOptionValue("config") || "./myop.config.json";
1689
+ }, x = d.program.getOptionValue("config") || "./myop.config.json";
1652
1690
  try {
1653
- n.writeFileSync(S, JSON.stringify(v, null, 2)), console.log(`
1654
- βœ… Created ${S}`);
1655
- const f = {
1691
+ n.writeFileSync(x, JSON.stringify(S, null, 2)), console.log(`
1692
+ βœ… Created ${x}`);
1693
+ const g = {
1656
1694
  name: c.toLowerCase().replace(/\s+/g, "-"),
1657
1695
  version: "1.0.0",
1658
1696
  type: "module",
@@ -1664,7 +1702,7 @@ Running sync...
1664
1702
  esbuild: "^0.24.0"
1665
1703
  }
1666
1704
  };
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';
1705
+ n.writeFileSync("package.json", JSON.stringify(g, 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';
1668
1706
  import fs from 'fs';
1669
1707
  import path from 'path';
1670
1708
 
@@ -1744,7 +1782,7 @@ fs.writeFileSync('dist/index.html', html);
1744
1782
  console.log('βœ… Built dist/index.html');
1745
1783
  console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS files\`);
1746
1784
  `), console.log("βœ… Created build.js");
1747
- const y = `<!DOCTYPE html>
1785
+ const w = `<!DOCTYPE html>
1748
1786
  <html lang="en">
1749
1787
  <head>
1750
1788
  <meta charset="UTF-8">
@@ -1761,7 +1799,7 @@ console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS
1761
1799
  </body>
1762
1800
  </html>
1763
1801
  `;
1764
- n.writeFileSync("index.html", y), console.log("βœ… Created index.html");
1802
+ n.writeFileSync("index.html", w), console.log("βœ… Created index.html");
1765
1803
  const j = `// ${c} - Entry Point
1766
1804
  import { init } from './modules/app.js';
1767
1805
  import { setupMyopInterface } from './modules/myop.js';
@@ -1801,7 +1839,7 @@ export function setupMyopInterface() {
1801
1839
  @import './main.css';
1802
1840
  `;
1803
1841
  n.writeFileSync("src/styles/index.css", z), console.log("βœ… Created src/styles/index.css");
1804
- const x = `/* ${c} - Main Styles */
1842
+ const v = `/* ${c} - Main Styles */
1805
1843
 
1806
1844
  * {
1807
1845
  box-sizing: border-box;
@@ -1830,49 +1868,49 @@ p {
1830
1868
  line-height: 1.5;
1831
1869
  }
1832
1870
  `;
1833
- n.writeFileSync("src/styles/main.css", x), console.log("βœ… Created src/styles/main.css"), console.log(`
1871
+ n.writeFileSync("src/styles/main.css", v), console.log("βœ… Created src/styles/main.css"), console.log(`
1834
1872
  πŸ“¦ Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
1835
- `), l.myopConfig = v, await U(!0);
1836
- } catch (f) {
1837
- console.error(`Failed to initialize component: ${f.message}`), process.exit(1);
1873
+ `), d.myopConfig = S, await B(!0);
1874
+ } catch (g) {
1875
+ console.error(`Failed to initialize component: ${g.message}`), process.exit(1);
1838
1876
  }
1839
1877
  };
1840
- l.program.command("default", { isDefault: !0 }).action(async () => {
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 };
1878
+ d.program.command("default", { isDefault: !0 }).action(async () => {
1879
+ if (d.program.getOptionValue("help") && (console.log(Ke), process.exit()), d.program.getOptionValue("ci")) {
1880
+ const c = await import("fs"), m = d.program.getOptionValue("config") || "./myop.config.json", S = d.program.version(), x = ye();
1881
+ let g = { found: !1 };
1844
1882
  try {
1845
- if (c.existsSync(p)) {
1846
- const y = c.readFileSync(p, "utf-8"), j = JSON.parse(y);
1847
- f = {
1883
+ if (c.existsSync(m)) {
1884
+ const w = c.readFileSync(m, "utf-8"), j = JSON.parse(w);
1885
+ g = {
1848
1886
  found: !0,
1849
- path: p,
1887
+ path: m,
1850
1888
  name: j.name || j.componentName || null,
1851
1889
  componentId: j.componentId || null,
1852
1890
  organization: j.organization || null
1853
1891
  };
1854
1892
  }
1855
- } catch (y) {
1856
- f = { found: !1, error: y.message };
1893
+ } catch (w) {
1894
+ g = { found: !1, error: w.message };
1857
1895
  }
1858
- const w = {
1859
- version: v,
1860
- config: f,
1896
+ const y = {
1897
+ version: S,
1898
+ config: g,
1861
1899
  auth: {
1862
- loggedIn: !!(S != null && S.email),
1863
- email: (S == null ? void 0 : S.email) || null
1900
+ loggedIn: !!(x != null && x.email),
1901
+ email: (x == null ? void 0 : x.email) || null
1864
1902
  }
1865
1903
  };
1866
- console.log(JSON.stringify(w, null, 2)), process.exit(0);
1904
+ console.log(JSON.stringify(y, null, 2)), process.exit(0);
1867
1905
  }
1868
- let n = A({
1906
+ let n = F({
1869
1907
  text: "Loading Myop CLI...",
1870
1908
  color: "green"
1871
1909
  }).start();
1872
- const a = ae();
1873
- await vt(500), n.stop();
1874
- const m = l.program.version();
1875
- await wt(m), await U(a.configFound);
1910
+ const a = ce();
1911
+ await St(500), n.stop();
1912
+ const u = d.program.version();
1913
+ await vt(u), await B(a.configFound);
1876
1914
  });
1877
- l.program.parse(process.argv);
1878
- l.program.opts();
1915
+ d.program.parse(process.argv);
1916
+ d.program.opts();