@myop/cli 0.1.11 β†’ 0.1.13

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 +531 -466
  2. package/package.json +1 -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 $e, Separator as de } from "@inquirer/prompts";
4
- import { Command as ze, Option as me } 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 Me, 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
- }, Oe = {
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
- }, Ie = {
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,7 +216,7 @@ ${a}
216
216
  </body>
217
217
  </html>`;
218
218
  }
219
- async function Pe() {
219
+ async function Ne() {
220
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://")) {
@@ -224,17 +224,53 @@ async function Pe() {
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"), j = e.default.readFileSync(o.default.join(p, "app.js"), "utf-8"), g = 9292, y = 9293, w = "./dist";
228
- let I = !1, C = !1;
229
- const _ = /* @__PURE__ */ new Map(), B = l.program.getOptionValue("config") || "./myop.config.json";
230
- let S, P, f = !1;
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
+ let j = !1, $ = !1;
229
+ const T = /* @__PURE__ */ new Map(), z = d.program.getOptionValue("config") || "./myop.config.json";
230
+ let v, _, h = !1;
231
231
  try {
232
- const s = e.default.readFileSync(B, "utf-8"), t = JSON.parse(s);
233
- S = t.componentId, P = t.componentName || null, f = t.HMR === !0, S || (console.error("❌ Error: componentId not found in myop.config.json"), process.exit(1)), f && console.log("πŸ”₯ HMR enabled");
232
+ const s = e.default.readFileSync(z, "utf-8"), t = JSON.parse(s);
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,41 +283,41 @@ async function Pe() {
247
283
  ".svg": "image/svg+xml",
248
284
  ".ico": "image/x-icon"
249
285
  }[t] || "application/octet-stream";
250
- }, $ = /* @__PURE__ */ new Map(), F = [], Ne = 50, L = [], z = /* @__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], m = s.headers["sec-websocket-key"], d = u("sha1").update(m + "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
- }, ae = 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: m, componentName: d } = JSON.parse(r);
274
- $.set(i, { path: m, name: d || null });
275
- const h = d ? ` (${d})` : "";
276
- console.log(`βœ… Registered: ${i}${h} -> ${m}`), t.writeHead(200), t.end(JSON.stringify({ success: !0, registered: Array.from($.keys()) }));
277
- const O = Array.from($.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
- L.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
322
  components: O
287
323
  })}
@@ -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
- $.delete(i), console.log(`❌ Unregistered: ${i}`), t.writeHead(200), t.end(JSON.stringify({ success: !0 }));
303
- const m = Array.from($.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
- L.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: m
348
+ components: l
313
349
  })}
314
350
 
315
351
  `);
@@ -320,124 +356,124 @@ 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($.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:${g}`), i = r.pathname, m = 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 = $.get(k), J = N ? N.path : null, Ce = (W) => {
337
- let x = "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 M = s.headers.referer || s.headers.referrer;
375
+ const I = s.headers.referer || s.headers.referrer;
340
376
  try {
341
- const Y = new URL(M);
342
- x = 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
- x = M, R = M;
380
+ C = I, E = I;
345
381
  }
346
382
  } else if (s.headers.origin)
347
383
  try {
348
- const M = new URL(s.headers.origin);
349
- x = M.origin, R = M.hostname || M.origin;
384
+ const I = new URL(s.headers.origin);
385
+ C = I.origin, E = I.hostname || I.origin;
350
386
  } catch {
351
- x = 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 M = s.socket.remoteAddress;
355
- M === "::1" || M === "::ffff:127.0.0.1" ? (x = "localhost", R = "localhost (direct)") : (x = M, R = M.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 le = s.headers.referer || s.headers.referrer || x, 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: le,
363
- origin: x,
364
- originLabel: R
398
+ referrer: pe,
399
+ origin: C,
400
+ originLabel: E
365
401
  };
366
- z.has(x) || (z.set(x, {
367
- url: x,
368
- label: R,
402
+ V.has(C) || (V.set(C, {
403
+ url: C,
404
+ label: E,
369
405
  firstSeen: Date.now(),
370
406
  requestCount: 0
371
- }), L.forEach((M) => {
407
+ }), D.forEach((I) => {
372
408
  try {
373
- M.write(`data: ${JSON.stringify({
409
+ I.write(`data: ${JSON.stringify({
374
410
  type: "origins",
375
- origins: Array.from(z.values())
411
+ origins: Array.from(V.values())
376
412
  })}
377
413
 
378
414
  `);
379
415
  } catch {
380
416
  }
381
417
  }));
382
- const Be = z.get(x);
383
- Be.requestCount++, L.forEach((M) => {
418
+ const ze = V.get(C);
419
+ ze.requestCount++, D.forEach((I) => {
384
420
  try {
385
- M.write(`data: ${JSON.stringify({
421
+ I.write(`data: ${JSON.stringify({
386
422
  type: "origins",
387
- origins: Array.from(z.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(), L.forEach((M) => {
429
+ }), q.push(oe), q.length > Fe && q.shift(), D.forEach((I) => {
394
430
  try {
395
- M.write(`data: ${JSON.stringify(te)}
431
+ I.write(`data: ${JSON.stringify(oe)}
396
432
 
397
433
  `);
398
434
  } catch {
399
435
  }
400
436
  });
401
437
  };
402
- if (J) {
403
- const W = o.default.join(J, "index.html");
404
- e.default.readFile(W, "utf-8", (x, R) => {
405
- if (x) {
438
+ if (L) {
439
+ const W = o.default.join(L, "index.html");
440
+ e.default.readFile(W, "utf-8", (C, E) => {
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 le = `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: le,
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}`), Ce(!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
- Ce(!1), fetch(W).then((x) => x.text()).then((x) => {
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": "*"
438
- }), t.end(x);
439
- }).catch((x) => {
440
- console.error(`❌ Proxy error: ${x.message}`), t.writeHead(502, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Failed to fetch from cloud.myop.dev" }));
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" }));
441
477
  });
442
478
  }
443
479
  return;
@@ -448,67 +484,67 @@ Sec-WebSocket-Accept: ${d}\r
448
484
  "Cache-Control": "no-cache",
449
485
  Connection: "keep-alive",
450
486
  "Access-Control-Allow-Origin": "*"
451
- }), L.push(t);
452
- const k = Array.from($.entries()).map(([N, J]) => ({
453
- id: N,
454
- path: J.path,
455
- name: J.name
487
+ }), D.push(t);
488
+ const P = Array.from(b.entries()).map(([R, L]) => ({
489
+ id: R,
490
+ path: L.path,
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(z.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 = L.indexOf(t);
474
- N !== -1 && L.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 (m.length === 0) {
479
- t.writeHead(200, { "Content-Type": "text/html" }), t.end(nt(g, y, v, j));
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 (m[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 (m.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 = m[1], h = $.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 O = h.path, T = m.slice(2), V = T.length === 0 ? "index.html" : T.join("/"), K = o.default.join(O, 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 J = H(K);
502
- console.log(`βœ… Serving: ${K} (${J})`), t.writeHead(200, {
503
- "Content-Type": J,
537
+ const L = K(J);
538
+ console.log(`βœ… Serving: ${J} (${L})`), t.writeHead(200, {
539
+ "Content-Type": L,
504
540
  "Access-Control-Allow-Origin": "*"
505
- }), t.end(N);
541
+ }), t.end(R);
506
542
  });
507
- }), ye = () => new Promise((s, t) => {
543
+ }), ve = () => new Promise((s, t) => {
508
544
  const r = JSON.stringify({
509
- componentId: S,
510
- distPath: o.default.resolve(b, w),
511
- componentName: P
545
+ componentId: v,
546
+ distPath: o.default.resolve(N, w),
547
+ componentName: _
512
548
  }), i = {
513
549
  hostname: "localhost",
514
550
  port: y,
@@ -518,15 +554,15 @@ Sec-WebSocket-Accept: ${d}\r
518
554
  "Content-Type": "application/json",
519
555
  "Content-Length": Buffer.byteLength(r)
520
556
  }
521
- }, m = a.default.request(i, (d) => {
522
- let h = "";
523
- d.on("data", (O) => h += O), 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
- m.on("error", t), m.write(r), m.end();
528
- }), Ee = () => new Promise((s, t) => {
529
- const r = JSON.stringify({ componentId: S }), 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
567
  port: y,
532
568
  path: "/_unregister",
@@ -535,24 +571,24 @@ Sec-WebSocket-Accept: ${d}\r
535
571
  "Content-Type": "application/json",
536
572
  "Content-Length": Buffer.byteLength(r)
537
573
  }
538
- }, m = a.default.request(i, (d) => {
574
+ }, l = a.default.request(i, (p) => {
539
575
  s();
540
576
  });
541
- m.on("error", () => s()), m.write(r), m.end();
577
+ l.on("error", () => s()), l.write(r), l.end();
542
578
  }), He = () => {
543
- if (!f) return;
579
+ if (!h) return;
544
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 -->"), m = t.indexOf("<\/script>", i) + 9;
549
- t = t.slice(0, i) + t.slice(m);
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 = '${S}';
591
+ const componentId = '${v}';
556
592
  const wsUrl = 'ws://localhost:${y}/_hmr/' + componentId;
557
593
  let ws;
558
594
  let reconnectAttempts = 0;
@@ -658,7 +694,7 @@ Sec-WebSocket-Accept: ${d}\r
658
694
  } catch (t) {
659
695
  console.error("❌ Failed to inject HMR script:", t.message);
660
696
  }
661
- }, Le = (s) => {
697
+ }, Je = (s) => {
662
698
  const t = Buffer.from(s), r = t.length;
663
699
  let i;
664
700
  return r < 126 ? i = Buffer.concat([
@@ -678,9 +714,9 @@ Sec-WebSocket-Accept: ${d}\r
678
714
  // 64-bit length
679
715
  t
680
716
  ]), i;
681
- }, Je = () => {
682
- if (!f) return;
683
- const s = D.get(S);
717
+ }, Le = () => {
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)`);
@@ -688,66 +724,66 @@ Sec-WebSocket-Accept: ${d}\r
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
- }), m = Le(i);
698
- s.forEach((d) => {
733
+ }), l = Je(i);
734
+ s.forEach((p) => {
699
735
  try {
700
- d.write(m);
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
- }, ce = () => {
709
- if (I) {
710
- C = !0;
744
+ }, de = () => {
745
+ if (j) {
746
+ $ = !0;
711
747
  return;
712
748
  }
713
- I = !0, console.log(`
749
+ j = !0, console.log(`
714
750
  πŸ”¨ Building...`), n("npm run build", (s, t, r) => {
715
- I = !1, s ? (console.error("❌ Build failed:", s.message), r && console.error(r)) : (console.log("βœ… Build completed"), t && console.log(t), He(), Je()), C && (C = !1, ce());
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
- }, we = /* @__PURE__ */ new Set(), ve = (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 m = 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(".") && ve(m);
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(m, "utf-8");
728
- _.set(m, h);
763
+ const f = e.default.readFileSync(l, "utf-8");
764
+ T.set(l, f);
729
765
  } catch {
730
766
  }
731
767
  }
732
- }), we.has(s) || (we.add(s), e.default.watch(s, (i, m) => {
733
- if (!m) return;
734
- const d = o.default.extname(m);
735
- if (d !== ".js" && d !== ".css" && d !== ".html") return;
736
- const h = o.default.join(s, m);
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 O = e.default.readFileSync(h, "utf-8"), T = _.get(h);
740
- O !== T && (_.set(h, O), console.log(`πŸ“ File changed: ${h}`), ce());
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
- }, Se = () => {
782
+ }, be = () => {
747
783
  console.log(`
748
- πŸ”¨ Component: ${S}`), ce(), ve(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
789
  port: y,
@@ -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 m = "";
767
- r.on("data", (d) => m += 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: O } = JSON.parse(m);
770
- $.set(d, { path: h, name: O || null });
771
- const T = O ? ` (${O})` : "";
772
- console.log(`βœ… Registered: ${d}${T} -> ${h}`), i.writeHead(200), i.end(JSON.stringify({ success: !0, registered: Array.from($.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 m = "";
779
- r.on("data", (d) => m += 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(m);
782
- $.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($.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
827
  }), t.listen(y, () => {
792
828
  console.log(`
793
- πŸ”„ Taking over as server...`), console.log(`πŸ“‘ Management server on port ${y}`), 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(g, () => {
796
- console.log(`πŸ“‘ Main server running at http://localhost:${g}`), $.set(S, {
797
- path: o.default.resolve(b, w),
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: ${S}${r}`), console.log(`πŸ“‘ Access at: http://localhost:${g}/view/${S}/`), 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 ye(), console.log(`βœ… Re-registered component: ${S}`), 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
- }, xe = 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", xe), process.on("SIGTERM", xe), ae.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 ye();
828
- console.log(`βœ… Registered component: ${S}`), console.log(`πŸ“‘ Access at: http://localhost:${g}/view/${S}/`), console.log(`πŸ“‹ All registered components: ${t.registered.join(", ")}`), Se(), 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
- }), ae.on("upgrade", Ae), ae.listen(y, 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 ${y}`), 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(g, async () => {
839
- console.log(`πŸ“‘ Main server running at http://localhost:${g}`), $.set(S, {
840
- path: o.default.resolve(b, w),
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: ${S}${s}`), console.log(`πŸ“‘ Access at: http://localhost:${g}/view/${S}/`), Se();
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 pe = Z.join(Ge.homedir(), ".myop"), Q = Z.join(pe, "credentials.json");
849
- function st() {
850
- E.existsSync(pe) || E.mkdirSync(pe, { 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
- function _e(e) {
863
- st();
899
+ function Te(e) {
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 Te() {
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 Re() {
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, he = `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: [he],
942
+ client_name: at,
943
+ redirect_uris: [we],
907
944
  grant_types: ["authorization_code", "refresh_token"],
908
945
  response_types: ["code"]
909
946
  })
@@ -914,7 +951,7 @@ async function lt() {
914
951
  }
915
952
  return e.json();
916
953
  }
917
- function oe(e, o, n, a = null) {
954
+ function ne(e, o, n, a = null) {
918
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"/>
@@ -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;
@@ -1080,14 +1117,14 @@ 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
1122
  const a = We.createServer((u, c) => {
1086
- const p = new Me(u.url, `http://localhost:${se}`);
1087
- if (p.pathname === "/callback") {
1088
- const v = p.searchParams.get("code"), j = p.searchParams.get("state"), g = p.searchParams.get("error");
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");
1089
1126
  if (g) {
1090
- c.writeHead(200, { "Content-Type": "text/html" }), c.end(oe(
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.",
@@ -1095,8 +1132,8 @@ function dt(e) {
1095
1132
  )), a.close(), n(new Error(`OAuth error: ${g}`));
1096
1133
  return;
1097
1134
  }
1098
- if (j !== 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,30 +1150,30 @@ 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: he,
1176
+ redirect_uri: we,
1140
1177
  code_verifier: n
1141
1178
  })
1142
1179
  });
@@ -1146,8 +1183,8 @@ async function pt(e, o, n) {
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 u, 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,26 +1222,26 @@ 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 = (u = n.result) == null ? void 0 : u.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(), u = 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 Me(`${G}/oauth/authorize`);
1200
- v.searchParams.set("response_type", "code"), v.searchParams.set("client_id", n), v.searchParams.set("redirect_uri", he), v.searchParams.set("code_challenge", u), 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 j = 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 g = await pt(j, n, a);
1242
+ const g = await mt(x, n, a);
1206
1243
  e.text = "Getting user info...";
1207
- const y = await ut(g.access_token), w = {
1244
+ const y = await ft(g.access_token), w = {
1208
1245
  accessToken: g.access_token,
1209
1246
  refreshToken: g.refresh_token,
1210
1247
  expiresAt: new Date(Date.now() + g.expires_in * 1e3).toISOString(),
@@ -1212,30 +1249,30 @@ async function X() {
1212
1249
  userId: y.userId,
1213
1250
  userEmail: y.email
1214
1251
  };
1215
- return _e(w), e.succeed(`Authenticated as ${y.email}`), w;
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
- Te(), 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
  );
@@ -1244,88 +1281,88 @@ async function ft() {
1244
1281
  accessToken: n.access_token,
1245
1282
  refreshToken: n.refresh_token,
1246
1283
  expiresAt: new Date(Date.now() + n.expires_in * 1e3).toISOString()
1247
- }, _e(e), o.succeed("Token refreshed"), e;
1284
+ }, Te(e), o.succeed("Token refreshed"), e;
1248
1285
  } catch {
1249
- return o.warn("Token refresh failed, please log in again"), Te(), 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
1306
  for (let u = 0; u < Math.max(n.length, a.length); u++) {
1270
- const c = n[u] || 0, p = a[u] || 0;
1271
- if (c > p) return 1;
1272
- if (c < p) return -1;
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 $e({
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 u = 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" }), u.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
1338
  return u.fail("Update failed"), console.log(`
1302
- You can manually update by running: npm install -g ${re}@latest
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 ie = (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,24 +1371,26 @@ const ie = (e = !1) => {
1334
1371
  }
1335
1372
  };
1336
1373
  [
1337
- new de(),
1338
- ...ot
1374
+ new me(),
1375
+ ...nt
1339
1376
  ];
1340
- l.program = new ze();
1341
- l.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version("0.1.10");
1342
- l.program.addOption(new me("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
1343
- l.program.addOption(new me("-h, --help", "Show helpful information"));
1344
- l.program.addOption(new me("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
1345
- l.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((e, o) => {
1346
- ie(!0), console.info("adding ", e, o, l.options.configPath), e === "flow" && ke._action(o), process.exit();
1377
+ const xt = "0.1.13";
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();
1347
1386
  });
1348
- l.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((e, o) => {
1349
- ie(), console.info("removing ", e, o, l.options.configPath), e === "flow" && Ie._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();
1350
1389
  });
1351
- l.program.command("install").description("Install Myop assets").action(async () => {
1352
- ie(), await Oe.action();
1390
+ d.program.command("install").description("Install Myop assets").action(async () => {
1391
+ ce(), await ke.action();
1353
1392
  });
1354
- l.program.command("login").description("Authenticate with Myop platform").action(async () => {
1393
+ d.program.command("login").description("Authenticate with Myop platform").action(async () => {
1355
1394
  try {
1356
1395
  await X();
1357
1396
  } catch (e) {
@@ -1359,52 +1398,52 @@ l.program.command("login").description("Authenticate with Myop platform").action
1359
1398
  }
1360
1399
  process.exit(0);
1361
1400
  });
1362
- l.program.command("logout").description("Clear stored credentials").action(async () => {
1363
- await Fe(), process.exit(0);
1401
+ d.program.command("logout").description("Clear stored credentials").action(async () => {
1402
+ await Re(), process.exit(0);
1364
1403
  });
1365
- l.program.command("whoami").description("Show current authenticated user").action(async () => {
1366
- const e = Re();
1404
+ d.program.command("whoami").description("Show current authenticated user").action(async () => {
1405
+ const e = ye();
1367
1406
  e && e.email ? console.log(`Logged in as: ${e.email}`) : console.log("Not logged in. Run `myop login` to authenticate."), process.exit(0);
1368
1407
  });
1369
- l.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (e) => {
1370
- var I, C, _, B, S, P;
1371
- const o = l.program.getOptionValue("config") || "./myop.config.json", n = await import("fs"), { execSync: a } = await import("child_process"), u = 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");
1372
1411
  let c = {};
1373
1412
  if (n.existsSync(o))
1374
1413
  try {
1375
- const f = n.readFileSync(o, "utf-8");
1376
- c = JSON.parse(f);
1377
- const b = c.name || c.componentName;
1378
- console.log(`πŸ“‹ Found config: ${b || "Unnamed component"}`), c.componentId && console.log(` Component ID: ${c.componentId}`);
1379
- } catch (f) {
1380
- console.error(`⚠️ Failed to parse ${o}:`, f.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);
1381
1420
  }
1382
1421
  else
1383
1422
  console.log("⚠️ No myop.config.json found. A new component will be created.");
1384
1423
  if (!e.skipBuild) {
1385
- const f = A("Building project...").start();
1424
+ const h = F("Building project...").start();
1386
1425
  try {
1387
- a("npm run build", { stdio: "pipe" }), f.succeed("Build completed");
1388
- } catch (b) {
1389
- f.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);
1390
1429
  }
1391
1430
  }
1392
- const p = "./dist/index.html";
1393
- 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));
1394
- 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;
1395
1434
  try {
1396
- v = await ft();
1397
- } catch (f) {
1398
- console.error("❌ Authentication failed:", f.message), process.exit(1);
1435
+ S = await gt();
1436
+ } catch (h) {
1437
+ console.error("❌ Authentication failed:", h.message), process.exit(1);
1399
1438
  }
1400
- const j = gt();
1401
- let g = A("Requesting upload URL...").start(), y;
1439
+ const x = ht();
1440
+ let g = F("Requesting upload URL...").start(), y;
1402
1441
  try {
1403
- const f = await fetch(`${j}/mcp`, {
1442
+ const h = await fetch(`${x}/mcp`, {
1404
1443
  method: "POST",
1405
1444
  headers: {
1406
1445
  "Content-Type": "application/json",
1407
- Authorization: `Bearer ${v.accessToken}`
1446
+ Authorization: `Bearer ${S.accessToken}`
1408
1447
  },
1409
1448
  body: JSON.stringify({
1410
1449
  jsonrpc: "2.0",
@@ -1420,56 +1459,56 @@ l.program.command("sync").description("Build and upload component to Myop platfo
1420
1459
  }
1421
1460
  })
1422
1461
  });
1423
- if (!f.ok)
1424
- throw new Error(`Server returned ${f.status}`);
1425
- const b = await f.json();
1426
- if (b.error)
1427
- throw new Error(b.error.message);
1428
- const H = (_ = (C = (I = b.result) == null ? void 0 : I.content) == null ? void 0 : C[0]) == null ? void 0 : _.text;
1429
- if (y = JSON.parse(H), !y.success)
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)
1430
1469
  throw new Error(y.error);
1431
1470
  g.succeed("Upload URL obtained");
1432
- } catch (f) {
1433
- g.fail("Failed to get upload URL"), console.error(" ", f.message), process.exit(1);
1471
+ } catch (h) {
1472
+ g.fail("Failed to get upload URL"), console.error(" ", h.message), process.exit(1);
1434
1473
  }
1435
- g = A("Uploading component...").start();
1474
+ g = F("Uploading component...").start();
1436
1475
  try {
1437
- const f = n.readFileSync(p, "utf-8");
1438
- let b;
1439
- const H = y.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
1440
- if (H)
1441
- 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];
1442
1481
  else {
1443
- const F = y.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
1444
- if (F)
1445
- b = F[1];
1482
+ const b = y.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
1483
+ if (b)
1484
+ M = b[1];
1446
1485
  else
1447
1486
  throw new Error("Could not parse presigned URL from: " + y.curlCommand);
1448
1487
  }
1449
- console.info("Uploading to:", b.substring(0, 100) + "...");
1450
- const $ = await fetch(b, {
1488
+ console.info("Uploading to:", M.substring(0, 100) + "...");
1489
+ const K = await fetch(M, {
1451
1490
  method: "PUT",
1452
1491
  headers: {
1453
1492
  "Content-Type": "text/html"
1454
1493
  },
1455
- body: f
1494
+ body: h
1456
1495
  });
1457
- if (!$.ok) {
1458
- const F = await $.text();
1459
- throw new Error(`Upload failed with status ${$.status}: ${F}`);
1496
+ if (!K.ok) {
1497
+ const b = await K.text();
1498
+ throw new Error(`Upload failed with status ${K.status}: ${b}`);
1460
1499
  }
1461
1500
  g.succeed("Component uploaded");
1462
- } catch (f) {
1463
- g.fail("Upload failed"), console.error(" ", f.message), f.cause && console.error(" Cause:", f.cause), process.exit(1);
1501
+ } catch (h) {
1502
+ g.fail("Upload failed"), console.error(" ", h.message), h.cause && console.error(" Cause:", h.cause), process.exit(1);
1464
1503
  }
1465
- g = A("Confirming upload...").start();
1504
+ g = F("Confirming upload...").start();
1466
1505
  let w;
1467
1506
  try {
1468
- const f = await fetch(`${j}/mcp`, {
1507
+ const h = await fetch(`${x}/mcp`, {
1469
1508
  method: "POST",
1470
1509
  headers: {
1471
1510
  "Content-Type": "application/json",
1472
- Authorization: `Bearer ${v.accessToken}`
1511
+ Authorization: `Bearer ${S.accessToken}`
1473
1512
  },
1474
1513
  body: JSON.stringify({
1475
1514
  jsonrpc: "2.0",
@@ -1483,45 +1522,45 @@ l.program.command("sync").description("Build and upload component to Myop platfo
1483
1522
  }
1484
1523
  })
1485
1524
  });
1486
- if (!f.ok)
1487
- throw new Error(`Server returned ${f.status}`);
1488
- const b = await f.json();
1489
- if (b.error)
1490
- throw new Error(b.error.message);
1491
- const H = (P = (S = (B = b.result) == null ? void 0 : B.content) == null ? void 0 : S[0]) == null ? void 0 : P.text;
1492
- if (w = JSON.parse(H), !w.success)
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)
1493
1532
  throw new Error(w.error);
1494
1533
  g.succeed("Upload confirmed");
1495
- } catch (f) {
1496
- g.fail("Confirmation failed"), console.error(" ", f.message), process.exit(1);
1534
+ } catch (h) {
1535
+ g.fail("Confirmation failed"), console.error(" ", h.message), process.exit(1);
1497
1536
  }
1498
1537
  if (w.isNewComponent || !c.componentId) {
1499
1538
  c.componentId = w.componentId, c.organization = w.orgId, c.name || (c.name = w.componentName);
1500
1539
  try {
1501
1540
  n.writeFileSync(o, JSON.stringify(c, null, 2)), console.log(`
1502
1541
  πŸ“ Updated ${o} with componentId`);
1503
- } catch (f) {
1542
+ } catch (h) {
1504
1543
  console.log(`
1505
- ⚠️ Could not update ${o}: ${f.message}`), console.log(` Please add componentId: "${w.componentId}" manually`);
1544
+ ⚠️ Could not update ${o}: ${h.message}`), console.log(` Please add componentId: "${w.componentId}" manually`);
1506
1545
  }
1507
1546
  }
1508
1547
  console.log(`
1509
1548
  βœ… Sync completed successfully!`), console.log(` Component: ${w.componentName}`), console.log(` Dashboard: ${w.dashboardUrl}`), process.exit(0);
1510
1549
  });
1511
- l.program.command("dev").description("Start development server with file watching").action(Pe);
1512
- const St = () => {
1550
+ d.program.command("dev").description("Start development server with file watching").action(Ne);
1551
+ const bt = () => {
1513
1552
  try {
1514
- ne("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1553
+ se("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1515
1554
  } catch {
1516
1555
  return { gitNotInstalled: !0 };
1517
1556
  }
1518
1557
  try {
1519
- 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"] });
1520
1559
  } catch {
1521
1560
  return { notARepo: !0 };
1522
1561
  }
1523
1562
  try {
1524
- 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", {
1525
1564
  encoding: "utf-8",
1526
1565
  stdio: ["pipe", "pipe", "pipe"]
1527
1566
  }).trim();
@@ -1541,13 +1580,13 @@ const St = () => {
1541
1580
  } catch {
1542
1581
  return null;
1543
1582
  }
1544
- }, U = async (e = !1, o = !1) => {
1545
- var y, w, I;
1546
- const n = Re(), a = !!(n != null && n.email), u = ((y = l.myopConfig) == null ? void 0 : y.name) || ((w = l.myopConfig) == null ? void 0 : w.componentName), c = (I = l.myopConfig) == null ? void 0 : I.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();
1547
1586
  console.log(`
1548
1587
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”`), console.log("β”‚ β”‚"), console.log("β”‚ Welcome to Myop CLI - Remote UI Made Easy β”‚"), console.log("β”‚ β”‚"), console.log(`β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1549
- `), 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"}`), 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("");
1550
- const j = [
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 = [
1551
1590
  {
1552
1591
  emoji: "πŸš€",
1553
1592
  label: "Initialize new component",
@@ -1569,14 +1608,14 @@ const St = () => {
1569
1608
  help: "Starts dev server with HMR for instant preview of changes",
1570
1609
  disabled: e ? !1 : "(no config file)"
1571
1610
  }
1572
- ].map((C) => ({
1573
- name: o && !C.disabled ? `${C.emoji} ${C.label}
1574
- ${C.help}` : `${C.emoji} ${C.label}`,
1575
- value: C.value,
1576
- disabled: C.disabled
1611
+ ].map(($) => ({
1612
+ name: o && !$.disabled ? `${$.emoji} ${$.label}
1613
+ ${$.help}` : `${$.emoji} ${$.label}`,
1614
+ value: $.value,
1615
+ disabled: $.disabled
1577
1616
  }));
1578
- switch (j.push(
1579
- new de(),
1617
+ switch (x.push(
1618
+ new me(),
1580
1619
  {
1581
1620
  name: o && a ? `πŸ”“ Logout (${n.email})
1582
1621
  Clears stored credentials from this machine` : o && !a ? `πŸ” Login to Myop
@@ -1587,55 +1626,55 @@ const St = () => {
1587
1626
  name: o ? "πŸ“– Hide help" : "πŸ“– Show help",
1588
1627
  value: "help"
1589
1628
  },
1590
- new de(),
1629
+ new me(),
1591
1630
  {
1592
1631
  name: "πŸ‘‹ Exit",
1593
1632
  value: "exit"
1594
1633
  }
1595
- ), await $e({
1634
+ ), await Oe({
1596
1635
  message: "What would you like to do?",
1597
- choices: j
1636
+ choices: x
1598
1637
  })) {
1599
1638
  case "init":
1600
- await bt();
1639
+ await Ct();
1601
1640
  break;
1602
1641
  case "sync":
1603
1642
  console.log(`
1604
1643
  Running sync...
1605
1644
  `);
1606
- const { execSync: C } = await import("child_process");
1645
+ const { execSync: $ } = await import("child_process");
1607
1646
  try {
1608
- C("node " + process.argv[1] + " sync", { stdio: "inherit" });
1647
+ $("node " + process.argv[1] + " sync", { stdio: "inherit" });
1609
1648
  } catch {
1610
1649
  }
1611
- await U(!0, o);
1650
+ await B(!0, o);
1612
1651
  break;
1613
1652
  case "dev":
1614
- await Pe();
1653
+ await Ne();
1615
1654
  break;
1616
1655
  case "login":
1617
1656
  try {
1618
1657
  await X(), console.log(`
1619
- `), await U(e, o);
1620
- } catch (_) {
1621
- 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);
1622
1661
  }
1623
1662
  break;
1624
1663
  case "logout":
1625
- await Fe(), console.log(`
1626
- `), await U(e, o);
1664
+ await Re(), console.log(`
1665
+ `), await B(e, o);
1627
1666
  break;
1628
1667
  case "help":
1629
- await U(e, !o);
1668
+ await B(e, !o);
1630
1669
  break;
1631
1670
  case "exit":
1632
1671
  process.exit(0);
1633
1672
  }
1634
- }, bt = async () => {
1673
+ }, Ct = async () => {
1635
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({
1636
1675
  message: "Component name:",
1637
1676
  default: u
1638
- }), p = await o({
1677
+ }), m = await o({
1639
1678
  message: "Component type:",
1640
1679
  choices: [
1641
1680
  { name: "πŸ“„ HTML", value: "html", description: "Plain HTML/JS/CSS component" },
@@ -1643,14 +1682,14 @@ Running sync...
1643
1682
  { name: "πŸ’š Vue", value: "vue", disabled: "(coming soon)" },
1644
1683
  { name: "πŸ…°οΈ Angular", value: "angular", disabled: "(coming soon)" }
1645
1684
  ]
1646
- }), v = {
1685
+ }), S = {
1647
1686
  name: c,
1648
- type: p,
1687
+ type: m,
1649
1688
  author: "@myop-cli"
1650
- }, j = l.program.getOptionValue("config") || "./myop.config.json";
1689
+ }, x = d.program.getOptionValue("config") || "./myop.config.json";
1651
1690
  try {
1652
- n.writeFileSync(j, JSON.stringify(v, null, 2)), console.log(`
1653
- βœ… Created ${j}`);
1691
+ n.writeFileSync(x, JSON.stringify(S, null, 2)), console.log(`
1692
+ βœ… Created ${x}`);
1654
1693
  const g = {
1655
1694
  name: c.toLowerCase().replace(/\s+/g, "-"),
1656
1695
  version: "1.0.0",
@@ -1761,7 +1800,7 @@ console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS
1761
1800
  </html>
1762
1801
  `;
1763
1802
  n.writeFileSync("index.html", w), console.log("βœ… Created index.html");
1764
- const I = `// ${c} - Entry Point
1803
+ const j = `// ${c} - Entry Point
1765
1804
  import { init } from './modules/app.js';
1766
1805
  import { setupMyopInterface } from './modules/myop.js';
1767
1806
 
@@ -1770,8 +1809,8 @@ document.addEventListener('DOMContentLoaded', () => {
1770
1809
  setupMyopInterface();
1771
1810
  });
1772
1811
  `;
1773
- n.writeFileSync("src/index.js", I), console.log("βœ… Created src/index.js");
1774
- const C = `// ${c} - Main Application Logic
1812
+ n.writeFileSync("src/index.js", j), console.log("βœ… Created src/index.js");
1813
+ const $ = `// ${c} - Main Application Logic
1775
1814
 
1776
1815
  export function init() {
1777
1816
  console.log('${c} loaded');
@@ -1779,7 +1818,7 @@ export function init() {
1779
1818
  // Your component logic here
1780
1819
  }
1781
1820
  `;
1782
- n.writeFileSync("src/modules/app.js", C), console.log("βœ… Created src/modules/app.js"), n.writeFileSync("src/modules/myop.js", `// Myop Interface - Communication with host app
1821
+ n.writeFileSync("src/modules/app.js", $), console.log("βœ… Created src/modules/app.js"), n.writeFileSync("src/modules/myop.js", `// Myop Interface - Communication with host app
1783
1822
 
1784
1823
  export function setupMyopInterface() {
1785
1824
  // Called when host app sends data to this component
@@ -1795,12 +1834,12 @@ export function setupMyopInterface() {
1795
1834
  };
1796
1835
  }
1797
1836
  `), console.log("βœ… Created src/modules/myop.js");
1798
- const B = `/* ${c} - Styles Entry Point */
1837
+ const z = `/* ${c} - Styles Entry Point */
1799
1838
  /* Add your CSS imports here - they will be auto-bundled */
1800
1839
  @import './main.css';
1801
1840
  `;
1802
- n.writeFileSync("src/styles/index.css", B), console.log("βœ… Created src/styles/index.css");
1803
- const S = `/* ${c} - Main Styles */
1841
+ n.writeFileSync("src/styles/index.css", z), console.log("βœ… Created src/styles/index.css");
1842
+ const v = `/* ${c} - Main Styles */
1804
1843
 
1805
1844
  * {
1806
1845
  box-sizing: border-box;
@@ -1829,23 +1868,49 @@ p {
1829
1868
  line-height: 1.5;
1830
1869
  }
1831
1870
  `;
1832
- n.writeFileSync("src/styles/main.css", S), 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(`
1833
1872
  πŸ“¦ Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
1834
- `), l.myopConfig = v, await U(!0);
1873
+ `), d.myopConfig = S, await B(!0);
1835
1874
  } catch (g) {
1836
1875
  console.error(`Failed to initialize component: ${g.message}`), process.exit(1);
1837
1876
  }
1838
1877
  };
1839
- l.program.command("default", { isDefault: !0 }).action(async () => {
1840
- l.program.getOptionValue("help") && (console.log(Ve), process.exit());
1841
- let o = A({
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 };
1882
+ try {
1883
+ if (c.existsSync(m)) {
1884
+ const w = c.readFileSync(m, "utf-8"), j = JSON.parse(w);
1885
+ g = {
1886
+ found: !0,
1887
+ path: m,
1888
+ name: j.name || j.componentName || null,
1889
+ componentId: j.componentId || null,
1890
+ organization: j.organization || null
1891
+ };
1892
+ }
1893
+ } catch (w) {
1894
+ g = { found: !1, error: w.message };
1895
+ }
1896
+ const y = {
1897
+ version: S,
1898
+ config: g,
1899
+ auth: {
1900
+ loggedIn: !!(x != null && x.email),
1901
+ email: (x == null ? void 0 : x.email) || null
1902
+ }
1903
+ };
1904
+ console.log(JSON.stringify(y, null, 2)), process.exit(0);
1905
+ }
1906
+ let n = F({
1842
1907
  text: "Loading Myop CLI...",
1843
1908
  color: "green"
1844
1909
  }).start();
1845
- const n = ie();
1846
- await vt(500), o.stop();
1847
- const a = l.program.version();
1848
- await wt(a), await U(n.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);
1849
1914
  });
1850
- l.program.parse(process.argv);
1851
- l.program.opts();
1915
+ d.program.parse(process.argv);
1916
+ d.program.opts();