@myop/cli 0.1.20 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/myop-cli.js CHANGED
@@ -1,16 +1,19 @@
1
1
  #!/usr/bin/env node
2
- import P from "ora";
3
- import { select as Ne, Separator as fe } from "@inquirer/prompts";
4
- import { Command as Ye, Option as le } from "commander";
5
- import { execSync as ie, spawn as Ke } from "child_process";
6
- import q from "path";
7
- import R from "fs";
8
- import he from "crypto";
9
- import Xe from "http";
10
- import { URL as ke, URLSearchParams as Ee } from "url";
11
- import Qe from "open";
12
- import Ze from "os";
13
- const qe = `
2
+ var rt = Object.defineProperty;
3
+ var at = (o, e, t) => e in o ? rt(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
4
+ var ue = (o, e, t) => at(o, typeof e != "symbol" ? e + "" : e, t);
5
+ import W from "ora";
6
+ import { select as Je, Separator as Re } from "@inquirer/prompts";
7
+ import { Command as lt, Option as le } from "commander";
8
+ import { execSync as fe, spawn as ct } from "child_process";
9
+ import ee from "path";
10
+ import H from "fs";
11
+ import Ie from "crypto";
12
+ import dt from "http";
13
+ import { URL as ze, URLSearchParams as We } from "url";
14
+ import pt from "open";
15
+ import mt from "os";
16
+ const ut = `
14
17
  Usage: myop [OPTIONS] COMMAND [ARGS]...
15
18
 
16
19
  A powerful command-line interface for managing your Myop projects.
@@ -44,7 +47,7 @@ Examples:
44
47
 
45
48
 
46
49
 
47
- `, d = {
50
+ `, h = {
48
51
  program: null,
49
52
  executionPath: "",
50
53
  options: {
@@ -52,89 +55,89 @@ Examples:
52
55
  verbose: !1
53
56
  },
54
57
  myopConfig: null
55
- }, Te = {
58
+ }, Ve = {
56
59
  name: "📥 Install Myop generated dependencies",
57
60
  value: "myopInstall",
58
61
  description: "Fetch and generates Myop dependencies. flows including components, refs and props.",
59
62
  action: async () => {
60
63
  console.info("installing... ");
61
- for (const e of d.myopConfig.flows) {
62
- const n = q.join(d.executionPath, "/node_modules/@myop/flow-types/");
63
- console.info(`Generate flow at ${n}`), console.info(`Generated flow at ${n}`);
64
+ for (const o of h.myopConfig.flows) {
65
+ const e = ee.join(h.executionPath, "/node_modules/@myop/flow-types/");
66
+ console.info(`Generate flow at ${e}`), console.info(`Generated flow at ${e}`);
64
67
  }
65
68
  process.exit();
66
69
  }
67
- }, et = (e) => {
68
- const n = q.join(d.executionPath, e);
69
- console.info(`reading config file from: ${n}`);
70
- const s = R.readFileSync(n, "utf8"), a = JSON.parse(s);
71
- return console.info("config file loaded, ", a), a;
72
- }, ye = (e, n) => {
73
- const s = q.join(d.executionPath, e);
74
- console.info(`writing config file to: ${s}`);
70
+ }, gt = (o) => {
71
+ const e = ee.join(h.executionPath, o);
72
+ console.info(`reading config file from: ${e}`);
73
+ const t = H.readFileSync(e, "utf8"), n = JSON.parse(t);
74
+ return console.info("config file loaded, ", n), n;
75
+ }, Oe = (o, e) => {
76
+ const t = ee.join(h.executionPath, o);
77
+ console.info(`writing config file to: ${t}`);
75
78
  try {
76
- const a = JSON.stringify(n, null, 2);
77
- R.writeFileSync(s, a), console.info(`config file updated ${a}`);
78
- } catch (a) {
79
- throw console.info(`error ${a} while writing to ${s}, JSON: ${n}`), console.log(`
80
- ⚠️ Failed write config file to ${s}, for more info use verbose flag`), a;
79
+ const n = JSON.stringify(e, null, 2);
80
+ H.writeFileSync(t, n), console.info(`config file updated ${n}`);
81
+ } catch (n) {
82
+ throw console.info(`error ${n} while writing to ${t}, JSON: ${e}`), console.log(`
83
+ ⚠️ Failed write config file to ${t}, for more info use verbose flag`), n;
81
84
  }
82
- }, Pe = {
85
+ }, Ge = {
83
86
  name: "🌟 Add flow definition to your project",
84
87
  value: "addFlow",
85
88
  description: "Adds flow to yours myop.config.json",
86
- _action: (e) => {
87
- d.myopConfig.flows.includes(e) || d.myopConfig.flows.push(e), ye(d.options.configPath, d.myopConfig);
89
+ _action: (o) => {
90
+ h.myopConfig.flows.includes(o) || h.myopConfig.flows.push(o), Oe(h.options.configPath, h.myopConfig);
88
91
  },
89
92
  action: async () => {
90
93
  }
91
- }, Re = {
94
+ }, Ye = {
92
95
  name: "🚫 Remove flow definition from your project",
93
96
  value: "removeFlow",
94
97
  description: "Removes flow to yours myop.config.json",
95
- _action: (e) => {
96
- d.myopConfig.flows = d.myopConfig.flows.filter((n) => n !== e), ye(d.options.configPath, d.myopConfig);
98
+ _action: (o) => {
99
+ h.myopConfig.flows = h.myopConfig.flows.filter((e) => e !== o), Oe(h.options.configPath, h.myopConfig);
97
100
  },
98
101
  action: () => {
99
102
  }
100
- }, tt = {
103
+ }, ft = {
101
104
  name: "👋 Quit",
102
105
  value: "quit",
103
106
  description: "Quit and continue coding.",
104
107
  action: () => {
105
108
  process.exit();
106
109
  }
107
- }, ot = {
110
+ }, ht = {
108
111
  name: "🟢 Create new component",
109
112
  value: "-",
110
113
  disabled: "(not available yet)"
111
- }, nt = {
114
+ }, yt = {
112
115
  name: "🔵 Create new experience",
113
116
  value: "-",
114
117
  disabled: "(not available yet)"
115
- }, st = {
118
+ }, wt = {
116
119
  name: "🟡 Create new skin",
117
120
  value: "-",
118
121
  disabled: "(not available yet)"
119
- }, rt = {
122
+ }, vt = {
120
123
  name: "🔴 Create new flow",
121
124
  value: "-",
122
125
  disabled: "(not available yet)"
123
- }, it = {
126
+ }, bt = {
124
127
  name: "🆕 Define new custom Myop message",
125
128
  value: "generateMyopMessage",
126
129
  description: "️Help you creates the right structure for a new Myop message, including types and handlers.",
127
130
  disabled: "(not available yet)"
128
- }, at = [it, ot, nt, st, rt];
129
- function ct(e, n, s, a) {
131
+ }, St = [bt, ht, yt, wt, vt];
132
+ function xt(o, e, t, n) {
130
133
  return `<!DOCTYPE html>
131
134
  <html lang="en">
132
135
  <head>
133
136
  <meta charset="UTF-8">
134
137
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
135
- <title>Myop DevTools - localhost:${e}</title>
138
+ <title>Myop DevTools - localhost:${o}</title>
136
139
  <style>
137
- ${s}
140
+ ${t}
138
141
  </style>
139
142
  </head>
140
143
  <body>
@@ -142,8 +145,8 @@ ${s}
142
145
  <div class="toolbar">
143
146
  <div class="toolbar-title">Myop DevTools</div>
144
147
  <div class="toolbar-info">
145
- <span><div class="status-dot"></div> localhost:${e}</span>
146
- <span>Management: ${n}</span>
148
+ <span><div class="status-dot"></div> localhost:${o}</span>
149
+ <span>Management: ${e}</span>
147
150
  </div>
148
151
  </div>
149
152
 
@@ -209,74 +212,144 @@ ${s}
209
212
 
210
213
  <script>
211
214
  // Inject PORT as a global variable for the app to use
212
- window.PORT = ${e};
215
+ window.PORT = ${o};
213
216
 
214
- ${a}
217
+ ${n}
215
218
  <\/script>
216
219
  </body>
217
220
  </html>`;
218
221
  }
222
+ function $t(o) {
223
+ return o.includes("esbuild") && o.includes("another platform");
224
+ }
225
+ function Ct(o) {
226
+ return o.includes("ERR_MODULE_NOT_FOUND") && o.includes("esbuild");
227
+ }
228
+ function Mt() {
229
+ console.error(`
230
+ ❌ esbuild platform mismatch detected!`), console.error(" Your node_modules contains esbuild binaries for a different OS."), console.error(`
231
+ This usually happens when node_modules is copied between different`), console.error(` operating systems (e.g., Windows → Mac, or Mac → Linux).
232
+ `);
233
+ }
234
+ function Pt(o) {
235
+ return new Promise((e) => {
236
+ console.log(`🔧 Attempting to fix: removing node_modules and reinstalling...
237
+ `);
238
+ const n = process.platform === "win32" ? "rmdir /s /q node_modules" : "rm -rf node_modules";
239
+ o(n, (i) => {
240
+ if (i) {
241
+ console.error("❌ Failed to remove node_modules:", i.message), console.error(`
242
+ Please run manually:`), console.error(` \x1B[36m${n} && npm install\x1B[0m
243
+ `), e(!1);
244
+ return;
245
+ }
246
+ console.log(" ✓ Removed node_modules"), console.log(` ⏳ Running npm install...
247
+ `), o("npm install", { maxBuffer: 10 * 1024 * 1024 }, (s, d, w) => {
248
+ if (s) {
249
+ console.error("❌ npm install failed:", s.message), w && console.error(w), e(!1);
250
+ return;
251
+ }
252
+ console.log(` ✓ Dependencies reinstalled successfully!
253
+ `), e(!0);
254
+ });
255
+ });
256
+ });
257
+ }
258
+ async function Ke(o, e, t, n, i = {}) {
259
+ const {
260
+ hasTriedPlatformFix: s = !1,
261
+ hasTriedInstall: d = !1,
262
+ onRetry: w
263
+ } = i, M = ((o == null ? void 0 : o.message) || "") + (e || "") + (t || "");
264
+ return !s && $t(M) ? (Mt(), await Pt(n) && w ? (console.log(`🔄 Retrying build...
265
+ `), w(), { handled: !0, hasTriedPlatformFix: !0, hasTriedInstall: d }) : { handled: !0, hasTriedPlatformFix: !0, hasTriedInstall: d }) : !d && Ct(M) ? (console.log("📦 Missing dependencies detected, running npm install..."), new Promise((m) => {
266
+ n("npm install", (p, b, u) => {
267
+ if (p) {
268
+ console.error("❌ Failed to install dependencies:", p.message), u && console.error(u), m({ handled: !0, hasTriedPlatformFix: s, hasTriedInstall: !0 });
269
+ return;
270
+ }
271
+ console.log("✅ Dependencies installed"), w && w(), m({ handled: !0, hasTriedPlatformFix: s, hasTriedInstall: !0 });
272
+ });
273
+ })) : { handled: !1, hasTriedPlatformFix: s, hasTriedInstall: d };
274
+ }
219
275
  async function Fe() {
220
- const e = await import("fs"), n = await import("path"), { exec: s } = await import("child_process"), a = await import("http"), { createHash: f } = await import("node:crypto");
221
- let c;
276
+ const o = await import("fs"), e = await import("path"), { exec: t } = await import("child_process"), n = await import("http"), { createHash: i } = await import("node:crypto");
277
+ let s;
222
278
  if (import.meta.url.startsWith("file://")) {
223
- const t = new URL(import.meta.url).pathname, r = process.platform === "win32" && t.startsWith("/") ? t.slice(1) : t;
224
- c = n.default.dirname(r);
279
+ const a = new URL(import.meta.url).pathname, l = process.platform === "win32" && a.startsWith("/") ? a.slice(1) : a;
280
+ s = e.default.dirname(l);
225
281
  } else
226
- c = n.default.dirname(import.meta.url);
227
- const u = n.default.join(c, "commands", "dev", "management-website"), w = e.default.readFileSync(n.default.join(u, "styles.css"), "utf-8"), O = e.default.readFileSync(n.default.join(u, "app.js"), "utf-8"), m = 9292, y = 9293, b = "./dist";
228
- let I = !1, v = !1;
229
- const E = (o) => {
230
- const t = process.platform;
231
- let r;
232
- t === "darwin" ? r = `open "${o}"` : t === "win32" ? r = `start "" "${o}"` : r = `xdg-open "${o}"`, s(r, (i) => {
282
+ s = e.default.dirname(import.meta.url);
283
+ const d = e.default.join(s, "commands", "dev", "management-website"), w = o.default.readFileSync(e.default.join(d, "styles.css"), "utf-8"), M = o.default.readFileSync(e.default.join(d, "app.js"), "utf-8"), m = 9292, p = 9293;
284
+ let b = "./dist", u = !1, v = !1, x = !1, $ = null;
285
+ const _ = () => {
286
+ try {
287
+ const r = o.default.readdirSync(".").filter((a) => !a.endsWith(".html") || a.startsWith(".") ? !1 : o.default.statSync(a).isFile());
288
+ if (r.length === 1)
289
+ return r[0];
290
+ } catch {
291
+ }
292
+ return null;
293
+ }, D = () => {
294
+ try {
295
+ const r = JSON.parse(o.default.readFileSync("package.json", "utf-8"));
296
+ return !!(r.scripts && r.scripts.build);
297
+ } catch {
298
+ return !1;
299
+ }
300
+ }, g = (r) => {
301
+ const a = process.platform;
302
+ let l;
303
+ a === "darwin" ? l = `open "${r}"` : a === "win32" ? l = `start "" "${r}"` : l = `xdg-open "${r}"`, t(l, (c) => {
233
304
  });
234
- }, F = /* @__PURE__ */ new Map(), W = d.program.getOptionValue("config") || "./myop.config.json";
235
- let S, h, C = !1;
305
+ }, P = /* @__PURE__ */ new Map(), E = h.program.getOptionValue("config") || "./myop.config.json";
306
+ let C, I, L = !1;
307
+ $ = _();
308
+ const Z = D();
236
309
  try {
237
- const o = e.default.readFileSync(W, "utf-8"), t = JSON.parse(o);
238
- S = t.componentId || "DEV", h = t.componentName || t.name || null, C = t.HMR === !0, C && console.log("🔥 HMR enabled");
239
- } catch (o) {
240
- console.error("❌ Error reading myop.config.json:", o.message), process.exit(1);
310
+ const r = o.default.readFileSync(E, "utf-8"), a = JSON.parse(r);
311
+ C = a.componentId || "DEV", I = a.componentName || a.name || null, L = a.HMR === !0, $ && !Z && (x = !0, L = !0, console.log(`📄 Single HTML file mode: ${$}`)), L && console.log("🔥 HMR enabled");
312
+ } catch (r) {
313
+ $ && !Z ? (x = !0, C = "DEV", I = e.default.basename($, ".html"), L = !0, console.log(`📄 Single HTML file mode: ${$}`), console.log("🔥 HMR enabled")) : (console.error("❌ Error reading myop.config.json:", r.message), process.exit(1));
241
314
  }
242
- const A = async () => {
243
- if (S !== "DEV" && S !== "NEW")
244
- return S;
315
+ const U = async () => {
316
+ if (C !== "DEV" && C !== "NEW")
317
+ return C;
245
318
  try {
246
- const t = ((await new Promise((l, p) => {
247
- const g = {
319
+ const a = ((await new Promise((f, y) => {
320
+ const S = {
248
321
  hostname: "localhost",
249
- port: y,
322
+ port: p,
250
323
  path: "/_list",
251
324
  method: "GET",
252
325
  timeout: 1e3
253
- }, x = a.default.request(g, (N) => {
254
- let L = "";
255
- N.on("data", (J) => L += J), N.on("end", () => {
326
+ }, F = n.default.request(S, (N) => {
327
+ let J = "";
328
+ N.on("data", (Q) => J += Q), N.on("end", () => {
256
329
  try {
257
- l(JSON.parse(L));
330
+ f(JSON.parse(J));
258
331
  } catch {
259
- l({ components: [] });
332
+ f({ components: [] });
260
333
  }
261
334
  });
262
335
  });
263
- x.on("error", () => l({ components: [] })), x.on("timeout", () => {
264
- x.destroy(), l({ components: [] });
265
- }), x.end();
266
- })).components || []).map(([l]) => l).filter((l) => l === "DEV" || l === "NEW" || /^DEV\d+$/.test(l) || /^NEW\d+$/.test(l));
267
- if (t.length === 0)
336
+ F.on("error", () => f({ components: [] })), F.on("timeout", () => {
337
+ F.destroy(), f({ components: [] });
338
+ }), F.end();
339
+ })).components || []).map(([f]) => f).filter((f) => f === "DEV" || f === "NEW" || /^DEV\d+$/.test(f) || /^NEW\d+$/.test(f));
340
+ if (a.length === 0)
268
341
  return "DEV1";
269
- const r = t.map((l) => {
270
- if (l === "DEV" || l === "NEW") return 1;
271
- const p = l.match(/^DEV(\d+)$/), g = l.match(/^NEW(\d+)$/);
272
- return p ? parseInt(p[1], 10) : g ? parseInt(g[1], 10) : 0;
273
- }).filter((l) => l > 0);
274
- return `DEV${Math.max(...r, 0) + 1}`;
342
+ const l = a.map((f) => {
343
+ if (f === "DEV" || f === "NEW") return 1;
344
+ const y = f.match(/^DEV(\d+)$/), S = f.match(/^NEW(\d+)$/);
345
+ return y ? parseInt(y[1], 10) : S ? parseInt(S[1], 10) : 0;
346
+ }).filter((f) => f > 0);
347
+ return `DEV${Math.max(...l, 0) + 1}`;
275
348
  } catch {
276
349
  return "DEV1";
277
350
  }
278
- }, D = process.cwd(), V = (o) => {
279
- const t = n.default.extname(o).toLowerCase();
351
+ }, O = process.cwd(), V = (r) => {
352
+ const a = e.default.extname(r).toLowerCase();
280
353
  return {
281
354
  ".html": "text/html",
282
355
  ".js": "text/javascript",
@@ -287,305 +360,306 @@ async function Fe() {
287
360
  ".gif": "image/gif",
288
361
  ".svg": "image/svg+xml",
289
362
  ".ico": "image/x-icon"
290
- }[t] || "application/octet-stream";
291
- }, j = /* @__PURE__ */ new Map(), ee = [], Le = 50, H = [], G = /* @__PURE__ */ new Map(), B = /* @__PURE__ */ new Map(), Je = (o, t, r) => {
292
- if (o.url.startsWith("/_hmr/")) {
293
- const i = o.url.split("/_hmr/")[1], l = o.headers["sec-websocket-key"], p = f("sha1").update(l + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
294
- t.write(
363
+ }[a] || "application/octet-stream";
364
+ }, R = /* @__PURE__ */ new Map(), G = [], Se = 50, K = [], te = /* @__PURE__ */ new Map(), X = /* @__PURE__ */ new Map(), et = (r, a, l) => {
365
+ if (r.url.startsWith("/_hmr/")) {
366
+ const c = r.url.split("/_hmr/")[1], f = r.headers["sec-websocket-key"], y = i("sha1").update(f + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
367
+ a.write(
295
368
  `HTTP/1.1 101 Switching Protocols\r
296
369
  Upgrade: websocket\r
297
370
  Connection: Upgrade\r
298
- Sec-WebSocket-Accept: ${p}\r
371
+ Sec-WebSocket-Accept: ${y}\r
299
372
  \r
300
373
  `
301
- ), B.has(i) || B.set(i, /* @__PURE__ */ new Set()), B.get(i).add(t), console.log(`🔌 HMR client connected: ${i}`), t.on("close", () => {
302
- const g = B.get(i);
303
- g && (g.delete(t), g.size === 0 && B.delete(i)), console.log(`🔌 HMR client disconnected: ${i}`);
304
- }), t.on("error", () => {
305
- const g = B.get(i);
306
- g && g.delete(t);
374
+ ), X.has(c) || X.set(c, /* @__PURE__ */ new Set()), X.get(c).add(a), console.log(`🔌 HMR client connected: ${c}`), a.on("close", () => {
375
+ const S = X.get(c);
376
+ S && (S.delete(a), S.size === 0 && X.delete(c)), console.log(`🔌 HMR client disconnected: ${c}`);
377
+ }), a.on("error", () => {
378
+ const S = X.get(c);
379
+ S && S.delete(a);
307
380
  });
308
381
  }
309
- }, pe = a.default.createServer((o, t) => {
310
- if (t.setHeader("Content-Type", "application/json"), o.method === "POST" && o.url === "/_register") {
311
- let r = "";
312
- o.on("data", (i) => r += i), o.on("end", () => {
382
+ }, xe = n.default.createServer((r, a) => {
383
+ if (a.setHeader("Content-Type", "application/json"), r.method === "POST" && r.url === "/_register") {
384
+ let l = "";
385
+ r.on("data", (c) => l += c), r.on("end", () => {
313
386
  try {
314
- const { componentId: i, distPath: l, componentName: p } = JSON.parse(r);
315
- j.set(i, { path: l, name: p || null });
316
- const g = p ? ` (${p})` : "";
317
- console.log(`✅ Registered: ${i}${g} -> ${l}`), t.writeHead(200), t.end(JSON.stringify({ success: !0, registered: Array.from(j.keys()) }));
318
- const x = Array.from(j.entries()).map(([N, L]) => ({
319
- id: N,
320
- path: L.path,
321
- name: L.name
387
+ const { componentId: c, distPath: f, componentName: y, htmlFile: S } = JSON.parse(l);
388
+ R.set(c, { path: f, name: y || null, htmlFile: S || null });
389
+ const F = y ? ` (${y})` : "";
390
+ console.log(`✅ Registered: ${c}${F} -> ${f}${S ? "/" + S : ""}`), a.writeHead(200), a.end(JSON.stringify({ success: !0, registered: Array.from(R.keys()) }));
391
+ const N = Array.from(R.entries()).map(([J, Q]) => ({
392
+ id: J,
393
+ path: Q.path,
394
+ name: Q.name
322
395
  }));
323
- H.forEach((N) => {
396
+ K.forEach((J) => {
324
397
  try {
325
- N.write(`data: ${JSON.stringify({
398
+ J.write(`data: ${JSON.stringify({
326
399
  type: "components",
327
- components: x
400
+ components: N
328
401
  })}
329
402
 
330
403
  `);
331
404
  } catch {
332
405
  }
333
406
  });
334
- } catch (i) {
335
- t.writeHead(400), t.end(JSON.stringify({ error: i.message }));
407
+ } catch (c) {
408
+ a.writeHead(400), a.end(JSON.stringify({ error: c.message }));
336
409
  }
337
410
  });
338
- } else if (o.method === "POST" && o.url === "/_unregister") {
339
- let r = "";
340
- o.on("data", (i) => r += i), o.on("end", () => {
411
+ } else if (r.method === "POST" && r.url === "/_unregister") {
412
+ let l = "";
413
+ r.on("data", (c) => l += c), r.on("end", () => {
341
414
  try {
342
- const { componentId: i } = JSON.parse(r);
343
- j.delete(i), console.log(`❌ Unregistered: ${i}`), t.writeHead(200), t.end(JSON.stringify({ success: !0 }));
344
- const l = Array.from(j.entries()).map(([p, g]) => ({
345
- id: p,
346
- path: g.path,
347
- name: g.name
415
+ const { componentId: c } = JSON.parse(l);
416
+ R.delete(c), console.log(`❌ Unregistered: ${c}`), a.writeHead(200), a.end(JSON.stringify({ success: !0 }));
417
+ const f = Array.from(R.entries()).map(([y, S]) => ({
418
+ id: y,
419
+ path: S.path,
420
+ name: S.name
348
421
  }));
349
- H.forEach((p) => {
422
+ K.forEach((y) => {
350
423
  try {
351
- p.write(`data: ${JSON.stringify({
424
+ y.write(`data: ${JSON.stringify({
352
425
  type: "components",
353
- components: l
426
+ components: f
354
427
  })}
355
428
 
356
429
  `);
357
430
  } catch {
358
431
  }
359
432
  });
360
- } catch (i) {
361
- t.writeHead(400), t.end(JSON.stringify({ error: i.message }));
433
+ } catch (c) {
434
+ a.writeHead(400), a.end(JSON.stringify({ error: c.message }));
362
435
  }
363
436
  });
364
- } else o.method === "GET" && o.url === "/_list" ? (t.writeHead(200), t.end(JSON.stringify({ components: Array.from(j.entries()) }))) : (t.writeHead(404), t.end(JSON.stringify({ error: "Not found" })));
365
- }), te = a.default.createServer((o, t) => {
366
- if (o.url.includes("..")) {
367
- t.writeHead(403, { "Content-Type": "text/plain" }), t.end("Forbidden");
437
+ } else r.method === "GET" && r.url === "/_list" ? (a.writeHead(200), a.end(JSON.stringify({ components: Array.from(R.entries()) }))) : (a.writeHead(404), a.end(JSON.stringify({ error: "Not found" })));
438
+ }), ce = n.default.createServer((r, a) => {
439
+ if (r.url.includes("..")) {
440
+ a.writeHead(403, { "Content-Type": "text/plain" }), a.end("Forbidden");
368
441
  return;
369
442
  }
370
- const r = new URL(o.url, `http://localhost:${m}`), i = r.pathname, l = i.split("/").filter((_) => _);
371
- if (i.startsWith("/consume")) {
372
- const _ = r.searchParams.get("id");
373
- if (!_) {
374
- t.writeHead(400, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Component ID required. Use /consume?id=<componentId>" }));
443
+ const l = new URL(r.url, `http://localhost:${m}`), c = l.pathname, f = c.split("/").filter((A) => A);
444
+ if (c.startsWith("/consume")) {
445
+ const A = l.searchParams.get("id");
446
+ if (!A) {
447
+ a.writeHead(400, { "Content-Type": "application/json" }), a.end(JSON.stringify({ error: "Component ID required. Use /consume?id=<componentId>" }));
375
448
  return;
376
449
  }
377
- const T = j.get(_), U = T ? T.path : null, _e = (Y) => {
378
- let $ = "Unknown", k = "Unknown";
379
- if (o.headers.referer || o.headers.referrer) {
380
- const M = o.headers.referer || o.headers.referrer;
450
+ const B = R.get(A), Y = B ? B.path : null, Be = (oe) => {
451
+ let j = "Unknown", z = "Unknown";
452
+ if (r.headers.referer || r.headers.referrer) {
453
+ const k = r.headers.referer || r.headers.referrer;
381
454
  try {
382
- const K = new URL(M);
383
- $ = K.origin, k = K.hostname || K.origin;
455
+ const ne = new URL(k);
456
+ j = ne.origin, z = ne.hostname || ne.origin;
384
457
  } catch {
385
- $ = M, k = M;
458
+ j = k, z = k;
386
459
  }
387
- } else if (o.headers.origin)
460
+ } else if (r.headers.origin)
388
461
  try {
389
- const M = new URL(o.headers.origin);
390
- $ = M.origin, k = M.hostname || M.origin;
462
+ const k = new URL(r.headers.origin);
463
+ j = k.origin, z = k.hostname || k.origin;
391
464
  } catch {
392
- $ = o.headers.origin, k = o.headers.origin;
465
+ j = r.headers.origin, z = r.headers.origin;
393
466
  }
394
- else if (o.socket.remoteAddress) {
395
- const M = o.socket.remoteAddress;
396
- M === "::1" || M === "::ffff:127.0.0.1" ? ($ = "localhost", k = "localhost (direct)") : ($ = M, k = M.replace("::ffff:", ""));
467
+ else if (r.socket.remoteAddress) {
468
+ const k = r.socket.remoteAddress;
469
+ k === "::1" || k === "::ffff:127.0.0.1" ? (j = "localhost", z = "localhost (direct)") : (j = k, z = k.replace("::ffff:", ""));
397
470
  }
398
- const me = o.headers.referer || o.headers.referrer || $, se = {
471
+ const Me = r.headers.referer || r.headers.referrer || j, me = {
399
472
  type: "request",
400
- componentId: _,
473
+ componentId: A,
401
474
  timestamp: Date.now(),
402
- servedLocally: Y,
403
- referrer: me,
404
- origin: $,
405
- originLabel: k
475
+ servedLocally: oe,
476
+ referrer: Me,
477
+ origin: j,
478
+ originLabel: z
406
479
  };
407
- G.has($) || (G.set($, {
408
- url: $,
409
- label: k,
480
+ te.has(j) || (te.set(j, {
481
+ url: j,
482
+ label: z,
410
483
  firstSeen: Date.now(),
411
484
  requestCount: 0
412
- }), H.forEach((M) => {
485
+ }), K.forEach((k) => {
413
486
  try {
414
- M.write(`data: ${JSON.stringify({
487
+ k.write(`data: ${JSON.stringify({
415
488
  type: "origins",
416
- origins: Array.from(G.values())
489
+ origins: Array.from(te.values())
417
490
  })}
418
491
 
419
492
  `);
420
493
  } catch {
421
494
  }
422
495
  }));
423
- const ue = G.get($);
424
- ue.requestCount++, H.forEach((M) => {
496
+ const Pe = te.get(j);
497
+ Pe.requestCount++, K.forEach((k) => {
425
498
  try {
426
- M.write(`data: ${JSON.stringify({
499
+ k.write(`data: ${JSON.stringify({
427
500
  type: "origins",
428
- origins: Array.from(G.values())
501
+ origins: Array.from(te.values())
429
502
  })}
430
503
 
431
504
  `);
432
505
  } catch {
433
506
  }
434
- }), ee.push(se), ee.length > Le && ee.shift(), H.forEach((M) => {
507
+ }), G.push(me), G.length > Se && G.shift(), K.forEach((k) => {
435
508
  try {
436
- M.write(`data: ${JSON.stringify(se)}
509
+ k.write(`data: ${JSON.stringify(me)}
437
510
 
438
511
  `);
439
512
  } catch {
440
513
  }
441
514
  });
442
515
  };
443
- if (U) {
444
- const Y = n.default.join(U, "index.html");
445
- e.default.readFile(Y, "utf-8", ($, k) => {
446
- if ($) {
447
- console.log(`❌ File not found: ${Y}`), t.writeHead(404, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "index.html not found" }));
516
+ if (Y) {
517
+ const oe = B.htmlFile ? e.default.join(Y, B.htmlFile) : e.default.join(Y, "index.html");
518
+ o.default.readFile(oe, "utf-8", (j, z) => {
519
+ if (j) {
520
+ console.log(`❌ File not found: ${oe}`), a.writeHead(404, { "Content-Type": "application/json" }), a.end(JSON.stringify({ error: "index.html not found" }));
448
521
  return;
449
522
  }
450
- const me = xe(k, _), se = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, ue = {
523
+ const Me = _e(z, A), me = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, Pe = {
451
524
  item: {
452
- name: _,
453
- id: _,
525
+ name: A,
526
+ id: A,
454
527
  consume_variant: [
455
528
  {
456
- id: se,
529
+ id: me,
457
530
  name: "dev version",
458
531
  loader: {
459
532
  type: "HTMLLoader",
460
533
  shadowRootMode: "localFrame",
461
- HTML: me
534
+ HTML: Me
462
535
  }
463
536
  }
464
537
  ]
465
538
  }
466
539
  };
467
- console.log(`✅ Serving consume JSON for: ${_}`), _e(!0), t.writeHead(200, {
540
+ console.log(`✅ Serving consume JSON for: ${A}`), Be(!0), a.writeHead(200, {
468
541
  "Content-Type": "application/json",
469
542
  "Access-Control-Allow-Origin": "*"
470
- }), t.end(JSON.stringify(ue, null, 2));
543
+ }), a.end(JSON.stringify(Pe, null, 2));
471
544
  });
472
545
  } else {
473
- console.log(`📡 Proxying consume request to cloud.myop.dev for: ${_}`);
474
- const Y = `https://cloud.myop.dev/consume${r.search}`;
475
- _e(!1), fetch(Y).then(($) => $.text()).then(($) => {
476
- t.writeHead(200, {
546
+ console.log(`📡 Proxying consume request to cloud.myop.dev for: ${A}`);
547
+ const oe = `https://cloud.myop.dev/consume${l.search}`;
548
+ Be(!1), fetch(oe).then((j) => j.text()).then((j) => {
549
+ a.writeHead(200, {
477
550
  "Content-Type": "application/json",
478
551
  "Access-Control-Allow-Origin": "*"
479
- }), t.end($);
480
- }).catch(($) => {
481
- console.error(`❌ Proxy error: ${$.message}`), t.writeHead(502, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Failed to fetch from cloud.myop.dev" }));
552
+ }), a.end(j);
553
+ }).catch((j) => {
554
+ console.error(`❌ Proxy error: ${j.message}`), a.writeHead(502, { "Content-Type": "application/json" }), a.end(JSON.stringify({ error: "Failed to fetch from cloud.myop.dev" }));
482
555
  });
483
556
  }
484
557
  return;
485
558
  }
486
- if (i === "/events") {
487
- t.writeHead(200, {
559
+ if (c === "/events") {
560
+ a.writeHead(200, {
488
561
  "Content-Type": "text/event-stream",
489
562
  "Cache-Control": "no-cache",
490
563
  Connection: "keep-alive",
491
564
  "Access-Control-Allow-Origin": "*"
492
- }), H.push(t);
493
- const _ = Array.from(j.entries()).map(([T, U]) => ({
494
- id: T,
495
- path: U.path,
496
- name: U.name
565
+ }), K.push(a);
566
+ const A = Array.from(R.entries()).map(([B, Y]) => ({
567
+ id: B,
568
+ path: Y.path,
569
+ name: Y.name
497
570
  }));
498
- t.write(`data: ${JSON.stringify({
571
+ a.write(`data: ${JSON.stringify({
499
572
  type: "components",
500
- components: _
573
+ components: A
501
574
  })}
502
575
 
503
- `), t.write(`data: ${JSON.stringify({
576
+ `), a.write(`data: ${JSON.stringify({
504
577
  type: "origins",
505
- origins: Array.from(G.values())
578
+ origins: Array.from(te.values())
506
579
  })}
507
580
 
508
- `), t.write(`data: ${JSON.stringify({
581
+ `), a.write(`data: ${JSON.stringify({
509
582
  type: "requestLog",
510
- log: ee
583
+ log: G
511
584
  })}
512
585
 
513
- `), o.on("close", () => {
514
- const T = H.indexOf(t);
515
- T !== -1 && H.splice(T, 1);
586
+ `), r.on("close", () => {
587
+ const B = K.indexOf(a);
588
+ B !== -1 && K.splice(B, 1);
516
589
  });
517
590
  return;
518
591
  }
519
- if (l.length === 0) {
520
- t.writeHead(200, { "Content-Type": "text/html" }), t.end(ct(m, y, w, O));
592
+ if (f.length === 0) {
593
+ a.writeHead(200, { "Content-Type": "text/html" }), a.end(xt(m, p, w, M));
521
594
  return;
522
595
  }
523
- if (l[0] !== "view") {
524
- t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Not found. Use /view/<componentId>/ to access components.");
596
+ if (f[0] !== "view") {
597
+ a.writeHead(404, { "Content-Type": "text/plain" }), a.end("Not found. Use /view/<componentId>/ to access components.");
525
598
  return;
526
599
  }
527
- if (l.length < 2) {
528
- t.writeHead(400, { "Content-Type": "text/plain" }), t.end("Component ID required. Use /view/<componentId>/");
600
+ if (f.length < 2) {
601
+ a.writeHead(400, { "Content-Type": "text/plain" }), a.end("Component ID required. Use /view/<componentId>/");
529
602
  return;
530
603
  }
531
- const p = l[1], g = j.get(p);
532
- if (!g) {
533
- t.writeHead(404, { "Content-Type": "text/plain" }), t.end(`Component not found: ${p}`);
604
+ const y = f[1], S = R.get(y);
605
+ if (!S) {
606
+ a.writeHead(404, { "Content-Type": "text/plain" }), a.end(`Component not found: ${y}`);
534
607
  return;
535
608
  }
536
- const x = g.path, N = l.slice(2), L = N.length === 0 ? "index.html" : N.join("/"), J = n.default.join(x, L);
537
- console.log(`📥 Request: ${o.url} -> ${J}`), e.default.readFile(J, (_, T) => {
538
- if (_) {
539
- console.log(`❌ File not found: ${J}`), t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Not Found");
609
+ const F = S.path, N = f.slice(2), J = S.htmlFile || "index.html", Q = N.length === 0 ? J : N.join("/"), ie = e.default.join(F, Q);
610
+ console.log(`📥 Request: ${r.url} -> ${ie}`), o.default.readFile(ie, (A, B) => {
611
+ if (A) {
612
+ console.log(`❌ File not found: ${ie}`), a.writeHead(404, { "Content-Type": "text/plain" }), a.end("Not Found");
540
613
  return;
541
614
  }
542
- const U = V(J);
543
- console.log(`✅ Serving: ${J} (${U})`), t.writeHead(200, {
544
- "Content-Type": U,
615
+ const Y = V(ie);
616
+ console.log(`✅ Serving: ${ie} (${Y})`), a.writeHead(200, {
617
+ "Content-Type": Y,
545
618
  "Access-Control-Allow-Origin": "*"
546
- }), t.end(T);
619
+ }), a.end(B);
547
620
  });
548
- }), be = () => new Promise((o, t) => {
549
- const r = JSON.stringify({
550
- componentId: S,
551
- distPath: n.default.resolve(D, b),
552
- componentName: h
553
- }), i = {
621
+ }), Ne = () => new Promise((r, a) => {
622
+ const l = x ? e.default.resolve(O) : e.default.resolve(O, b), c = JSON.stringify({
623
+ componentId: C,
624
+ distPath: l,
625
+ componentName: I,
626
+ htmlFile: x ? $ : null
627
+ }), f = {
554
628
  hostname: "localhost",
555
- port: y,
629
+ port: p,
556
630
  path: "/_register",
557
631
  method: "POST",
558
632
  headers: {
559
633
  "Content-Type": "application/json",
560
- "Content-Length": Buffer.byteLength(r)
634
+ "Content-Length": Buffer.byteLength(c)
561
635
  }
562
- }, l = a.default.request(i, (p) => {
563
- let g = "";
564
- p.on("data", (x) => g += x), p.on("end", () => {
565
- p.statusCode === 200 ? o(JSON.parse(g)) : t(new Error(`Registration failed: ${p.statusCode}`));
636
+ }, y = n.default.request(f, (S) => {
637
+ let F = "";
638
+ S.on("data", (N) => F += N), S.on("end", () => {
639
+ S.statusCode === 200 ? r(JSON.parse(F)) : a(new Error(`Registration failed: ${S.statusCode}`));
566
640
  });
567
641
  });
568
- l.on("error", t), l.write(r), l.end();
569
- }), Ue = () => new Promise((o, t) => {
570
- const r = JSON.stringify({ componentId: S }), i = {
642
+ y.on("error", a), y.write(c), y.end();
643
+ }), tt = () => new Promise((r, a) => {
644
+ const l = JSON.stringify({ componentId: C }), c = {
571
645
  hostname: "localhost",
572
- port: y,
646
+ port: p,
573
647
  path: "/_unregister",
574
648
  method: "POST",
575
649
  headers: {
576
650
  "Content-Type": "application/json",
577
- "Content-Length": Buffer.byteLength(r)
651
+ "Content-Length": Buffer.byteLength(l)
578
652
  }
579
- }, l = a.default.request(i, (p) => {
580
- o();
653
+ }, f = n.default.request(c, (y) => {
654
+ r();
581
655
  });
582
- l.on("error", () => o()), l.write(r), l.end();
583
- }), Be = (o) => `
656
+ f.on("error", () => r()), f.write(l), f.end();
657
+ }), ot = (r) => `
584
658
  <!-- MYOP HMR -->
585
659
  <script>
586
660
  (function() {
587
- const componentId = '${o}';
588
- const wsUrl = 'ws://localhost:${y}/_hmr/' + componentId;
661
+ const componentId = '${r}';
662
+ const wsUrl = 'ws://localhost:${p}/_hmr/' + componentId;
589
663
  let ws;
590
664
  let reconnectAttempts = 0;
591
665
  const maxReconnectAttempts = 10;
@@ -685,281 +759,536 @@ Sec-WebSocket-Accept: ${p}\r
685
759
  connect();
686
760
  })();
687
761
  <\/script>
688
- `, xe = (o, t) => {
689
- if (!C) return o;
690
- const r = Be(t);
691
- return o.includes("</body>") ? o.replace("</body>", `${r}</body>`) : o.includes("</html>") ? o.replace("</html>", `${r}</html>`) : o + r;
692
- }, ze = (o) => {
693
- const t = Buffer.from(o), r = t.length;
694
- let i;
695
- return r < 126 ? i = Buffer.concat([
696
- Buffer.from([129, r]),
762
+ `, _e = (r, a) => {
763
+ if (!L) return r;
764
+ const l = ot(a);
765
+ return r.includes("</body>") ? r.replace("</body>", `${l}</body>`) : r.includes("</html>") ? r.replace("</html>", `${l}</html>`) : r + l;
766
+ }, nt = (r) => {
767
+ const a = Buffer.from(r), l = a.length;
768
+ let c;
769
+ return l < 126 ? c = Buffer.concat([
770
+ Buffer.from([129, l]),
697
771
  // FIN + text frame, length
698
- t
699
- ]) : r < 65536 ? i = Buffer.concat([
772
+ a
773
+ ]) : l < 65536 ? c = Buffer.concat([
700
774
  Buffer.from([129, 126]),
701
775
  // FIN + text frame, extended length
702
- Buffer.from([r >> 8, r & 255]),
776
+ Buffer.from([l >> 8, l & 255]),
703
777
  // 16-bit length
704
- t
705
- ]) : i = Buffer.concat([
778
+ a
779
+ ]) : c = Buffer.concat([
706
780
  Buffer.from([129, 127]),
707
781
  // FIN + text frame, extended length
708
- Buffer.from([0, 0, 0, 0, r >> 24, r >> 16 & 255, r >> 8 & 255, r & 255]),
782
+ Buffer.from([0, 0, 0, 0, l >> 24, l >> 16 & 255, l >> 8 & 255, l & 255]),
709
783
  // 64-bit length
710
- t
711
- ]), i;
712
- }, We = () => {
713
- if (!C) return;
714
- const o = B.get(S);
715
- if (!o || o.size === 0)
784
+ a
785
+ ]), c;
786
+ }, Le = () => {
787
+ if (!L) return;
788
+ const r = X.get(C);
789
+ if (!r || r.size === 0)
716
790
  return;
717
- console.log(`🔥 Notifying ${o.size} HMR client(s)`);
718
- const t = n.default.join(b, "index.html");
791
+ console.log(`🔥 Notifying ${r.size} HMR client(s)`);
792
+ const a = x ? $ : e.default.join(b, "index.html");
719
793
  try {
720
- const r = e.default.readFileSync(t, "utf-8"), i = xe(r, S), l = JSON.stringify({
794
+ const l = o.default.readFileSync(a, "utf-8"), c = _e(l, C), f = JSON.stringify({
721
795
  type: "update",
722
- html: i
723
- }), p = ze(l);
724
- o.forEach((g) => {
796
+ html: c
797
+ }), y = nt(f);
798
+ r.forEach((S) => {
725
799
  try {
726
- g.write(p);
800
+ S.write(y);
727
801
  } catch {
728
- o.delete(g);
802
+ r.delete(S);
729
803
  }
730
804
  });
731
- } catch (r) {
732
- console.error("❌ Failed to read HTML for HMR:", r.message);
805
+ } catch (l) {
806
+ console.error("❌ Failed to read HTML for HMR:", l.message);
733
807
  }
734
808
  };
735
- let Ce = !1;
736
- const oe = (o) => {
737
- if (I) {
809
+ let $e = { hasTriedPlatformFix: !1, hasTriedInstall: !1 };
810
+ const de = (r) => {
811
+ if (u) {
738
812
  v = !0;
739
813
  return;
740
814
  }
741
- I = !0, console.log(`
742
- 🔨 Building...`), s("npm run build", (t, r, i) => {
743
- if (I = !1, t) {
744
- const l = t.message + (i || "");
745
- if (!Ce && l.includes("ERR_MODULE_NOT_FOUND") && l.includes("esbuild")) {
746
- Ce = !0, console.log("📦 Missing dependencies detected, running npm install..."), s("npm install", (p, g, x) => {
747
- p ? (console.error("❌ Failed to install dependencies:", p.message), x && console.error(x)) : (console.log("✅ Dependencies installed"), oe(o));
748
- });
749
- return;
750
- }
751
- console.error("❌ Build failed:", t.message), i && console.error(i);
815
+ u = !0, console.log(`
816
+ 🔨 Building...`), t("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (a, l, c) => {
817
+ if (u = !1, a) {
818
+ const f = await Ke(a, l, c, t, {
819
+ ...$e,
820
+ onRetry: () => de(r)
821
+ });
822
+ $e = { ...$e, ...f }, f.handled || (console.error("❌ Build failed:", a.message), c && console.error(c));
752
823
  } else
753
- console.log("✅ Build completed"), r && console.log(r), We(), o && o();
754
- v && (v = !1, oe());
824
+ console.log("✅ Build completed"), l && console.log(l), Le(), r && r();
825
+ v && (v = !1, de());
755
826
  });
756
- }, $e = /* @__PURE__ */ new Set(), Me = (o) => {
757
- e.default.readdir(o, { withFileTypes: !0 }, (t, r) => {
758
- t || (r.forEach((i) => {
759
- const l = n.default.join(o, i.name);
760
- if (i.isDirectory())
761
- i.name !== "node_modules" && i.name !== "dist" && !i.name.startsWith(".") && Me(l);
762
- else if (i.isFile()) {
763
- const p = n.default.extname(i.name);
764
- if (p === ".js" || p === ".css" || p === ".html")
827
+ }, Ae = /* @__PURE__ */ new Set(), Ce = (r) => {
828
+ o.default.readdir(r, { withFileTypes: !0 }, (a, l) => {
829
+ a || (l.forEach((c) => {
830
+ const f = e.default.join(r, c.name);
831
+ if (c.isDirectory())
832
+ c.name !== "node_modules" && c.name !== "dist" && !c.name.startsWith(".") && Ce(f);
833
+ else if (c.isFile()) {
834
+ const y = e.default.extname(c.name);
835
+ if (y === ".js" || y === ".css" || y === ".html")
765
836
  try {
766
- const g = e.default.readFileSync(l, "utf-8");
767
- F.set(l, g);
837
+ const S = o.default.readFileSync(f, "utf-8");
838
+ P.set(f, S);
768
839
  } catch {
769
840
  }
770
841
  }
771
- }), $e.has(o) || ($e.add(o), e.default.watch(o, (i, l) => {
772
- if (!l) return;
773
- const p = n.default.extname(l);
774
- if (p !== ".js" && p !== ".css" && p !== ".html") return;
775
- const g = n.default.join(o, l);
842
+ }), Ae.has(r) || (Ae.add(r), o.default.watch(r, (c, f) => {
843
+ if (!f) return;
844
+ const y = e.default.extname(f);
845
+ if (y !== ".js" && y !== ".css" && y !== ".html") return;
846
+ const S = e.default.join(r, f);
776
847
  setTimeout(() => {
777
848
  try {
778
- const x = e.default.readFileSync(g, "utf-8"), N = F.get(g);
779
- x !== N && (F.set(g, x), console.log(`📝 File changed: ${g}`), oe());
849
+ const F = o.default.readFileSync(S, "utf-8"), N = P.get(S);
850
+ F !== N && (P.set(S, F), console.log(`📝 File changed: ${S}`), x ? Le() : de());
780
851
  } catch {
781
852
  }
782
853
  }, 50);
783
854
  })));
784
855
  });
785
- }, Oe = (o) => {
856
+ }, De = (r) => {
786
857
  console.log(`
787
- 🔨 Component: ${S}`), oe(o), Me(D), console.log("👀 Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
788
- `);
789
- }, Ve = () => new Promise((o) => {
790
- const t = {
858
+ 🔨 Component: ${C}`), x ? (console.log("📄 No build needed (single HTML file mode)"), Ce(O), console.log(`👀 Watching ${$} for changes...`), console.log(`Press Ctrl+C to stop
859
+ `), r && r()) : (de(r), Ce(O), console.log("👀 Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
860
+ `));
861
+ }, st = () => new Promise((r) => {
862
+ const a = {
791
863
  hostname: "localhost",
792
- port: y,
864
+ port: p,
793
865
  path: "/_list",
794
866
  method: "GET",
795
867
  timeout: 1e3
796
- }, r = a.default.request(t, (i) => {
797
- o(!0);
868
+ }, l = n.default.request(a, (c) => {
869
+ r(!0);
798
870
  });
799
- r.on("error", () => o(!1)), r.on("timeout", () => {
800
- r.destroy(), o(!1);
801
- }), r.end();
802
- }), Ge = () => new Promise((o) => {
803
- const t = a.default.createServer((r, i) => {
804
- if (i.setHeader("Content-Type", "application/json"), r.method === "POST" && r.url === "/_register") {
805
- let l = "";
806
- r.on("data", (p) => l += p), r.on("end", () => {
871
+ l.on("error", () => r(!1)), l.on("timeout", () => {
872
+ l.destroy(), r(!1);
873
+ }), l.end();
874
+ }), it = () => new Promise((r) => {
875
+ const a = n.default.createServer((l, c) => {
876
+ if (c.setHeader("Content-Type", "application/json"), l.method === "POST" && l.url === "/_register") {
877
+ let f = "";
878
+ l.on("data", (y) => f += y), l.on("end", () => {
807
879
  try {
808
- const { componentId: p, distPath: g, componentName: x } = JSON.parse(l);
809
- j.set(p, { path: g, name: x || null });
810
- const N = x ? ` (${x})` : "";
811
- console.log(`✅ Registered: ${p}${N} -> ${g}`), i.writeHead(200), i.end(JSON.stringify({ success: !0, registered: Array.from(j.keys()) }));
812
- } catch (p) {
813
- i.writeHead(400), i.end(JSON.stringify({ error: p.message }));
880
+ const { componentId: y, distPath: S, componentName: F, htmlFile: N } = JSON.parse(f);
881
+ R.set(y, { path: S, name: F || null, htmlFile: N || null });
882
+ const J = F ? ` (${F})` : "";
883
+ console.log(`✅ Registered: ${y}${J} -> ${S}${N ? "/" + N : ""}`), c.writeHead(200), c.end(JSON.stringify({ success: !0, registered: Array.from(R.keys()) }));
884
+ } catch (y) {
885
+ c.writeHead(400), c.end(JSON.stringify({ error: y.message }));
814
886
  }
815
887
  });
816
- } else if (r.method === "POST" && r.url === "/_unregister") {
817
- let l = "";
818
- r.on("data", (p) => l += p), r.on("end", () => {
888
+ } else if (l.method === "POST" && l.url === "/_unregister") {
889
+ let f = "";
890
+ l.on("data", (y) => f += y), l.on("end", () => {
819
891
  try {
820
- const { componentId: p } = JSON.parse(l);
821
- j.delete(p), console.log(`❌ Unregistered: ${p}`), i.writeHead(200), i.end(JSON.stringify({ success: !0 }));
822
- } catch (p) {
823
- i.writeHead(400), i.end(JSON.stringify({ error: p.message }));
892
+ const { componentId: y } = JSON.parse(f);
893
+ R.delete(y), console.log(`❌ Unregistered: ${y}`), c.writeHead(200), c.end(JSON.stringify({ success: !0 }));
894
+ } catch (y) {
895
+ c.writeHead(400), c.end(JSON.stringify({ error: y.message }));
824
896
  }
825
897
  });
826
- } else r.method === "GET" && r.url === "/_list" ? (i.writeHead(200), i.end(JSON.stringify({ components: Array.from(j.entries()) }))) : (i.writeHead(404), i.end(JSON.stringify({ error: "Not found" })));
898
+ } else l.method === "GET" && l.url === "/_list" ? (c.writeHead(200), c.end(JSON.stringify({ components: Array.from(R.entries()) }))) : (c.writeHead(404), c.end(JSON.stringify({ error: "Not found" })));
827
899
  });
828
- t.on("error", () => {
829
- o(!1);
830
- }), t.listen(y, () => {
900
+ a.on("error", () => {
901
+ r(!1);
902
+ }), a.listen(p, () => {
831
903
  console.log(`
832
- 🔄 Taking over as server...`), console.log(`📡 Management server on port ${y}`), te.on("error", () => {
833
- t.close(), o(!1);
834
- }), te.listen(m, () => {
835
- console.log(`📡 Main server running at http://localhost:${m}`), j.set(S, {
836
- path: n.default.resolve(D, b),
837
- name: h
904
+ 🔄 Taking over as server...`), console.log(`📡 Management server on port ${p}`), ce.on("error", () => {
905
+ a.close(), r(!1);
906
+ }), ce.listen(m, () => {
907
+ console.log(`📡 Main server running at http://localhost:${m}`);
908
+ const l = x ? e.default.resolve(O) : e.default.resolve(O, b);
909
+ R.set(C, {
910
+ path: l,
911
+ name: I,
912
+ htmlFile: x ? $ : null
838
913
  });
839
- const r = h ? ` (${h})` : "";
840
- console.log(`✅ Registered component: ${S}${r}`), console.log(`📡 Access at: http://localhost:${m}/view/${S}/`), o(!0);
914
+ const c = I ? ` (${I})` : "";
915
+ console.log(`✅ Registered component: ${C}${c}`), console.log(`📡 Access at: http://localhost:${m}/view/${C}/`), r(!0);
841
916
  });
842
917
  });
843
918
  });
844
- let ne;
845
- const Ie = () => {
846
- ne = setInterval(async () => {
847
- await Ve() || (clearInterval(ne), console.log(`
848
- ⚠️ Server appears to be down, attempting to take over...`), await Ge() ? console.log("✅ Successfully took over as server") : (console.log("ℹ️ Another instance took over, re-registering..."), setTimeout(async () => {
919
+ let pe;
920
+ const He = () => {
921
+ pe = setInterval(async () => {
922
+ await st() || (clearInterval(pe), console.log(`
923
+ ⚠️ Server appears to be down, attempting to take over...`), await it() ? console.log("✅ Successfully took over as server") : (console.log("ℹ️ Another instance took over, re-registering..."), setTimeout(async () => {
849
924
  try {
850
- await be(), console.log(`✅ Re-registered component: ${S}`), Ie();
851
- } catch (r) {
852
- console.error("❌ Failed to re-register:", r.message);
925
+ await Ne(), console.log(`✅ Re-registered component: ${C}`), He();
926
+ } catch (l) {
927
+ console.error("❌ Failed to re-register:", l.message);
853
928
  }
854
929
  }, 2e3)));
855
930
  }, 3e3);
856
- }, je = async () => {
931
+ }, Ue = async () => {
857
932
  console.log(`
858
933
 
859
- 🛑 Shutting down...`), ne && clearInterval(ne), await Ue(), process.exit(0);
934
+ 🛑 Shutting down...`), pe && clearInterval(pe), await tt(), process.exit(0);
860
935
  };
861
- process.on("SIGINT", je), process.on("SIGTERM", je), pe.on("error", async (o) => {
862
- if (o.code === "EADDRINUSE") {
936
+ process.on("SIGINT", Ue), process.on("SIGTERM", Ue), xe.on("error", async (r) => {
937
+ if (r.code === "EADDRINUSE") {
863
938
  console.log(`
864
939
  🔗 Connecting to existing dev server...`);
865
940
  try {
866
- S = await A();
867
- const t = await be();
868
- console.log(`✅ Registered component: ${S}`), console.log(`📡 Access at: http://localhost:${m}/view/${S}/`), console.log(`📋 All registered components: ${t.registered.join(", ")}`), Oe(() => {
869
- E(`http://localhost:${m}/view/${S}/`);
870
- }), Ie();
871
- } catch (t) {
872
- console.error("❌ Failed to register component:", t.message), process.exit(1);
941
+ C = await U();
942
+ const a = await Ne();
943
+ console.log(`✅ Registered component: ${C}`), console.log(`📡 Access at: http://localhost:${m}/view/${C}/`), console.log(`📋 All registered components: ${a.registered.join(", ")}`), De(() => {
944
+ process.env.MYOP_NO_BROWSER || g(`http://localhost:${m}/view/${C}/`);
945
+ }), He();
946
+ } catch (a) {
947
+ console.error("❌ Failed to register component:", a.message), process.exit(1);
873
948
  }
874
949
  } else
875
- console.error("❌ Management server error:", o.message), process.exit(1);
876
- }), pe.on("upgrade", Je), pe.listen(y, async () => {
950
+ console.error("❌ Management server error:", r.message), process.exit(1);
951
+ }), xe.on("upgrade", et), xe.listen(p, async () => {
877
952
  console.log(`
878
- 🚀 Starting shared dev server...`), console.log(`📡 Management server on port ${y}`), te.on("error", (o) => {
879
- console.error("❌ Main server error:", o.message), process.exit(1);
880
- }), te.listen(m, async () => {
881
- console.log(`📡 Main server running at http://localhost:${m}`), (S === "DEV" || S === "NEW") && (S = "DEV1"), j.set(S, {
882
- path: n.default.resolve(D, b),
883
- name: h
953
+ 🚀 Starting shared dev server...`), console.log(`📡 Management server on port ${p}`), ce.on("error", (r) => {
954
+ console.error("❌ Main server error:", r.message), process.exit(1);
955
+ }), ce.listen(m, async () => {
956
+ console.log(`📡 Main server running at http://localhost:${m}`), (C === "DEV" || C === "NEW") && (C = "DEV1");
957
+ const r = x ? e.default.resolve(O) : e.default.resolve(O, b);
958
+ R.set(C, {
959
+ path: r,
960
+ name: I,
961
+ htmlFile: x ? $ : null
884
962
  });
885
- const o = h ? ` (${h})` : "";
886
- console.log(`✅ Registered component: ${S}${o}`), console.log(`📡 Access at: http://localhost:${m}/view/${S}/`), Oe(() => {
887
- E(`http://localhost:${m}/view/${S}/`);
963
+ const a = I ? ` (${I})` : "";
964
+ console.log(`✅ Registered component: ${C}${a}`), console.log(`📡 Access at: http://localhost:${m}/view/${C}/`), De(() => {
965
+ process.env.MYOP_NO_BROWSER || g(`http://localhost:${m}/view/${C}/`);
888
966
  });
889
967
  });
890
968
  });
891
969
  }
892
- const ge = q.join(Ze.homedir(), ".myop"), Z = q.join(ge, "credentials.json");
893
- function lt() {
894
- R.existsSync(ge) || R.mkdirSync(ge, { recursive: !0, mode: 448 });
970
+ const T = class T {
971
+ constructor(e) {
972
+ this.components = e.map(
973
+ (t) => typeof t == "string" ? { name: t, path: "", id: "" } : t
974
+ ), this.logs = /* @__PURE__ */ new Map(), this.scrollPos = /* @__PURE__ */ new Map(), this.statuses = /* @__PURE__ */ new Map(), this.statusKeys = /* @__PURE__ */ new Map(), this.panelPositions = /* @__PURE__ */ new Map(), this.needsFullRedraw = !0, this.pendingUpdates = /* @__PURE__ */ new Set(), this.renderQueued = !1, this.startTime = Date.now(), this.visibleLogLines = 8, this.selectedPanel = 0;
975
+ for (const t of this.components)
976
+ this.logs.set(t.name, []), this.scrollPos.set(t.name, 0), this.statuses.set(t.name, "Initializing..."), this.statusKeys.set(t.name, "initializing");
977
+ this.cols = process.stdout.columns || 120, this.rows = process.stdout.rows || 30, process.stdout.on("resize", () => {
978
+ this.cols = process.stdout.columns || 120, this.rows = process.stdout.rows || 30, this.needsFullRedraw = !0, this.calculateLayout(), this.render();
979
+ }), this.setupKeyboardInput(), process.stdout.write(T.ESC.hideCursor), this.calculateLayout(), this.render(), this.uptimeInterval = setInterval(() => this.updateHeader(), 1e3);
980
+ }
981
+ setupKeyboardInput() {
982
+ process.stdin.isTTY && (process.stdin.setRawMode(!0), process.stdin.resume(), process.stdin.setEncoding("utf8"), process.stdin.on("data", (e) => {
983
+ var n;
984
+ e === "" && (this.clear(), process.exit());
985
+ const t = (n = this.components[this.selectedPanel]) == null ? void 0 : n.name;
986
+ if (t)
987
+ switch (e) {
988
+ case "\x1B[A":
989
+ this.scroll(t, -1);
990
+ break;
991
+ case "\x1B[B":
992
+ this.scroll(t, 1);
993
+ break;
994
+ case "\x1B[C":
995
+ this.selectedPanel = (this.selectedPanel + 1) % this.components.length, this.needsFullRedraw = !0, this.render();
996
+ break;
997
+ case "\x1B[D":
998
+ this.selectedPanel = (this.selectedPanel - 1 + this.components.length) % this.components.length, this.needsFullRedraw = !0, this.render();
999
+ break;
1000
+ case "\x1B[5~":
1001
+ this.scroll(t, -this.visibleLogLines);
1002
+ break;
1003
+ case "\x1B[6~":
1004
+ this.scroll(t, this.visibleLogLines);
1005
+ break;
1006
+ case "g":
1007
+ this.scrollPos.set(t, 0), this.queueUpdate(t);
1008
+ break;
1009
+ case "G":
1010
+ const i = this.logs.get(t) || [];
1011
+ this.scrollPos.set(t, Math.max(0, i.length - this.visibleLogLines)), this.queueUpdate(t);
1012
+ break;
1013
+ }
1014
+ }));
1015
+ }
1016
+ calculateLayout() {
1017
+ const e = this.components.length, t = 38;
1018
+ let n;
1019
+ this.cols >= t * 3 + 4 ? n = Math.min(e, 3) : this.cols >= t * 2 + 2 ? n = Math.min(e, 2) : n = 1;
1020
+ const i = Math.ceil(e / n), s = Math.floor(this.cols / n), d = 2, M = this.rows - d - 2, m = Math.floor(M / i);
1021
+ this.visibleLogLines = Math.max(2, m - 4), this.layout = { panelsPerRow: n, panelWidth: s, numRows: i, panelHeight: m }, this.panelPositions.clear();
1022
+ for (let p = 0; p < e; p++) {
1023
+ const b = this.components[p], u = Math.floor(p / n), v = p % n;
1024
+ this.panelPositions.set(b.name, {
1025
+ row: d + 1 + u * m,
1026
+ col: v * s + 1,
1027
+ width: s,
1028
+ height: m
1029
+ });
1030
+ }
1031
+ }
1032
+ log(e, t, n = "info") {
1033
+ const i = this.logs.get(e) || [], s = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
1034
+ hour12: !1,
1035
+ hour: "2-digit",
1036
+ minute: "2-digit",
1037
+ second: "2-digit"
1038
+ });
1039
+ t.includes("✅") || t.includes("completed") ? n = "success" : t.includes("❌") || t.includes("failed") ? n = "error" : t.includes("⚠") ? n = "warning" : t.includes("🔥") || t.includes("HMR") ? n = "hmr" : (t.includes("📝") || t.includes("changed")) && (n = "change"), i.push({ timestamp: s, message: t.replace(/[✅❌⚠🔥📝🔨]/g, "").trim(), type: n }), this.logs.set(e, i), i.length > this.visibleLogLines && this.scrollPos.set(e, i.length - this.visibleLogLines), this.queueUpdate(e);
1040
+ }
1041
+ setStatus(e, t) {
1042
+ let n = "ready";
1043
+ const i = t.toLowerCase();
1044
+ i.includes("initializing") || i.includes("⏳") ? n = "initializing" : i.includes("starting") ? n = "starting" : i.includes("building") || i.includes("🔨") ? n = "building" : i.includes("ready") || i.includes("✅") ? n = "ready" : i.includes("changed") || i.includes("📝") ? n = "changed" : i.includes("hmr") ? n = "hmr_update" : i.includes("🔥") ? n = "hmr" : i.includes("error") || i.includes("❌") ? n = "error" : i.includes("warning") || i.includes("⚠") ? n = "warning" : (i.includes("stopped") || i.includes("exited")) && (n = "stopped"), this.statuses.set(e, t), this.statusKeys.set(e, n), this.queueUpdate(e);
1045
+ }
1046
+ scroll(e, t) {
1047
+ const n = this.logs.get(e) || [], i = this.scrollPos.get(e) || 0, s = Math.max(0, n.length - this.visibleLogLines), d = Math.max(0, Math.min(s, i + t));
1048
+ d !== i && (this.scrollPos.set(e, d), this.queueUpdate(e));
1049
+ }
1050
+ queueUpdate(e) {
1051
+ this.pendingUpdates.add(e), this.renderQueued || (this.renderQueued = !0, setImmediate(() => {
1052
+ this.renderQueued = !1, this.flushUpdates();
1053
+ }));
1054
+ }
1055
+ flushUpdates() {
1056
+ if (this.needsFullRedraw) {
1057
+ this.fullRender(), this.needsFullRedraw = !1, this.pendingUpdates.clear();
1058
+ return;
1059
+ }
1060
+ for (const e of this.pendingUpdates)
1061
+ this.renderPanel(e);
1062
+ this.pendingUpdates.clear();
1063
+ }
1064
+ getUptime() {
1065
+ const e = Math.floor((Date.now() - this.startTime) / 1e3), t = Math.floor(e / 60), n = e % 60;
1066
+ return `${t}:${n.toString().padStart(2, "0")}`;
1067
+ }
1068
+ updateHeader() {
1069
+ const e = T.C, t = Array.from(this.statusKeys.values()).filter((s) => s === "ready").length, n = this.components.length;
1070
+ let i = `${e.dim}📡${e.reset} http://localhost:9292 ${e.gray}|${e.reset} `;
1071
+ i += `${e.green}${t}${e.reset}/${n} ready ${e.gray}|${e.reset} `, i += `⏱ ${this.getUptime()} ${e.gray}|${e.reset} `, i += `Press ${e.yellow}Ctrl+C${e.reset} to stop`, i += T.ESC.clearLine.slice(0, -1), process.stdout.write(T.ESC.moveTo(2, 1) + i);
1072
+ }
1073
+ renderPanel(e) {
1074
+ const t = T.C, n = T.STATUS, i = this.panelPositions.get(e);
1075
+ if (!i) return;
1076
+ const s = this.components.findIndex((U) => U.name === e), d = this.components[s], w = s === this.selectedPanel, M = this.statusKeys.get(e) || "initializing", m = n[M], p = t[m.color], b = this.logs.get(e) || [], u = this.scrollPos.get(e) || 0, v = i.width - 1, x = w ? t.cyan : t.gray, $ = [], _ = d.name.substring(0, v - 20);
1077
+ let D = `${x}┌─${t.reset} ${p}${m.icon}${t.reset} `;
1078
+ D += `${t.bold}${_}${t.reset} ${t.gray}─${t.reset} ${p}${m.label}${t.reset} `;
1079
+ const g = 5 + _.length + m.label.length + 3;
1080
+ D += `${x}${"─".repeat(Math.max(0, v - g))}┐${t.reset}`, $.push(T.ESC.moveTo(i.row, i.col) + D);
1081
+ const P = (d.path || "").substring(0, v - 6);
1082
+ let E = `${x}│${t.reset} ${t.dim}${P}${t.reset}`;
1083
+ E += " ".repeat(Math.max(0, v - P.length - 3)), E += `${x}│${t.reset}`, $.push(T.ESC.moveTo(i.row + 1, i.col) + E);
1084
+ const C = b.length, I = C > this.visibleLogLines ? `${u + 1}-${Math.min(u + this.visibleLogLines, C)}/${C}` : "";
1085
+ let L = `${x}├${"─".repeat(v - I.length - 4)}${t.reset}`;
1086
+ I && (L += `${t.dim}${I}${t.reset}`), L += `${x}${"─".repeat(2)}┤${t.reset}`, $.push(T.ESC.moveTo(i.row + 2, i.col) + L);
1087
+ const Z = b.slice(u, u + this.visibleLogLines);
1088
+ for (let U = 0; U < this.visibleLogLines; U++) {
1089
+ const O = Z[U];
1090
+ let V = `${x}│${t.reset}`;
1091
+ if (O) {
1092
+ let R = t.white;
1093
+ O.type === "success" ? R = t.green : O.type === "error" ? R = t.red : O.type === "warning" ? R = t.yellow : O.type === "hmr" ? R = t.magenta : O.type === "change" && (R = t.blue);
1094
+ const G = O.message.substring(0, v - 12);
1095
+ V += `${t.dim}${O.timestamp}${t.reset} ${R}${G}${t.reset}`;
1096
+ const Se = v - O.timestamp.length - G.length - 2;
1097
+ V += " ".repeat(Math.max(0, Se));
1098
+ } else
1099
+ V += " ".repeat(v - 2);
1100
+ V += `${x}│${t.reset}`, $.push(T.ESC.moveTo(i.row + 3 + U, i.col) + V);
1101
+ }
1102
+ $.push(T.ESC.moveTo(i.row + 3 + this.visibleLogLines, i.col) + `${x}└${"─".repeat(v - 2)}┘${t.reset}`), process.stdout.write($.join(""));
1103
+ }
1104
+ fullRender() {
1105
+ const e = T.C;
1106
+ process.stdout.write(T.ESC.clearScreen + T.ESC.moveTo(1, 1));
1107
+ const t = " MYOP MONOREPO DEV ", n = Math.floor((this.cols - t.length) / 2);
1108
+ process.stdout.write(`${e.cyan}${"━".repeat(n)}${e.bold}${e.bgCyan}${e.black}${t}${e.reset}${e.cyan}${"━".repeat(this.cols - n - t.length)}${e.reset}`), this.updateHeader();
1109
+ for (const i of this.components)
1110
+ this.renderPanel(i.name);
1111
+ this.renderFooter();
1112
+ }
1113
+ renderFooter() {
1114
+ const e = T.C, t = this.rows - 1;
1115
+ let n = `${e.gray}`;
1116
+ n += `${e.green}●${e.gray} Ready `, n += `${e.yellow}⟳${e.gray} Building `, n += `${e.magenta}⚡${e.gray} HMR `, n += `${e.red}✖${e.gray} Error `, n += `${e.dim}| ←→: select panel ↑↓: scroll PgUp/PgDn: page g/G: top/bottom${e.reset}`, process.stdout.write(T.ESC.moveTo(t, 1) + n);
1117
+ }
1118
+ render() {
1119
+ this.needsFullRedraw = !0, this.queueUpdate("__full__");
1120
+ }
1121
+ clear() {
1122
+ this.uptimeInterval && clearInterval(this.uptimeInterval), process.stdin.isTTY && process.stdin.setRawMode(!1), process.stdout.write(T.ESC.clearScreen + T.ESC.moveTo(1, 1) + T.ESC.showCursor);
1123
+ }
1124
+ };
1125
+ // ANSI escape codes
1126
+ ue(T, "ESC", {
1127
+ moveTo: (e, t) => `\x1B[${e};${t}H`,
1128
+ hideCursor: "\x1B[?25l",
1129
+ showCursor: "\x1B[?25h",
1130
+ clearScreen: "\x1B[2J",
1131
+ clearLine: "\x1B[2K"
1132
+ }), // Colors
1133
+ ue(T, "C", {
1134
+ reset: "\x1B[0m",
1135
+ bold: "\x1B[1m",
1136
+ dim: "\x1B[2m",
1137
+ red: "\x1B[31m",
1138
+ green: "\x1B[32m",
1139
+ yellow: "\x1B[33m",
1140
+ blue: "\x1B[34m",
1141
+ magenta: "\x1B[35m",
1142
+ cyan: "\x1B[36m",
1143
+ white: "\x1B[37m",
1144
+ gray: "\x1B[90m",
1145
+ bgCyan: "\x1B[46m",
1146
+ black: "\x1B[30m"
1147
+ }), // Status configs
1148
+ ue(T, "STATUS", {
1149
+ initializing: { icon: "◔", color: "yellow", label: "Initializing" },
1150
+ starting: { icon: "◑", color: "yellow", label: "Starting" },
1151
+ building: { icon: "⟳", color: "yellow", label: "Building" },
1152
+ ready: { icon: "●", color: "green", label: "Ready" },
1153
+ changed: { icon: "○", color: "blue", label: "Changed" },
1154
+ hmr: { icon: "⚡", color: "magenta", label: "HMR" },
1155
+ hmr_update: { icon: "⚡", color: "magenta", label: "HMR Update" },
1156
+ hmr_connected: { icon: "⚡", color: "magenta", label: "HMR" },
1157
+ error: { icon: "✖", color: "red", label: "Error" },
1158
+ warning: { icon: "⚠", color: "yellow", label: "Warning" },
1159
+ stopped: { icon: "■", color: "gray", label: "Stopped" }
1160
+ });
1161
+ let Te = T;
1162
+ async function Rt(o) {
1163
+ const { spawn: e, exec: t } = await import("child_process"), n = await import("path"), i = o.map((p) => ({
1164
+ name: p.name,
1165
+ path: p.path,
1166
+ id: p.componentId || ""
1167
+ })), s = new Te(i), d = [], w = (p) => {
1168
+ const b = process.platform;
1169
+ let u;
1170
+ b === "darwin" ? u = `open "${p}"` : b === "win32" ? u = `start "" "${p}"` : u = `xdg-open "${p}"`, t(u, () => {
1171
+ });
1172
+ }, M = () => {
1173
+ s.clear(), console.log(`
1174
+ 🛑 Shutting down all components...`), d.forEach((p) => {
1175
+ try {
1176
+ p.kill("SIGTERM");
1177
+ } catch {
1178
+ }
1179
+ }), setTimeout(() => process.exit(0), 500);
1180
+ };
1181
+ process.on("SIGINT", M), process.on("SIGTERM", M);
1182
+ const m = process.argv[1];
1183
+ for (let p = 0; p < o.length; p++) {
1184
+ const b = o[p], u = b.name;
1185
+ s.setStatus(u, "⏳ Starting..."), s.log(u, `Starting in ${b.path}`);
1186
+ const v = e("node", [m, "dev"], {
1187
+ cwd: n.default.resolve(b.path),
1188
+ env: { ...process.env, FORCE_COLOR: "1", MYOP_NO_BROWSER: "1" },
1189
+ stdio: ["ignore", "pipe", "pipe"]
1190
+ });
1191
+ d.push(v);
1192
+ let x = "";
1193
+ v.stdout.on("data", ($) => {
1194
+ x += $.toString();
1195
+ const _ = x.split(`
1196
+ `);
1197
+ x = _.pop() || "";
1198
+ for (const D of _) {
1199
+ const g = D.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "").trim();
1200
+ g && (g.includes("Registered component") || g.includes("Registered:") ? s.setStatus(u, "✅ Ready") : g.includes("Building...") || g.includes("Running initial build") ? s.setStatus(u, "🔨 Building...") : g.includes("Build completed") || g.includes("Build succeeded") ? s.setStatus(u, "✅ Ready") : g.includes("Build failed") ? s.setStatus(u, "❌ Build Error") : g.includes("File changed") ? (s.setStatus(u, "📝 Changed"), setTimeout(() => s.setStatus(u, "✅ Ready"), 1500)) : g.includes("Notifying") && g.includes("HMR") ? (s.setStatus(u, "🔥 HMR Update"), setTimeout(() => s.setStatus(u, "✅ Ready"), 1e3)) : g.includes("HMR client connected") && (s.setStatus(u, "🔥 HMR Connected"), setTimeout(() => s.setStatus(u, "✅ Ready"), 1e3)), !g.includes("Watching") && !g.includes("Press Ctrl+C") && !g.includes("Starting shared") && !g.includes("Management server") && !g.includes("Main server") && !g.includes("Access at:") && !g.includes("No build needed") && s.log(u, g));
1201
+ }
1202
+ }), v.stderr.on("data", ($) => {
1203
+ const _ = $.toString().split(`
1204
+ `);
1205
+ for (const D of _) {
1206
+ const g = D.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "").trim();
1207
+ g && (s.log(u, `⚠️ ${g}`), s.setStatus(u, "⚠️ Warning"));
1208
+ }
1209
+ }), v.on("exit", ($) => {
1210
+ $ !== 0 && $ !== null && (s.setStatus(u, `❌ Exited (${$})`), s.log(u, `Process exited with code ${$}`));
1211
+ }), p < o.length - 1 && await new Promise(($) => setTimeout($, 500));
1212
+ }
1213
+ s.render(), setTimeout(() => {
1214
+ w("http://localhost:9292");
1215
+ }, 2e3);
895
1216
  }
896
- function we() {
1217
+ const Tt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1218
+ __proto__: null,
1219
+ devCommand: Fe,
1220
+ monorepoDevCommand: Rt
1221
+ }, Symbol.toStringTag, { value: "Module" })), Ee = ee.join(mt.homedir(), ".myop"), ae = ee.join(Ee, "credentials.json");
1222
+ function Et() {
1223
+ H.existsSync(Ee) || H.mkdirSync(Ee, { recursive: !0, mode: 448 });
1224
+ }
1225
+ function je() {
897
1226
  try {
898
- if (!R.existsSync(Z))
1227
+ if (!H.existsSync(ae))
899
1228
  return null;
900
- const e = R.readFileSync(Z, "utf8");
901
- return JSON.parse(e);
902
- } catch (e) {
903
- return console.info("Failed to read credentials:", e.message), null;
1229
+ const o = H.readFileSync(ae, "utf8");
1230
+ return JSON.parse(o);
1231
+ } catch (o) {
1232
+ return console.info("Failed to read credentials:", o.message), null;
904
1233
  }
905
1234
  }
906
- function Ae(e) {
907
- lt();
908
- const n = {
909
- ...e,
1235
+ function Qe(o) {
1236
+ Et();
1237
+ const e = {
1238
+ ...o,
910
1239
  savedAt: (/* @__PURE__ */ new Date()).toISOString()
911
1240
  };
912
- R.writeFileSync(Z, JSON.stringify(n, null, 2), {
1241
+ H.writeFileSync(ae, JSON.stringify(e, null, 2), {
913
1242
  mode: 384
914
1243
  // Read/write for owner only
915
1244
  });
916
1245
  }
917
- function De() {
1246
+ function Ze() {
918
1247
  try {
919
- return R.existsSync(Z) && R.unlinkSync(Z), !0;
920
- } catch (e) {
921
- return console.error("Failed to clear credentials:", e.message), !1;
1248
+ return H.existsSync(ae) && H.unlinkSync(ae), !0;
1249
+ } catch (o) {
1250
+ return console.error("Failed to clear credentials:", o.message), !1;
922
1251
  }
923
1252
  }
924
- function dt(e) {
925
- if (!e || !e.expiresAt)
1253
+ function It(o) {
1254
+ if (!o || !o.expiresAt)
926
1255
  return !0;
927
- const n = 5 * 60 * 1e3, s = new Date(e.expiresAt).getTime();
928
- return Date.now() > s - n;
1256
+ const e = 5 * 60 * 1e3, t = new Date(o.expiresAt).getTime();
1257
+ return Date.now() > t - e;
929
1258
  }
930
1259
  function ve() {
931
- const e = we();
932
- return e ? {
933
- email: e.userEmail,
934
- userId: e.userId
1260
+ const o = je();
1261
+ return o ? {
1262
+ email: o.userEmail,
1263
+ userId: o.userId
935
1264
  } : null;
936
1265
  }
937
- const X = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", ae = 19284, Se = `http://localhost:${ae}/callback`, pt = "myop-cli";
938
- function mt() {
939
- return he.randomBytes(32).toString("base64url");
1266
+ const se = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", he = 19284, ke = `http://localhost:${he}/callback`, Ot = "myop-cli";
1267
+ function Ft() {
1268
+ return Ie.randomBytes(32).toString("base64url");
940
1269
  }
941
- function ut(e) {
942
- return he.createHash("sha256").update(e).digest("base64url");
1270
+ function jt(o) {
1271
+ return Ie.createHash("sha256").update(o).digest("base64url");
943
1272
  }
944
- async function ft() {
945
- const e = await fetch(`${X}/oauth/register`, {
1273
+ async function kt() {
1274
+ const o = await fetch(`${se}/oauth/register`, {
946
1275
  method: "POST",
947
1276
  headers: { "Content-Type": "application/json" },
948
1277
  body: JSON.stringify({
949
- client_name: pt,
950
- redirect_uris: [Se],
1278
+ client_name: Ot,
1279
+ redirect_uris: [ke],
951
1280
  grant_types: ["authorization_code", "refresh_token"],
952
1281
  response_types: ["code"]
953
1282
  })
954
1283
  });
955
- if (!e.ok) {
956
- const n = await e.text();
957
- throw new Error(`Failed to register client: ${n}`);
1284
+ if (!o.ok) {
1285
+ const e = await o.text();
1286
+ throw new Error(`Failed to register client: ${e}`);
958
1287
  }
959
- return e.json();
1288
+ return o.json();
960
1289
  }
961
- function re(e, n, s, a = null) {
962
- const f = {
1290
+ function ge(o, e, t, n = null) {
1291
+ const i = {
963
1292
  success: `<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#4ade80" stroke-width="2">
964
1293
  <circle cx="12" cy="12" r="10"/>
965
1294
  <path d="M8 12l2.5 2.5L16 9"/>
@@ -972,17 +1301,17 @@ function re(e, n, s, a = null) {
972
1301
  <path d="M12 2L2 22h20L12 2z"/>
973
1302
  <path d="M12 9v4M12 17h.01"/>
974
1303
  </svg>`
975
- }, c = {
1304
+ }, s = {
976
1305
  success: { accent: "#4ade80", glow: "rgba(74, 222, 128, 0.1)" },
977
1306
  error: { accent: "#f87171", glow: "rgba(248, 113, 113, 0.1)" },
978
1307
  warning: { accent: "#fbbf24", glow: "rgba(251, 191, 36, 0.1)" }
979
- }, { accent: u, glow: w } = c[e] || c.error;
1308
+ }, { accent: d, glow: w } = s[o] || s.error;
980
1309
  return `<!DOCTYPE html>
981
1310
  <html lang="en">
982
1311
  <head>
983
1312
  <meta charset="UTF-8">
984
1313
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
985
- <title>myop-cli | ${n}</title>
1314
+ <title>myop-cli | ${e}</title>
986
1315
  <style>
987
1316
  * {
988
1317
  margin: 0;
@@ -1037,7 +1366,7 @@ function re(e, n, s, a = null) {
1037
1366
  h1 {
1038
1367
  font-size: 20px;
1039
1368
  font-weight: 500;
1040
- color: ${u};
1369
+ color: ${d};
1041
1370
  margin-bottom: 12px;
1042
1371
  letter-spacing: -0.5px;
1043
1372
  }
@@ -1070,7 +1399,7 @@ function re(e, n, s, a = null) {
1070
1399
  align-items: center;
1071
1400
  gap: 8px;
1072
1401
  background: ${w};
1073
- border: 1px solid ${u}33;
1402
+ border: 1px solid ${d}33;
1074
1403
  border-radius: 4px;
1075
1404
  padding: 10px 16px;
1076
1405
  font-size: 12px;
@@ -1107,11 +1436,11 @@ function re(e, n, s, a = null) {
1107
1436
  <body>
1108
1437
  <div class="container">
1109
1438
  <div class="icon">
1110
- ${f[e] || f.error}
1439
+ ${i[o] || i.error}
1111
1440
  </div>
1112
- <h1>${n}</h1>
1113
- <p class="message">${s}</p>
1114
- ${a ? `<div class="details"><code>Error:</code> ${a}</div>` : ""}
1441
+ <h1>${e}</h1>
1442
+ <p class="message">${t}</p>
1443
+ ${n ? `<div class="details"><code>Error:</code> ${n}</div>` : ""}
1115
1444
  <div class="hint">
1116
1445
  <span>Press</span>
1117
1446
  <kbd>⌘</kbd><kbd>W</kbd>
@@ -1124,95 +1453,95 @@ function re(e, n, s, a = null) {
1124
1453
  </body>
1125
1454
  </html>`;
1126
1455
  }
1127
- function gt(e) {
1128
- return new Promise((n, s) => {
1129
- const a = Xe.createServer((f, c) => {
1130
- const u = new ke(f.url, `http://localhost:${ae}`);
1131
- if (u.pathname === "/callback") {
1132
- const w = u.searchParams.get("code"), O = u.searchParams.get("state"), m = u.searchParams.get("error");
1456
+ function Nt(o) {
1457
+ return new Promise((e, t) => {
1458
+ const n = dt.createServer((i, s) => {
1459
+ const d = new ze(i.url, `http://localhost:${he}`);
1460
+ if (d.pathname === "/callback") {
1461
+ const w = d.searchParams.get("code"), M = d.searchParams.get("state"), m = d.searchParams.get("error");
1133
1462
  if (m) {
1134
- c.writeHead(200, { "Content-Type": "text/html" }), c.end(re(
1463
+ s.writeHead(200, { "Content-Type": "text/html" }), s.end(ge(
1135
1464
  "error",
1136
1465
  "Authentication Failed",
1137
1466
  "Unable to complete the authentication process.",
1138
1467
  m
1139
- )), a.close(), s(new Error(`OAuth error: ${m}`));
1468
+ )), n.close(), t(new Error(`OAuth error: ${m}`));
1140
1469
  return;
1141
1470
  }
1142
- if (O !== e) {
1143
- c.writeHead(400, { "Content-Type": "text/html" }), c.end(re(
1471
+ if (M !== o) {
1472
+ s.writeHead(400, { "Content-Type": "text/html" }), s.end(ge(
1144
1473
  "warning",
1145
1474
  "Security Error",
1146
1475
  "State mismatch detected. This could indicate a CSRF attack. Please try authenticating again.",
1147
1476
  "state_mismatch"
1148
- )), a.close(), s(new Error("State mismatch"));
1477
+ )), n.close(), t(new Error("State mismatch"));
1149
1478
  return;
1150
1479
  }
1151
1480
  if (!w) {
1152
- c.writeHead(400, { "Content-Type": "text/html" }), c.end(re(
1481
+ s.writeHead(400, { "Content-Type": "text/html" }), s.end(ge(
1153
1482
  "error",
1154
1483
  "Missing Authorization Code",
1155
1484
  "No authorization code was received from the server.",
1156
1485
  "missing_code"
1157
- )), a.close(), s(new Error("No authorization code"));
1486
+ )), n.close(), t(new Error("No authorization code"));
1158
1487
  return;
1159
1488
  }
1160
- c.writeHead(200, { "Content-Type": "text/html" }), c.end(re(
1489
+ s.writeHead(200, { "Content-Type": "text/html" }), s.end(ge(
1161
1490
  "success",
1162
1491
  "Authentication Successful",
1163
1492
  "You have been authenticated successfully. Return to the terminal to continue."
1164
- )), a.close(), n(w);
1493
+ )), n.close(), e(w);
1165
1494
  } else
1166
- c.writeHead(404), c.end("Not found");
1495
+ s.writeHead(404), s.end("Not found");
1167
1496
  });
1168
- a.listen(ae, () => {
1169
- console.info(`OAuth callback server listening on port ${ae}`);
1497
+ n.listen(he, () => {
1498
+ console.info(`OAuth callback server listening on port ${he}`);
1170
1499
  }), setTimeout(() => {
1171
- a.close(), s(new Error("Authentication timed out"));
1500
+ n.close(), t(new Error("Authentication timed out"));
1172
1501
  }, 5 * 60 * 1e3);
1173
1502
  });
1174
1503
  }
1175
- async function ht(e, n, s) {
1176
- const a = await fetch(`${X}/oauth/token`, {
1504
+ async function _t(o, e, t) {
1505
+ const n = await fetch(`${se}/oauth/token`, {
1177
1506
  method: "POST",
1178
1507
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
1179
- body: new Ee({
1508
+ body: new We({
1180
1509
  grant_type: "authorization_code",
1181
- code: e,
1182
- client_id: n,
1183
- redirect_uri: Se,
1184
- code_verifier: s
1510
+ code: o,
1511
+ client_id: e,
1512
+ redirect_uri: ke,
1513
+ code_verifier: t
1185
1514
  })
1186
1515
  });
1187
- if (!a.ok) {
1188
- const f = await a.json();
1189
- throw new Error(f.error_description || f.error || "Token exchange failed");
1516
+ if (!n.ok) {
1517
+ const i = await n.json();
1518
+ throw new Error(i.error_description || i.error || "Token exchange failed");
1190
1519
  }
1191
- return a.json();
1520
+ return n.json();
1192
1521
  }
1193
- async function yt(e, n) {
1194
- const s = await fetch(`${X}/oauth/token`, {
1522
+ async function Lt(o, e) {
1523
+ const t = await fetch(`${se}/oauth/token`, {
1195
1524
  method: "POST",
1196
1525
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
1197
- body: new Ee({
1526
+ body: new We({
1198
1527
  grant_type: "refresh_token",
1199
- refresh_token: e,
1200
- client_id: n
1528
+ refresh_token: o,
1529
+ client_id: e
1201
1530
  })
1202
1531
  });
1203
- if (!s.ok) {
1204
- const a = await s.json();
1205
- throw new Error(a.error_description || a.error || "Token refresh failed");
1532
+ if (!t.ok) {
1533
+ const n = await t.json();
1534
+ throw new Error(n.error_description || n.error || "Token refresh failed");
1206
1535
  }
1207
- return s.json();
1536
+ return t.json();
1208
1537
  }
1209
- async function wt(e) {
1210
- var f, c, u;
1211
- const n = await fetch(`${X}/mcp`, {
1538
+ async function At(o) {
1539
+ var i, s, d;
1540
+ const e = await fetch(`${se}/mcp`, {
1212
1541
  method: "POST",
1213
1542
  headers: {
1214
1543
  "Content-Type": "application/json",
1215
- Authorization: `Bearer ${e}`
1544
+ Authorization: `Bearer ${o}`
1216
1545
  },
1217
1546
  body: JSON.stringify({
1218
1547
  jsonrpc: "2.0",
@@ -1224,244 +1553,287 @@ async function wt(e) {
1224
1553
  }
1225
1554
  })
1226
1555
  });
1227
- if (!n.ok)
1556
+ if (!e.ok)
1228
1557
  throw new Error("Failed to get user info");
1229
- const s = await n.json();
1230
- if (s.error)
1231
- throw new Error(s.error.message);
1232
- const a = (u = (c = (f = s.result) == null ? void 0 : f.content) == null ? void 0 : c[0]) == null ? void 0 : u.text;
1233
- if (a)
1234
- return JSON.parse(a);
1558
+ const t = await e.json();
1559
+ if (t.error)
1560
+ throw new Error(t.error.message);
1561
+ const n = (d = (s = (i = t.result) == null ? void 0 : i.content) == null ? void 0 : s[0]) == null ? void 0 : d.text;
1562
+ if (n)
1563
+ return JSON.parse(n);
1235
1564
  throw new Error("Invalid response from whoami");
1236
1565
  }
1237
- async function Q() {
1238
- const e = P("Starting authentication...").start();
1566
+ async function re() {
1567
+ const o = W("Starting authentication...").start();
1239
1568
  try {
1240
- e.text = "Registering OAuth client...";
1241
- const s = (await ft()).client_id, a = mt(), f = ut(a), c = he.randomBytes(16).toString("hex");
1242
- e.text = "Waiting for authorization...";
1243
- const u = gt(c), w = new ke(`${X}/oauth/authorize`);
1244
- w.searchParams.set("response_type", "code"), w.searchParams.set("client_id", s), w.searchParams.set("redirect_uri", Se), w.searchParams.set("code_challenge", f), w.searchParams.set("code_challenge_method", "S256"), w.searchParams.set("state", c), e.stop(), console.log(`
1569
+ o.text = "Registering OAuth client...";
1570
+ const t = (await kt()).client_id, n = Ft(), i = jt(n), s = Ie.randomBytes(16).toString("hex");
1571
+ o.text = "Waiting for authorization...";
1572
+ const d = Nt(s), w = new ze(`${se}/oauth/authorize`);
1573
+ w.searchParams.set("response_type", "code"), w.searchParams.set("client_id", t), w.searchParams.set("redirect_uri", ke), w.searchParams.set("code_challenge", i), w.searchParams.set("code_challenge_method", "S256"), w.searchParams.set("state", s), o.stop(), console.log(`
1245
1574
  🌐 Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${w.toString()}
1246
- `), await Qe(w.toString());
1247
- const O = await u;
1248
- e.start("Exchanging authorization code...");
1249
- const m = await ht(O, s, a);
1250
- e.text = "Getting user info...";
1251
- const y = await wt(m.access_token), b = {
1575
+ `), await pt(w.toString());
1576
+ const M = await d;
1577
+ o.start("Exchanging authorization code...");
1578
+ const m = await _t(M, t, n);
1579
+ o.text = "Getting user info...";
1580
+ const p = await At(m.access_token), b = {
1252
1581
  accessToken: m.access_token,
1253
1582
  refreshToken: m.refresh_token,
1254
1583
  expiresAt: new Date(Date.now() + m.expires_in * 1e3).toISOString(),
1255
- clientId: s,
1256
- userId: y.userId,
1257
- userEmail: y.email
1584
+ clientId: t,
1585
+ userId: p.userId,
1586
+ userEmail: p.email
1258
1587
  };
1259
- return Ae(b), e.succeed(`Authenticated as ${y.email}`), b;
1260
- } catch (n) {
1261
- throw e.fail(`Authentication failed: ${n.message}`), n;
1588
+ return Qe(b), o.succeed(`Authenticated as ${p.email}`), b;
1589
+ } catch (e) {
1590
+ throw o.fail(`Authentication failed: ${e.message}`), e;
1262
1591
  }
1263
1592
  }
1264
- async function He() {
1265
- const e = we();
1266
- if (!e) {
1593
+ async function Xe() {
1594
+ const o = je();
1595
+ if (!o) {
1267
1596
  console.log("Not currently logged in.");
1268
1597
  return;
1269
1598
  }
1270
- De(), console.log(`✅ Logged out (was: ${e.userEmail})`);
1599
+ Ze(), console.log(`✅ Logged out (was: ${o.userEmail})`);
1271
1600
  }
1272
- async function vt() {
1273
- let e = we();
1274
- if (!e)
1601
+ async function Dt() {
1602
+ let o = je();
1603
+ if (!o)
1275
1604
  return console.log(`Not logged in. Starting authentication...
1276
- `), await Q();
1277
- if (!dt(e))
1278
- return e;
1279
- if (e.refreshToken) {
1280
- const n = P("Refreshing access token...").start();
1605
+ `), await re();
1606
+ if (!It(o))
1607
+ return o;
1608
+ if (o.refreshToken) {
1609
+ const e = W("Refreshing access token...").start();
1281
1610
  try {
1282
- const s = await yt(
1283
- e.refreshToken,
1284
- e.clientId
1611
+ const t = await Lt(
1612
+ o.refreshToken,
1613
+ o.clientId
1285
1614
  );
1286
- return e = {
1287
- ...e,
1288
- accessToken: s.access_token,
1289
- refreshToken: s.refresh_token,
1290
- expiresAt: new Date(Date.now() + s.expires_in * 1e3).toISOString()
1291
- }, Ae(e), n.succeed("Token refreshed"), e;
1615
+ return o = {
1616
+ ...o,
1617
+ accessToken: t.access_token,
1618
+ refreshToken: t.refresh_token,
1619
+ expiresAt: new Date(Date.now() + t.expires_in * 1e3).toISOString()
1620
+ }, Qe(o), e.succeed("Token refreshed"), o;
1292
1621
  } catch {
1293
- return n.warn("Token refresh failed, please log in again"), De(), await Q();
1622
+ return e.warn("Token refresh failed, please log in again"), Ze(), await re();
1294
1623
  }
1295
1624
  }
1296
1625
  return console.log(`Session expired. Please log in again.
1297
- `), await Q();
1626
+ `), await re();
1298
1627
  }
1299
- function St() {
1300
- return X;
1628
+ function Ht() {
1629
+ return se;
1301
1630
  }
1302
- const ce = "@myop/cli";
1303
- async function bt() {
1631
+ const ye = "@myop/cli";
1632
+ async function Ut() {
1304
1633
  try {
1305
- const e = await fetch(`https://registry.npmjs.org/${ce}/latest`);
1306
- return e.ok ? (await e.json()).version : null;
1634
+ const o = await fetch(`https://registry.npmjs.org/${ye}/latest`);
1635
+ return o.ok ? (await o.json()).version : null;
1307
1636
  } catch {
1308
1637
  return null;
1309
1638
  }
1310
1639
  }
1311
- function xt(e, n) {
1312
- const s = e.split(".").map(Number), a = n.split(".").map(Number);
1313
- for (let f = 0; f < Math.max(s.length, a.length); f++) {
1314
- const c = s[f] || 0, u = a[f] || 0;
1315
- if (c > u) return 1;
1316
- if (c < u) return -1;
1640
+ function Bt(o, e) {
1641
+ const t = o.split(".").map(Number), n = e.split(".").map(Number);
1642
+ for (let i = 0; i < Math.max(t.length, n.length); i++) {
1643
+ const s = t[i] || 0, d = n[i] || 0;
1644
+ if (s > d) return 1;
1645
+ if (s < d) return -1;
1317
1646
  }
1318
1647
  return 0;
1319
1648
  }
1320
- async function Ct(e) {
1321
- const n = P({
1649
+ async function Jt(o) {
1650
+ const e = W({
1322
1651
  text: "Checking for updates...",
1323
1652
  color: "cyan"
1324
- }).start(), s = await bt();
1325
- if (n.stop(), !s || xt(s, e) <= 0)
1653
+ }).start(), t = await Ut();
1654
+ if (e.stop(), !t || Bt(t, o) <= 0)
1326
1655
  return !1;
1327
1656
  console.log(`
1328
- 📦 New version available: ${e} → ${s}
1657
+ 📦 New version available: ${o} → ${t}
1329
1658
  `);
1330
- let a;
1659
+ let n;
1331
1660
  try {
1332
- a = await Ne({
1661
+ n = await Je({
1333
1662
  message: "Would you like to update now?",
1334
1663
  choices: [
1335
1664
  { name: "Yes, update now", value: !0 },
1336
1665
  { name: "No, continue with current version", value: !1 }
1337
1666
  ]
1338
1667
  });
1339
- } catch (f) {
1340
- throw f.name === "ExitPromptError" && (console.log(`
1668
+ } catch (i) {
1669
+ throw i.name === "ExitPromptError" && (console.log(`
1341
1670
 
1342
1671
  👋 Goodbye!
1343
- `), process.exit(0)), f;
1672
+ `), process.exit(0)), i;
1344
1673
  }
1345
- if (a) {
1346
- const f = P({
1347
- text: `Updating ${ce} to v${s}...`,
1674
+ if (n) {
1675
+ const i = W({
1676
+ text: `Updating ${ye} to v${t}...`,
1348
1677
  color: "green"
1349
1678
  }).start();
1350
1679
  try {
1351
- return ie(`npm install -g ${ce}@latest`, { stdio: "pipe" }), f.succeed(`Updated to v${s}`), console.log(`
1680
+ return fe(`npm install -g ${ye}@latest`, { stdio: "pipe" }), i.succeed(`Updated to v${t}`), console.log(`
1352
1681
  🔄 Restarting with new version...
1353
- `), Ke("myop", process.argv.slice(2), {
1682
+ `), ct("myop", process.argv.slice(2), {
1354
1683
  stdio: "inherit",
1355
1684
  shell: !0
1356
- }).on("close", (u) => {
1357
- process.exit(u || 0);
1685
+ }).on("close", (d) => {
1686
+ process.exit(d || 0);
1358
1687
  }), !0;
1359
1688
  } catch {
1360
- return f.fail("Update failed"), console.log(`
1361
- You can manually update by running: npm install -g ${ce}@latest
1689
+ return i.fail("Update failed"), console.log(`
1690
+ You can manually update by running: npm install -g ${ye}@latest
1362
1691
  `), !1;
1363
1692
  }
1364
1693
  }
1365
1694
  return !1;
1366
1695
  }
1367
- const $t = (e) => new Promise((n) => setTimeout(n, e));
1368
- d.executionPath = process.cwd();
1369
- const de = (e = !1) => {
1370
- const n = d.program.getOptionValue("verbose");
1371
- n || (console.info = () => {
1372
- }), console.info("📝 verbose mode on"), d.options = {
1373
- configPath: d.program.getOptionValue("config"),
1374
- verbose: n
1696
+ const zt = (o) => new Promise((e) => setTimeout(e, o)), qe = (o = ".", e = 3, t = 0) => {
1697
+ const n = [];
1698
+ if (t > e) return n;
1699
+ try {
1700
+ const i = H.readdirSync(o, { withFileTypes: !0 });
1701
+ for (const s of i) {
1702
+ const d = ee.join(o, s.name);
1703
+ if (s.isDirectory()) {
1704
+ if (s.name === "node_modules" || s.name === ".git" || s.name === "dist" || s.name.startsWith("."))
1705
+ continue;
1706
+ n.push(...qe(d, e, t + 1));
1707
+ } else if (s.name === "myop.config.json")
1708
+ try {
1709
+ const w = H.readFileSync(d, "utf-8"), M = JSON.parse(w);
1710
+ n.push({
1711
+ path: o,
1712
+ configPath: d,
1713
+ name: M.name || M.componentName || ee.basename(o),
1714
+ componentId: M.componentId || null,
1715
+ config: M
1716
+ });
1717
+ } catch {
1718
+ }
1719
+ }
1720
+ } catch {
1721
+ }
1722
+ return n;
1723
+ };
1724
+ h.executionPath = process.cwd();
1725
+ const be = (o = !1) => {
1726
+ const e = h.program.getOptionValue("verbose");
1727
+ e || (console.info = () => {
1728
+ }), console.info("📝 verbose mode on"), h.options = {
1729
+ configPath: h.program.getOptionValue("config"),
1730
+ verbose: e
1375
1731
  };
1376
1732
  try {
1377
- return d.myopConfig = et(d.options.configPath), { configFound: !0 };
1378
- } catch (s) {
1379
- if (e) {
1733
+ return h.myopConfig = gt(h.options.configPath), { configFound: !0 };
1734
+ } catch (t) {
1735
+ if (o) {
1380
1736
  console.info(`
1381
- ⚠️ failed read config file from ${d.options.configPath}, trying to create new one`);
1737
+ ⚠️ failed read config file from ${h.options.configPath}, trying to create new one`);
1382
1738
  try {
1383
- const a = {
1739
+ const n = {
1384
1740
  author: "@myop-cli",
1385
1741
  flows: []
1386
1742
  };
1387
- return ye(d.options.configPath, a), d.myopConfig = a, { configFound: !0 };
1743
+ return Oe(h.options.configPath, n), h.myopConfig = n, { configFound: !0 };
1388
1744
  } catch {
1389
- return console.info("Error details :", s), { configFound: !1, error: s };
1745
+ return console.info("Error details :", t), { configFound: !1, error: t };
1390
1746
  }
1391
1747
  } else
1392
- return console.info("Error details :", s), { configFound: !1, error: s };
1748
+ return console.info("Error details :", t), { configFound: !1, error: t };
1393
1749
  }
1394
1750
  };
1395
1751
  [
1396
- new fe(),
1397
- ...at
1752
+ new Re(),
1753
+ ...St
1398
1754
  ];
1399
- const Mt = "0.1.20";
1400
- d.program = new Ye();
1401
- d.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(Mt);
1402
- d.program.addOption(new le("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
1403
- d.program.addOption(new le("-h, --help", "Show helpful information"));
1404
- d.program.addOption(new le("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
1405
- d.program.addOption(new le("--ci", "CI mode: print status info (version, config, auth) as JSON and exit without prompts"));
1406
- d.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((e, n) => {
1407
- de(!0), console.info("adding ", e, n, d.options.configPath), e === "flow" && Pe._action(n), process.exit();
1755
+ const Wt = "0.1.22";
1756
+ h.program = new lt();
1757
+ h.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(Wt);
1758
+ h.program.addOption(new le("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
1759
+ h.program.addOption(new le("-h, --help", "Show helpful information"));
1760
+ h.program.addOption(new le("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
1761
+ h.program.addOption(new le("--ci", "CI mode: print status info (version, config, auth) as JSON and exit without prompts"));
1762
+ h.program.addOption(new le("-m, --monorepo", "Monorepo mode: scan for all myop.config.json files in nested directories"));
1763
+ h.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((o, e) => {
1764
+ be(!0), console.info("adding ", o, e, h.options.configPath), o === "flow" && Ge._action(e), process.exit();
1408
1765
  });
1409
- d.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((e, n) => {
1410
- de(), console.info("removing ", e, n, d.options.configPath), e === "flow" && Re._action(n), process.exit();
1766
+ h.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((o, e) => {
1767
+ be(), console.info("removing ", o, e, h.options.configPath), o === "flow" && Ye._action(e), process.exit();
1411
1768
  });
1412
- d.program.command("install").description("Install Myop assets").action(async () => {
1413
- de(), await Te.action();
1769
+ h.program.command("install").description("Install Myop assets").action(async () => {
1770
+ be(), await Ve.action();
1414
1771
  });
1415
- d.program.command("login").description("Authenticate with Myop platform").action(async () => {
1772
+ h.program.command("login").description("Authenticate with Myop platform").action(async () => {
1416
1773
  try {
1417
- await Q();
1418
- } catch (e) {
1419
- console.error("Login failed:", e.message), process.exit(1);
1774
+ await re();
1775
+ } catch (o) {
1776
+ console.error("Login failed:", o.message), process.exit(1);
1420
1777
  }
1421
1778
  process.exit(0);
1422
1779
  });
1423
- d.program.command("logout").description("Clear stored credentials").action(async () => {
1424
- await He(), process.exit(0);
1780
+ h.program.command("logout").description("Clear stored credentials").action(async () => {
1781
+ await Xe(), process.exit(0);
1425
1782
  });
1426
- d.program.command("whoami").description("Show current authenticated user").action(async () => {
1427
- const e = ve();
1428
- e && e.email ? console.log(`Logged in as: ${e.email}`) : console.log("Not logged in. Run `myop login` to authenticate."), process.exit(0);
1783
+ h.program.command("whoami").description("Show current authenticated user").action(async () => {
1784
+ const o = ve();
1785
+ o && o.email ? console.log(`Logged in as: ${o.email}`) : console.log("Not logged in. Run `myop login` to authenticate."), process.exit(0);
1429
1786
  });
1430
- d.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (e) => {
1431
- var I, v, E, F, W, S;
1432
- const n = d.program.getOptionValue("config") || "./myop.config.json", s = await import("fs"), { execSync: a } = await import("child_process"), f = await import("path");
1433
- let c = {};
1434
- if (s.existsSync(n))
1787
+ h.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (o) => {
1788
+ var u, v, x, $, _, D;
1789
+ const e = h.program.getOptionValue("config") || "./myop.config.json", t = await import("fs"), { execSync: n } = await import("child_process"), i = await import("path");
1790
+ let s = {};
1791
+ if (t.existsSync(e))
1435
1792
  try {
1436
- const h = s.readFileSync(n, "utf-8");
1437
- c = JSON.parse(h);
1438
- const C = c.name || c.componentName;
1439
- console.log(`📋 Found config: ${C || "Unnamed component"}`), c.componentId && console.log(` Component ID: ${c.componentId}`);
1440
- } catch (h) {
1441
- console.error(`⚠️ Failed to parse ${n}:`, h.message);
1793
+ const g = t.readFileSync(e, "utf-8");
1794
+ s = JSON.parse(g);
1795
+ const P = s.name || s.componentName;
1796
+ console.log(`📋 Found config: ${P || "Unnamed component"}`), s.componentId && console.log(` Component ID: ${s.componentId}`);
1797
+ } catch (g) {
1798
+ console.error(`⚠️ Failed to parse ${e}:`, g.message);
1442
1799
  }
1443
1800
  else
1444
1801
  console.log("⚠️ No myop.config.json found. A new component will be created.");
1445
- if (!e.skipBuild) {
1446
- const h = P("Building project...").start();
1447
- try {
1448
- a("npm run build", { stdio: "pipe" }), h.succeed("Build completed");
1449
- } catch (C) {
1450
- h.fail("Build failed"), console.error(C.message), process.exit(1);
1451
- }
1802
+ if (!o.skipBuild) {
1803
+ const { exec: g } = await import("child_process");
1804
+ let P = { hasTriedPlatformFix: !1, hasTriedInstall: !1 };
1805
+ const E = (I = !1) => new Promise((L) => {
1806
+ const Z = W(I ? "Retrying build..." : "Building project...").start();
1807
+ g("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (U, O, V) => {
1808
+ if (!U) {
1809
+ Z.succeed("Build completed"), L(!0);
1810
+ return;
1811
+ }
1812
+ if (Z.fail("Build failed"), !P.hasTriedPlatformFix && !P.hasTriedInstall) {
1813
+ const R = await Ke(U, O, V, g, P);
1814
+ if (P = { ...P, ...R }, R.handled) {
1815
+ const G = await E(!0);
1816
+ L(G);
1817
+ return;
1818
+ }
1819
+ }
1820
+ console.error(U.message), L(!1);
1821
+ });
1822
+ });
1823
+ await E() || process.exit(1);
1452
1824
  }
1453
- const u = "./dist/index.html";
1454
- s.existsSync(u) || (console.error("❌ Error: ./dist/index.html not found"), console.log(" Make sure your build outputs to ./dist/index.html"), process.exit(1));
1825
+ const d = "./dist/index.html";
1826
+ t.existsSync(d) || (console.error("❌ Error: ./dist/index.html not found"), console.log(" Make sure your build outputs to ./dist/index.html"), process.exit(1));
1455
1827
  let w;
1456
1828
  try {
1457
- w = await vt();
1458
- } catch (h) {
1459
- console.error("❌ Authentication failed:", h.message), process.exit(1);
1829
+ w = await Dt();
1830
+ } catch (g) {
1831
+ console.error("❌ Authentication failed:", g.message), process.exit(1);
1460
1832
  }
1461
- const O = St();
1462
- let m = P("Requesting upload URL...").start(), y;
1833
+ const M = Ht();
1834
+ let m = W("Requesting upload URL...").start(), p;
1463
1835
  try {
1464
- const h = await fetch(`${O}/mcp`, {
1836
+ const g = await fetch(`${M}/mcp`, {
1465
1837
  method: "POST",
1466
1838
  headers: {
1467
1839
  "Content-Type": "application/json",
@@ -1474,59 +1846,59 @@ d.program.command("sync").description("Build and upload component to Myop platfo
1474
1846
  params: {
1475
1847
  name: "upload_component",
1476
1848
  arguments: {
1477
- name: c.name || c.componentName || f.default.basename(process.cwd()),
1478
- componentId: c.componentId || void 0,
1479
- organization: c.organization || void 0
1849
+ name: s.name || s.componentName || i.default.basename(process.cwd()),
1850
+ componentId: s.componentId || void 0,
1851
+ organization: s.organization || void 0
1480
1852
  }
1481
1853
  }
1482
1854
  })
1483
1855
  });
1484
- if (!h.ok)
1485
- throw new Error(`Server returned ${h.status}`);
1486
- const C = await h.json();
1487
- if (C.error)
1488
- throw new Error(C.error.message);
1489
- const A = (E = (v = (I = C.result) == null ? void 0 : I.content) == null ? void 0 : v[0]) == null ? void 0 : E.text;
1490
- if (y = JSON.parse(A), !y.success)
1491
- throw new Error(y.error);
1856
+ if (!g.ok)
1857
+ throw new Error(`Server returned ${g.status}`);
1858
+ const P = await g.json();
1859
+ if (P.error)
1860
+ throw new Error(P.error.message);
1861
+ const E = (x = (v = (u = P.result) == null ? void 0 : u.content) == null ? void 0 : v[0]) == null ? void 0 : x.text;
1862
+ if (p = JSON.parse(E), !p.success)
1863
+ throw new Error(p.error);
1492
1864
  m.succeed("Upload URL obtained");
1493
- } catch (h) {
1494
- m.fail("Failed to get upload URL"), console.error(" ", h.message), process.exit(1);
1865
+ } catch (g) {
1866
+ m.fail("Failed to get upload URL"), console.error(" ", g.message), process.exit(1);
1495
1867
  }
1496
- m = P("Uploading component...").start();
1868
+ m = W("Uploading component...").start();
1497
1869
  try {
1498
- const h = s.readFileSync(u, "utf-8");
1499
- let C;
1500
- const A = y.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
1501
- if (A)
1502
- C = A[1];
1870
+ const g = t.readFileSync(d, "utf-8");
1871
+ let P;
1872
+ const E = p.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
1873
+ if (E)
1874
+ P = E[1];
1503
1875
  else {
1504
- const V = y.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
1505
- if (V)
1506
- C = V[1];
1876
+ const I = p.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
1877
+ if (I)
1878
+ P = I[1];
1507
1879
  else
1508
- throw new Error("Could not parse presigned URL from: " + y.curlCommand);
1880
+ throw new Error("Could not parse presigned URL from: " + p.curlCommand);
1509
1881
  }
1510
- console.info("Uploading to:", C.substring(0, 100) + "...");
1511
- const D = await fetch(C, {
1882
+ console.info("Uploading to:", P.substring(0, 100) + "...");
1883
+ const C = await fetch(P, {
1512
1884
  method: "PUT",
1513
1885
  headers: {
1514
1886
  "Content-Type": "text/html"
1515
1887
  },
1516
- body: h
1888
+ body: g
1517
1889
  });
1518
- if (!D.ok) {
1519
- const V = await D.text();
1520
- throw new Error(`Upload failed with status ${D.status}: ${V}`);
1890
+ if (!C.ok) {
1891
+ const I = await C.text();
1892
+ throw new Error(`Upload failed with status ${C.status}: ${I}`);
1521
1893
  }
1522
1894
  m.succeed("Component uploaded");
1523
- } catch (h) {
1524
- m.fail("Upload failed"), console.error(" ", h.message), h.cause && console.error(" Cause:", h.cause), process.exit(1);
1895
+ } catch (g) {
1896
+ m.fail("Upload failed"), console.error(" ", g.message), g.cause && console.error(" Cause:", g.cause), process.exit(1);
1525
1897
  }
1526
- m = P("Confirming upload...").start();
1898
+ m = W("Confirming upload...").start();
1527
1899
  let b;
1528
1900
  try {
1529
- const h = await fetch(`${O}/mcp`, {
1901
+ const g = await fetch(`${M}/mcp`, {
1530
1902
  method: "POST",
1531
1903
  headers: {
1532
1904
  "Content-Type": "application/json",
@@ -1539,116 +1911,116 @@ d.program.command("sync").description("Build and upload component to Myop platfo
1539
1911
  params: {
1540
1912
  name: "confirm_upload",
1541
1913
  arguments: {
1542
- uploadId: y.uploadId
1914
+ uploadId: p.uploadId
1543
1915
  }
1544
1916
  }
1545
1917
  })
1546
1918
  });
1547
- if (!h.ok)
1548
- throw new Error(`Server returned ${h.status}`);
1549
- const C = await h.json();
1550
- if (C.error)
1551
- throw new Error(C.error.message);
1552
- const A = (S = (W = (F = C.result) == null ? void 0 : F.content) == null ? void 0 : W[0]) == null ? void 0 : S.text;
1553
- if (b = JSON.parse(A), !b.success)
1919
+ if (!g.ok)
1920
+ throw new Error(`Server returned ${g.status}`);
1921
+ const P = await g.json();
1922
+ if (P.error)
1923
+ throw new Error(P.error.message);
1924
+ const E = (D = (_ = ($ = P.result) == null ? void 0 : $.content) == null ? void 0 : _[0]) == null ? void 0 : D.text;
1925
+ if (b = JSON.parse(E), !b.success)
1554
1926
  throw new Error(b.error);
1555
1927
  m.succeed("Upload confirmed");
1556
- } catch (h) {
1557
- m.fail("Confirmation failed"), console.error(" ", h.message), process.exit(1);
1928
+ } catch (g) {
1929
+ m.fail("Confirmation failed"), console.error(" ", g.message), process.exit(1);
1558
1930
  }
1559
- if (b.isNewComponent || !c.componentId) {
1560
- c.componentId = b.componentId, c.organization = b.orgId, c.name || (c.name = b.componentName);
1931
+ if (b.isNewComponent || !s.componentId) {
1932
+ s.componentId = b.componentId, s.organization = b.orgId, s.name || (s.name = b.componentName);
1561
1933
  try {
1562
- s.writeFileSync(n, JSON.stringify(c, null, 2)), console.log(`
1563
- 📝 Updated ${n} with componentId`);
1564
- } catch (h) {
1934
+ t.writeFileSync(e, JSON.stringify(s, null, 2)), console.log(`
1935
+ 📝 Updated ${e} with componentId`);
1936
+ } catch (g) {
1565
1937
  console.log(`
1566
- ⚠️ Could not update ${n}: ${h.message}`), console.log(` Please add componentId: "${b.componentId}" manually`);
1938
+ ⚠️ Could not update ${e}: ${g.message}`), console.log(` Please add componentId: "${b.componentId}" manually`);
1567
1939
  }
1568
1940
  }
1569
1941
  console.log(`
1570
1942
  ✅ Sync completed successfully!`), console.log(` Component: ${b.componentName}`), console.log(` Dashboard: ${b.dashboardUrl}`), process.exit(0);
1571
1943
  });
1572
- d.program.command("dev").description("Start development server with file watching").action(Fe);
1573
- const Ot = () => {
1944
+ h.program.command("dev").description("Start development server with file watching").action(Fe);
1945
+ const Vt = () => {
1574
1946
  try {
1575
- ie("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1947
+ fe("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1576
1948
  } catch {
1577
1949
  return { gitNotInstalled: !0 };
1578
1950
  }
1579
1951
  try {
1580
- ie("git rev-parse --git-dir", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1952
+ fe("git rev-parse --git-dir", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
1581
1953
  } catch {
1582
1954
  return { notARepo: !0 };
1583
1955
  }
1584
1956
  try {
1585
- const e = ie("git diff --stat HEAD -- . 2>/dev/null || git diff --stat -- . 2>/dev/null", {
1957
+ const o = fe("git diff --stat HEAD -- . 2>/dev/null || git diff --stat -- . 2>/dev/null", {
1586
1958
  encoding: "utf-8",
1587
1959
  stdio: ["pipe", "pipe", "pipe"]
1588
1960
  }).trim();
1589
- if (!e)
1961
+ if (!o)
1590
1962
  return {
1591
1963
  files: 0,
1592
1964
  insertions: 0,
1593
1965
  deletions: 0
1594
1966
  };
1595
- const n = e.split(`
1596
- `), s = n[n.length - 1], a = s.match(/(\d+) insertion/), f = s.match(/(\d+) deletion/), c = s.match(/(\d+) file/);
1967
+ const e = o.split(`
1968
+ `), t = e[e.length - 1], n = t.match(/(\d+) insertion/), i = t.match(/(\d+) deletion/), s = t.match(/(\d+) file/);
1597
1969
  return {
1598
- files: c ? parseInt(c[1]) : 0,
1599
- insertions: a ? parseInt(a[1]) : 0,
1600
- deletions: f ? parseInt(f[1]) : 0
1970
+ files: s ? parseInt(s[1]) : 0,
1971
+ insertions: n ? parseInt(n[1]) : 0,
1972
+ deletions: i ? parseInt(i[1]) : 0
1601
1973
  };
1602
1974
  } catch {
1603
1975
  return null;
1604
1976
  }
1605
- }, z = async (e = !1, n = !1) => {
1606
- var y, b, I;
1607
- const s = ve(), a = !!(s != null && s.email), f = ((y = d.myopConfig) == null ? void 0 : y.name) || ((b = d.myopConfig) == null ? void 0 : b.componentName), c = (I = d.myopConfig) == null ? void 0 : I.componentId, u = Ot();
1977
+ }, q = async (o = !1, e = !1) => {
1978
+ var p, b, u;
1979
+ const t = ve(), n = !!(t != null && t.email), i = ((p = h.myopConfig) == null ? void 0 : p.name) || ((b = h.myopConfig) == null ? void 0 : b.componentName), s = (u = h.myopConfig) == null ? void 0 : u.componentId, d = Vt();
1608
1980
  console.log(`
1609
1981
  ┌─────────────────────────────────────────────────┐`), console.log("│ │"), console.log("│ Welcome to Myop CLI - Remote UI Made Easy │"), console.log("│ │"), console.log(`└─────────────────────────────────────────────────┘
1610
- `), e && f ? (console.log(` Component: ${f}`), c ? (console.log(` ID: ${c}`), console.log(` Dashboard: https://dashboard.myop.dev/dashboard/2.0/component/${c}`)) : console.log(" ID: (not yet pushed)")) : console.log(" Component: No myop.config.json found"), console.log(` User: ${a ? s.email : "Not logged in"}`), u != null && u.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")) : u != null && u.notARepo ? console.log(" Changes: Not a git repository") : u && (u.insertions > 0 || u.deletions > 0) ? console.log(` Changes: ${u.files} file${u.files !== 1 ? "s" : ""} | \x1B[32m+${u.insertions}\x1B[0m \x1B[31m-${u.deletions}\x1B[0m`) : u && console.log(" Changes: No uncommitted changes"), console.log("");
1611
- const O = [
1982
+ `), o && i ? (console.log(` Component: ${i}`), s ? (console.log(` ID: ${s}`), console.log(` Dashboard: https://dashboard.myop.dev/dashboard/2.0/component/${s}`)) : console.log(" ID: (not yet pushed)")) : console.log(" Component: No myop.config.json found"), console.log(` User: ${n ? t.email : "Not logged in"}`), d != null && d.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")) : d != null && d.notARepo ? console.log(" Changes: Not a git repository") : d && (d.insertions > 0 || d.deletions > 0) ? console.log(` Changes: ${d.files} file${d.files !== 1 ? "s" : ""} | \x1B[32m+${d.insertions}\x1B[0m \x1B[31m-${d.deletions}\x1B[0m`) : d && console.log(" Changes: No uncommitted changes"), console.log("");
1983
+ const M = [
1612
1984
  {
1613
1985
  emoji: "🚀",
1614
1986
  label: "Initialize new component",
1615
1987
  value: "init",
1616
1988
  help: "Creates myop.config.json in current directory",
1617
- disabled: e ? "(config already exists)" : !1
1989
+ disabled: o ? "(config already exists)" : !1
1618
1990
  },
1619
1991
  {
1620
1992
  emoji: "🛠️ ",
1621
- label: f ? `Start dev mode for "${f}"` : "Start dev mode",
1993
+ label: i ? `Start dev mode for "${i}"` : "Start dev mode",
1622
1994
  value: "dev",
1623
1995
  help: "Starts dev server with HMR for instant preview of changes",
1624
- disabled: e ? !1 : "(no config file)"
1996
+ disabled: o ? !1 : "(no config file)"
1625
1997
  },
1626
1998
  {
1627
1999
  emoji: "📦",
1628
- label: f ? `Push "${f}"` : "Push component",
2000
+ label: i ? `Push "${i}"` : "Push component",
1629
2001
  value: "sync",
1630
2002
  help: "Builds project & uploads dist/index.html to Myop",
1631
- disabled: e ? a ? !1 : "(login required)" : "(no config file)"
2003
+ disabled: o ? n ? !1 : "(login required)" : "(no config file)"
1632
2004
  }
1633
2005
  ].map((v) => ({
1634
- name: n && !v.disabled ? `${v.emoji} ${v.label}
2006
+ name: e && !v.disabled ? `${v.emoji} ${v.label}
1635
2007
  ${v.help}` : `${v.emoji} ${v.label}`,
1636
2008
  value: v.value,
1637
2009
  disabled: v.disabled
1638
2010
  }));
1639
- O.push(
1640
- new fe(),
2011
+ M.push(
2012
+ new Re(),
1641
2013
  {
1642
- name: n && a ? `🔓 Logout (${s.email})
1643
- Clears stored credentials from this machine` : n && !a ? `🔐 Login to Myop
1644
- Opens browser to authenticate with Myop` : a ? `🔓 Logout (${s.email})` : "🔐 Login to Myop",
1645
- value: a ? "logout" : "login"
2014
+ name: e && n ? `🔓 Logout (${t.email})
2015
+ Clears stored credentials from this machine` : e && !n ? `🔐 Login to Myop
2016
+ Opens browser to authenticate with Myop` : n ? `🔓 Logout (${t.email})` : "🔐 Login to Myop",
2017
+ value: n ? "logout" : "login"
1646
2018
  },
1647
2019
  {
1648
- name: n ? "📖 Hide help" : "📖 Show help",
2020
+ name: e ? "📖 Hide help" : "📖 Show help",
1649
2021
  value: "help"
1650
2022
  },
1651
- new fe(),
2023
+ new Re(),
1652
2024
  {
1653
2025
  name: "👋 Exit",
1654
2026
  value: "exit"
@@ -1656,9 +2028,9 @@ const Ot = () => {
1656
2028
  );
1657
2029
  let m;
1658
2030
  try {
1659
- m = await Ne({
2031
+ m = await Je({
1660
2032
  message: "What would you like to do?",
1661
- choices: O
2033
+ choices: M
1662
2034
  });
1663
2035
  } catch (v) {
1664
2036
  throw v.name === "ExitPromptError" && (console.log(`
@@ -1668,7 +2040,7 @@ const Ot = () => {
1668
2040
  }
1669
2041
  switch (m) {
1670
2042
  case "init":
1671
- await It();
2043
+ await Qt();
1672
2044
  break;
1673
2045
  case "sync":
1674
2046
  console.log(`
@@ -1679,37 +2051,93 @@ Running sync...
1679
2051
  v("node " + process.argv[1] + " sync", { stdio: "inherit" });
1680
2052
  } catch {
1681
2053
  }
1682
- await z(!0, n);
2054
+ await q(!0, e);
1683
2055
  break;
1684
2056
  case "dev":
1685
2057
  await Fe();
1686
2058
  break;
1687
2059
  case "login":
1688
2060
  try {
1689
- await Q(), console.log(`
1690
- `), await z(e, n);
1691
- } catch (E) {
1692
- console.error("Login failed:", E.message), await z(e, n);
2061
+ await re(), console.log(`
2062
+ `), await q(o, e);
2063
+ } catch (x) {
2064
+ console.error("Login failed:", x.message), await q(o, e);
1693
2065
  }
1694
2066
  break;
1695
2067
  case "logout":
1696
- await He(), console.log(`
1697
- `), await z(e, n);
2068
+ await Xe(), console.log(`
2069
+ `), await q(o, e);
1698
2070
  break;
1699
2071
  case "help":
1700
- await z(e, !n);
2072
+ await q(o, !e);
1701
2073
  break;
1702
2074
  case "exit":
1703
2075
  process.exit(0);
1704
2076
  }
1705
- }, It = async () => {
1706
- const { input: e, select: n } = await import("@inquirer/prompts"), s = await import("fs"), f = (await import("path")).default.basename(process.cwd());
1707
- let c, u;
2077
+ }, we = ".myop-monorepo.json", Gt = () => {
1708
2078
  try {
1709
- c = await e({
2079
+ const o = H.readFileSync(we, "utf-8");
2080
+ return JSON.parse(o);
2081
+ } catch {
2082
+ return null;
2083
+ }
2084
+ }, Yt = (o) => {
2085
+ try {
2086
+ const e = {
2087
+ selectedComponents: o,
2088
+ lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
2089
+ };
2090
+ H.writeFileSync(we, JSON.stringify(e, null, 2));
2091
+ } catch {
2092
+ }
2093
+ }, Kt = async () => {
2094
+ const o = ve(), e = !!(o != null && o.email);
2095
+ console.log(`
2096
+ ┌─────────────────────────────────────────────────┐`), console.log("│ │"), console.log("│ Myop CLI - Monorepo Mode │"), console.log("│ │"), console.log(`└─────────────────────────────────────────────────┘
2097
+ `);
2098
+ const t = W("Scanning for components...").start(), n = qe(".");
2099
+ t.stop(), n.length === 0 && (console.log(` ⚠️ No myop.config.json files found in this directory or subdirectories.
2100
+ `), console.log(" Run `myop` without -m flag to initialize a single component.\n"), process.exit(0));
2101
+ const i = Gt(), s = (i == null ? void 0 : i.selectedComponents) || [], d = s.length > 0;
2102
+ console.log(` Found ${n.length} component${n.length > 1 ? "s" : ""}:
2103
+ `), n.forEach((u, v) => {
2104
+ const x = u.componentId ? "✅" : "⚪", $ = u.componentId ? u.componentId.substring(0, 8) + "..." : "(not pushed)";
2105
+ console.log(` ${x} ${u.name}`), console.log(` Path: ${u.path}`), console.log(` ID: ${$}`), console.log("");
2106
+ }), console.log(` User: ${e ? o.email : "Not logged in"}`), d && console.log(` 📋 Using saved selection from ${we}`), console.log("");
2107
+ const { checkbox: w } = await import("@inquirer/prompts"), M = n.map((u) => ({
2108
+ name: `${u.name} (${u.path})`,
2109
+ value: u.path,
2110
+ checked: d ? s.includes(u.path) : !0
2111
+ }));
2112
+ let m;
2113
+ try {
2114
+ m = await w({
2115
+ message: "Select components to start in dev mode:",
2116
+ choices: M
2117
+ });
2118
+ } catch (u) {
2119
+ throw u.name === "ExitPromptError" && (console.log(`
2120
+
2121
+ 👋 Goodbye!
2122
+ `), process.exit(0)), u;
2123
+ }
2124
+ m.length === 0 && (console.log(`
2125
+ ⚠️ No components selected.
2126
+ `), process.exit(0)), Yt(m), console.log(`
2127
+ 💾 Selection saved to ${we}`);
2128
+ const p = n.filter((u) => m.includes(u.path));
2129
+ console.log(`🚀 Starting dev mode for ${p.length} component${p.length > 1 ? "s" : ""}...
2130
+ `);
2131
+ const { monorepoDevCommand: b } = await Promise.resolve().then(() => Tt);
2132
+ await b(p);
2133
+ }, Qt = async () => {
2134
+ const { input: o, select: e } = await import("@inquirer/prompts"), t = await import("fs"), i = (await import("path")).default.basename(process.cwd());
2135
+ let s, d;
2136
+ try {
2137
+ s = await o({
1710
2138
  message: "Component name:",
1711
- default: f
1712
- }), u = await n({
2139
+ default: i
2140
+ }), d = await e({
1713
2141
  message: "Component type:",
1714
2142
  choices: [
1715
2143
  { name: "📄 HTML", value: "html", description: "Plain HTML/JS/CSS component" },
@@ -1725,16 +2153,16 @@ Running sync...
1725
2153
  `), process.exit(0)), m;
1726
2154
  }
1727
2155
  const w = {
1728
- name: c,
1729
- type: u,
2156
+ name: s,
2157
+ type: d,
1730
2158
  author: "@myop-cli",
1731
2159
  HMR: !0
1732
- }, O = d.program.getOptionValue("config") || "./myop.config.json";
2160
+ }, M = h.program.getOptionValue("config") || "./myop.config.json";
1733
2161
  try {
1734
- s.writeFileSync(O, JSON.stringify(w, null, 2)), console.log(`
1735
- ✅ Created ${O}`);
2162
+ t.writeFileSync(M, JSON.stringify(w, null, 2)), console.log(`
2163
+ ✅ Created ${M}`);
1736
2164
  const m = {
1737
- name: c.toLowerCase().replace(/\s+/g, "-"),
2165
+ name: s.toLowerCase().replace(/\s+/g, "-"),
1738
2166
  version: "1.0.0",
1739
2167
  type: "module",
1740
2168
  scripts: {
@@ -1745,7 +2173,7 @@ Running sync...
1745
2173
  esbuild: "^0.24.0"
1746
2174
  }
1747
2175
  };
1748
- s.writeFileSync("package.json", JSON.stringify(m, null, 2)), console.log("✅ Created package.json"), s.mkdirSync("src/modules", { recursive: !0 }), s.mkdirSync("src/styles", { recursive: !0 }), s.writeFileSync("build.js", `import * as esbuild from 'esbuild';
2176
+ t.writeFileSync("package.json", JSON.stringify(m, null, 2)), console.log("✅ Created package.json"), t.mkdirSync("src/modules", { recursive: !0 }), t.mkdirSync("src/styles", { recursive: !0 }), t.writeFileSync("build.js", `import * as esbuild from 'esbuild';
1749
2177
  import fs from 'fs';
1750
2178
  import path from 'path';
1751
2179
 
@@ -1830,20 +2258,20 @@ console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS
1830
2258
  <head>
1831
2259
  <meta charset="UTF-8">
1832
2260
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
1833
- <title>${c}</title>
2261
+ <title>${s}</title>
1834
2262
  <link rel="stylesheet" href="./src/styles/index.css">
1835
2263
  </head>
1836
2264
  <body>
1837
2265
  <div id="app">
1838
- <h1>${c}</h1>
2266
+ <h1>${s}</h1>
1839
2267
  <p>Your Myop component is ready!</p>
1840
2268
  </div>
1841
2269
  <script type="module" src="./src/index.js"><\/script>
1842
2270
  </body>
1843
2271
  </html>
1844
2272
  `;
1845
- s.writeFileSync("index.html", b), console.log("✅ Created index.html");
1846
- const I = `// ${c} - Entry Point
2273
+ t.writeFileSync("index.html", b), console.log("✅ Created index.html");
2274
+ const u = `// ${s} - Entry Point
1847
2275
  import { init } from './modules/app.js';
1848
2276
  import { setupMyopInterface } from './modules/myop.js';
1849
2277
 
@@ -1852,16 +2280,16 @@ document.addEventListener('DOMContentLoaded', () => {
1852
2280
  setupMyopInterface();
1853
2281
  });
1854
2282
  `;
1855
- s.writeFileSync("src/index.js", I), console.log("✅ Created src/index.js");
1856
- const v = `// ${c} - Main Application Logic
2283
+ t.writeFileSync("src/index.js", u), console.log("✅ Created src/index.js");
2284
+ const v = `// ${s} - Main Application Logic
1857
2285
 
1858
2286
  export function init() {
1859
- console.log('${c} loaded');
2287
+ console.log('${s} loaded');
1860
2288
 
1861
2289
  // Your component logic here
1862
2290
  }
1863
2291
  `;
1864
- s.writeFileSync("src/modules/app.js", v), console.log("✅ Created src/modules/app.js"), s.writeFileSync("src/modules/myop.js", `// Myop Interface - Communication with host app
2292
+ t.writeFileSync("src/modules/app.js", v), console.log("✅ Created src/modules/app.js"), t.writeFileSync("src/modules/myop.js", `// Myop Interface - Communication with host app
1865
2293
 
1866
2294
  export function setupMyopInterface() {
1867
2295
  // Called when host app sends data to this component
@@ -1877,12 +2305,12 @@ export function setupMyopInterface() {
1877
2305
  };
1878
2306
  }
1879
2307
  `), console.log("✅ Created src/modules/myop.js");
1880
- const F = `/* ${c} - Styles Entry Point */
2308
+ const $ = `/* ${s} - Styles Entry Point */
1881
2309
  /* Add your CSS imports here - they will be auto-bundled */
1882
2310
  @import './main.css';
1883
2311
  `;
1884
- s.writeFileSync("src/styles/index.css", F), console.log("✅ Created src/styles/index.css");
1885
- const W = `/* ${c} - Main Styles */
2312
+ t.writeFileSync("src/styles/index.css", $), console.log("✅ Created src/styles/index.css");
2313
+ const _ = `/* ${s} - Main Styles */
1886
2314
 
1887
2315
  * {
1888
2316
  box-sizing: border-box;
@@ -1911,49 +2339,85 @@ p {
1911
2339
  line-height: 1.5;
1912
2340
  }
1913
2341
  `;
1914
- s.writeFileSync("src/styles/main.css", W), console.log("✅ Created src/styles/main.css"), console.log(`
2342
+ t.writeFileSync("src/styles/main.css", _), console.log("✅ Created src/styles/main.css"), t.writeFileSync(".gitignore", `node_modules/
2343
+ dist/
2344
+ .temp-entry.js
2345
+ .temp-styles.css
2346
+ .DS_Store
2347
+ `), console.log("✅ Created .gitignore");
2348
+ const g = await import("./index-DuEoKctW.js").then((E) => E.i), P = process.cwd();
2349
+ try {
2350
+ await g.init({ fs: t, dir: P });
2351
+ const E = [
2352
+ "myop.config.json",
2353
+ "package.json",
2354
+ "build.js",
2355
+ "index.html",
2356
+ ".gitignore",
2357
+ "src/index.js",
2358
+ "src/modules/app.js",
2359
+ "src/modules/myop.js",
2360
+ "src/styles/index.css",
2361
+ "src/styles/main.css"
2362
+ ];
2363
+ for (const C of E)
2364
+ await g.add({ fs: t, dir: P, filepath: C });
2365
+ await g.commit({
2366
+ fs: t,
2367
+ dir: P,
2368
+ message: "init",
2369
+ author: { name: "myop-cli", email: "cli@myop.dev" }
2370
+ }), console.log("✅ Initialized git repository");
2371
+ } catch (E) {
2372
+ console.log("⚠️ Failed to initialize git repository:", E.message);
2373
+ }
2374
+ console.log(`
1915
2375
  📦 Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
1916
- `), d.myopConfig = w, await z(!0);
2376
+ `), h.myopConfig = w, await q(!0);
1917
2377
  } catch (m) {
1918
2378
  console.error(`Failed to initialize component: ${m.message}`), process.exit(1);
1919
2379
  }
1920
2380
  };
1921
- d.program.command("default", { isDefault: !0 }).action(async () => {
1922
- if (d.program.getOptionValue("help") && (console.log(qe), process.exit()), d.program.getOptionValue("ci")) {
1923
- const u = await import("fs"), w = d.program.getOptionValue("config") || "./myop.config.json", O = d.program.version(), m = ve();
1924
- let y = { found: !1 };
2381
+ h.program.command("default", { isDefault: !0 }).action(async () => {
2382
+ if (h.program.getOptionValue("help") && (console.log(ut), process.exit()), h.program.getOptionValue("monorepo")) {
2383
+ await Kt();
2384
+ return;
2385
+ }
2386
+ if (h.program.getOptionValue("ci")) {
2387
+ const w = await import("fs"), M = h.program.getOptionValue("config") || "./myop.config.json", m = h.program.version(), p = ve();
2388
+ let b = { found: !1 };
1925
2389
  try {
1926
- if (u.existsSync(w)) {
1927
- const I = u.readFileSync(w, "utf-8"), v = JSON.parse(I);
1928
- y = {
2390
+ if (w.existsSync(M)) {
2391
+ const v = w.readFileSync(M, "utf-8"), x = JSON.parse(v);
2392
+ b = {
1929
2393
  found: !0,
1930
- path: w,
1931
- name: v.name || v.componentName || null,
1932
- componentId: v.componentId || null,
1933
- organization: v.organization || null
2394
+ path: M,
2395
+ name: x.name || x.componentName || null,
2396
+ componentId: x.componentId || null,
2397
+ organization: x.organization || null
1934
2398
  };
1935
2399
  }
1936
- } catch (I) {
1937
- y = { found: !1, error: I.message };
2400
+ } catch (v) {
2401
+ b = { found: !1, error: v.message };
1938
2402
  }
1939
- const b = {
1940
- version: O,
1941
- config: y,
2403
+ const u = {
2404
+ version: m,
2405
+ config: b,
1942
2406
  auth: {
1943
- loggedIn: !!(m != null && m.email),
1944
- email: (m == null ? void 0 : m.email) || null
2407
+ loggedIn: !!(p != null && p.email),
2408
+ email: (p == null ? void 0 : p.email) || null
1945
2409
  }
1946
2410
  };
1947
- console.log(JSON.stringify(b, null, 2)), process.exit(0);
2411
+ console.log(JSON.stringify(u, null, 2)), process.exit(0);
1948
2412
  }
1949
- let s = P({
2413
+ let n = W({
1950
2414
  text: "Loading Myop CLI...",
1951
2415
  color: "green"
1952
2416
  }).start();
1953
- const a = de();
1954
- await $t(500), s.stop();
1955
- const f = d.program.version();
1956
- await Ct(f) || await z(a.configFound);
2417
+ const i = be();
2418
+ await zt(500), n.stop();
2419
+ const s = h.program.version();
2420
+ await Jt(s) || await q(i.configFound);
1957
2421
  });
1958
- d.program.parse(process.argv);
1959
- d.program.opts();
2422
+ h.program.parse(process.argv);
2423
+ h.program.opts();