@myop/cli 0.1.20 β†’ 0.1.21

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