@myop/cli 0.1.6 β†’ 0.1.8

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,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import he from "ora";
3
- import { Separator as ye, select as ve } from "@inquirer/prompts";
4
- import { Command as we, Option as V } from "commander";
5
- import Q from "path";
6
- import ne from "fs";
7
- const Se = `
2
+ import be from "ora";
3
+ import { Separator as xe, select as $e } from "@inquirer/prompts";
4
+ import { Command as Me, Option as Z } from "commander";
5
+ import K from "path";
6
+ import re from "fs";
7
+ const Pe = `
8
8
  Usage: myop [OPTIONS] COMMAND [ARGS]...
9
9
 
10
10
  A powerful command-line interface for managing your Myop projects.
@@ -46,87 +46,87 @@ Examples:
46
46
  verbose: !1
47
47
  },
48
48
  myopConfig: null
49
- }, se = {
49
+ }, ae = {
50
50
  name: "πŸ“₯ Install Myop generated dependencies",
51
51
  value: "myopInstall",
52
52
  description: "Fetch and generates Myop dependencies. flows including components, refs and props.",
53
53
  action: async () => {
54
54
  console.info("installing... ");
55
- for (const s of a.myopConfig.flows) {
56
- const t = Q.join(a.executionPath, "/node_modules/@myop/flow-types/");
57
- console.info(`Generate flow at ${t}`), console.info(`Generated flow at ${t}`);
55
+ for (const i of a.myopConfig.flows) {
56
+ const s = K.join(a.executionPath, "/node_modules/@myop/flow-types/");
57
+ console.info(`Generate flow at ${s}`), console.info(`Generated flow at ${s}`);
58
58
  }
59
59
  process.exit();
60
60
  }
61
- }, Ce = (s) => {
62
- const t = Q.join(a.executionPath, s);
63
- console.info(`reading config file from: ${t}`);
64
- const m = ne.readFileSync(t, "utf8"), l = JSON.parse(m);
65
- return console.info("config file loaded, ", l), l;
66
- }, Z = (s, t) => {
67
- const m = Q.join(a.executionPath, s);
61
+ }, He = (i) => {
62
+ const s = K.join(a.executionPath, i);
63
+ console.info(`reading config file from: ${s}`);
64
+ const m = re.readFileSync(s, "utf8"), d = JSON.parse(m);
65
+ return console.info("config file loaded, ", d), d;
66
+ }, q = (i, s) => {
67
+ const m = K.join(a.executionPath, i);
68
68
  console.info(`writing config file to: ${m}`);
69
69
  try {
70
- const l = JSON.stringify(t, null, 2);
71
- ne.writeFileSync(m, l), console.info(`config file updated ${l}`);
72
- } catch (l) {
73
- throw console.info(`error ${l} while writing to ${m}, JSON: ${t}`), console.log(`
74
- ⚠️ Failed write config file to ${m}, for more info use verbose flag`), l;
70
+ const d = JSON.stringify(s, null, 2);
71
+ re.writeFileSync(m, d), console.info(`config file updated ${d}`);
72
+ } catch (d) {
73
+ throw console.info(`error ${d} while writing to ${m}, JSON: ${s}`), console.log(`
74
+ ⚠️ Failed write config file to ${m}, for more info use verbose flag`), d;
75
75
  }
76
- }, ie = {
76
+ }, ce = {
77
77
  name: "🌟 Add flow definition to your project",
78
78
  value: "addFlow",
79
79
  description: "Adds flow to yours myop.config.json",
80
- _action: (s) => {
81
- a.myopConfig.flows.includes(s) || a.myopConfig.flows.push(s), Z(a.options.configPath, a.myopConfig);
80
+ _action: (i) => {
81
+ a.myopConfig.flows.includes(i) || a.myopConfig.flows.push(i), q(a.options.configPath, a.myopConfig);
82
82
  },
83
83
  action: async () => {
84
84
  }
85
- }, ae = {
85
+ }, le = {
86
86
  name: "🚫 Remove flow definition from your project",
87
87
  value: "removeFlow",
88
88
  description: "Removes flow to yours myop.config.json",
89
- _action: (s) => {
90
- a.myopConfig.flows = a.myopConfig.flows.filter((t) => t !== s), Z(a.options.configPath, a.myopConfig);
89
+ _action: (i) => {
90
+ a.myopConfig.flows = a.myopConfig.flows.filter((s) => s !== i), q(a.options.configPath, a.myopConfig);
91
91
  },
92
92
  action: () => {
93
93
  }
94
- }, Oe = {
94
+ }, Te = {
95
95
  name: "πŸ‘‹ Quit",
96
96
  value: "quit",
97
97
  description: "Quit and continue coding.",
98
98
  action: () => {
99
99
  process.exit();
100
100
  }
101
- }, $e = {
101
+ }, Re = {
102
102
  name: "🟒 Create new component",
103
103
  value: "-",
104
104
  disabled: "(not available yet)"
105
- }, be = {
105
+ }, Ae = {
106
106
  name: "πŸ”΅ Create new experience",
107
107
  value: "-",
108
108
  disabled: "(not available yet)"
109
- }, Te = {
109
+ }, Ie = {
110
110
  name: "🟑 Create new skin",
111
111
  value: "-",
112
112
  disabled: "(not available yet)"
113
- }, xe = {
113
+ }, _e = {
114
114
  name: "πŸ”΄ Create new flow",
115
115
  value: "-",
116
116
  disabled: "(not available yet)"
117
- }, Pe = {
117
+ }, Ne = {
118
118
  name: "πŸ†• Define new custom Myop message",
119
119
  value: "generateMyopMessage",
120
120
  description: "️Help you creates the right structure for a new Myop message, including types and handlers.",
121
121
  disabled: "(not available yet)"
122
- }, Ne = [Pe, $e, be, Te, xe];
123
- function Ie(s, t, m, l) {
122
+ }, je = [Ne, Re, Ae, Ie, _e];
123
+ function Fe(i, s, m, d) {
124
124
  return `<!DOCTYPE html>
125
125
  <html lang="en">
126
126
  <head>
127
127
  <meta charset="UTF-8">
128
128
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
129
- <title>Myop DevTools - localhost:${s}</title>
129
+ <title>Myop DevTools - localhost:${i}</title>
130
130
  <style>
131
131
  ${m}
132
132
  </style>
@@ -136,8 +136,8 @@ ${m}
136
136
  <div class="toolbar">
137
137
  <div class="toolbar-title">Myop DevTools</div>
138
138
  <div class="toolbar-info">
139
- <span><div class="status-dot"></div> localhost:${s}</span>
140
- <span>Management: ${t}</span>
139
+ <span><div class="status-dot"></div> localhost:${i}</span>
140
+ <span>Management: ${s}</span>
141
141
  </div>
142
142
  </div>
143
143
 
@@ -145,6 +145,7 @@ ${m}
145
145
  <div class="tab active">Network Architecture</div>
146
146
  <div class="tab">Performance</div>
147
147
  <div class="tab">Console</div>
148
+ <button class="clear-data-btn" onclick="clearStoredData()" title="Clear all stored data">πŸ—‘οΈ Clear Data</button>
148
149
  </div>
149
150
 
150
151
  <div class="main-content">
@@ -202,33 +203,33 @@ ${m}
202
203
 
203
204
  <script>
204
205
  // Inject PORT as a global variable for the app to use
205
- window.PORT = ${s};
206
+ window.PORT = ${i};
206
207
 
207
- ${l}
208
+ ${d}
208
209
  <\/script>
209
210
  </body>
210
211
  </html>`;
211
212
  }
212
- async function Ae() {
213
- const s = await import("fs"), t = await import("path"), { exec: m } = await import("child_process"), l = await import("http");
214
- let N;
213
+ async function Ee() {
214
+ const i = await import("fs"), s = await import("path"), { exec: m } = await import("child_process"), d = await import("http"), { createHash: I } = await import("node:crypto");
215
+ let P;
215
216
  if (import.meta.url.startsWith("file://")) {
216
217
  const o = import.meta.url.slice(7);
217
- N = t.default.dirname(o);
218
+ P = s.default.dirname(o);
218
219
  } else
219
- N = t.default.dirname(import.meta.url);
220
- const I = t.default.join(N, "commands", "dev", "management-website"), E = s.default.readFileSync(t.default.join(I, "styles.css"), "utf-8"), D = s.default.readFileSync(t.default.join(I, "app.js"), "utf-8"), v = 9292, S = 9293, b = "./dist";
221
- let w = !1, H = !1;
222
- const B = /* @__PURE__ */ new Map(), le = a.program.getOptionValue("config") || "./myop.config.json";
223
- let u, T;
220
+ P = s.default.dirname(import.meta.url);
221
+ const _ = s.default.join(P, "commands", "dev", "management-website"), E = i.default.readFileSync(s.default.join(_, "styles.css"), "utf-8"), J = i.default.readFileSync(s.default.join(_, "app.js"), "utf-8"), S = 9292, h = 9293, y = "./dist";
222
+ let N = !1, Y = !1;
223
+ const V = /* @__PURE__ */ new Map(), me = a.program.getOptionValue("config") || "./myop.config.json";
224
+ let g, x, D = !1;
224
225
  try {
225
- const o = s.default.readFileSync(le, "utf-8"), e = JSON.parse(o);
226
- u = e.componentId, T = e.componentName || null, u || (console.error("❌ Error: componentId not found in myop.config.json"), process.exit(1));
226
+ const o = i.default.readFileSync(me, "utf-8"), e = JSON.parse(o);
227
+ g = e.componentId, x = e.componentName || null, D = e.HMR === !0, g || (console.error("❌ Error: componentId not found in myop.config.json"), process.exit(1)), D && console.log("πŸ”₯ HMR enabled");
227
228
  } catch (o) {
228
229
  console.error("❌ Error reading myop.config.json:", o.message), process.exit(1);
229
230
  }
230
- const R = process.cwd(), de = (o) => {
231
- const e = t.default.extname(o).toLowerCase();
231
+ const L = process.cwd(), fe = (o) => {
232
+ const e = s.default.extname(o).toLowerCase();
232
233
  return {
233
234
  ".html": "text/html",
234
235
  ".js": "text/javascript",
@@ -240,25 +241,43 @@ async function Ae() {
240
241
  ".svg": "image/svg+xml",
241
242
  ".ico": "image/x-icon"
242
243
  }[e] || "application/octet-stream";
243
- }, g = /* @__PURE__ */ new Map(), L = [], pe = 50, x = [], A = /* @__PURE__ */ new Map(), Y = l.default.createServer((o, e) => {
244
+ }, u = /* @__PURE__ */ new Map(), U = [], ge = 50, $ = [], T = /* @__PURE__ */ new Map(), H = /* @__PURE__ */ new Map(), ue = (o, e, t) => {
245
+ if (o.url.startsWith("/_hmr/")) {
246
+ const n = o.url.split("/_hmr/")[1], c = o.headers["sec-websocket-key"], r = I("sha1").update(c + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
247
+ e.write(
248
+ `HTTP/1.1 101 Switching Protocols\r
249
+ Upgrade: websocket\r
250
+ Connection: Upgrade\r
251
+ Sec-WebSocket-Accept: ${r}\r
252
+ \r
253
+ `
254
+ ), H.has(n) || H.set(n, /* @__PURE__ */ new Set()), H.get(n).add(e), console.log(`πŸ”Œ HMR client connected: ${n}`), e.on("close", () => {
255
+ const l = H.get(n);
256
+ l && (l.delete(e), l.size === 0 && H.delete(n)), console.log(`πŸ”Œ HMR client disconnected: ${n}`);
257
+ }), e.on("error", () => {
258
+ const l = H.get(n);
259
+ l && l.delete(e);
260
+ });
261
+ }
262
+ }, X = d.default.createServer((o, e) => {
244
263
  if (e.setHeader("Content-Type", "application/json"), o.method === "POST" && o.url === "/_register") {
245
- let i = "";
246
- o.on("data", (n) => i += n), o.on("end", () => {
264
+ let t = "";
265
+ o.on("data", (n) => t += n), o.on("end", () => {
247
266
  try {
248
- const { componentId: n, distPath: r, componentName: c } = JSON.parse(i);
249
- g.set(n, { path: r, name: c || null });
250
- const p = c ? ` (${c})` : "";
251
- console.log(`βœ… Registered: ${n}${p} -> ${r}`), e.writeHead(200), e.end(JSON.stringify({ success: !0, registered: Array.from(g.keys()) }));
252
- const h = Array.from(g.entries()).map(([C, J]) => ({
267
+ const { componentId: n, distPath: c, componentName: r } = JSON.parse(t);
268
+ u.set(n, { path: c, name: r || null });
269
+ const l = r ? ` (${r})` : "";
270
+ console.log(`βœ… Registered: ${n}${l} -> ${c}`), e.writeHead(200), e.end(JSON.stringify({ success: !0, registered: Array.from(u.keys()) }));
271
+ const w = Array.from(u.entries()).map(([C, j]) => ({
253
272
  id: C,
254
- path: J.path,
255
- name: J.name
273
+ path: j.path,
274
+ name: j.name
256
275
  }));
257
- x.forEach((C) => {
276
+ $.forEach((C) => {
258
277
  try {
259
278
  C.write(`data: ${JSON.stringify({
260
279
  type: "components",
261
- components: h
280
+ components: w
262
281
  })}
263
282
 
264
283
  `);
@@ -270,21 +289,21 @@ async function Ae() {
270
289
  }
271
290
  });
272
291
  } else if (o.method === "POST" && o.url === "/_unregister") {
273
- let i = "";
274
- o.on("data", (n) => i += n), o.on("end", () => {
292
+ let t = "";
293
+ o.on("data", (n) => t += n), o.on("end", () => {
275
294
  try {
276
- const { componentId: n } = JSON.parse(i);
277
- g.delete(n), console.log(`❌ Unregistered: ${n}`), e.writeHead(200), e.end(JSON.stringify({ success: !0 }));
278
- const r = Array.from(g.entries()).map(([c, p]) => ({
279
- id: c,
280
- path: p.path,
281
- name: p.name
295
+ const { componentId: n } = JSON.parse(t);
296
+ u.delete(n), console.log(`❌ Unregistered: ${n}`), e.writeHead(200), e.end(JSON.stringify({ success: !0 }));
297
+ const c = Array.from(u.entries()).map(([r, l]) => ({
298
+ id: r,
299
+ path: l.path,
300
+ name: l.name
282
301
  }));
283
- x.forEach((c) => {
302
+ $.forEach((r) => {
284
303
  try {
285
- c.write(`data: ${JSON.stringify({
304
+ r.write(`data: ${JSON.stringify({
286
305
  type: "components",
287
- components: r
306
+ components: c
288
307
  })}
289
308
 
290
309
  `);
@@ -295,99 +314,99 @@ async function Ae() {
295
314
  e.writeHead(400), e.end(JSON.stringify({ error: n.message }));
296
315
  }
297
316
  });
298
- } else o.method === "GET" && o.url === "/_list" ? (e.writeHead(200), e.end(JSON.stringify({ components: Array.from(g.entries()) }))) : (e.writeHead(404), e.end(JSON.stringify({ error: "Not found" })));
299
- }), _ = l.default.createServer((o, e) => {
317
+ } else o.method === "GET" && o.url === "/_list" ? (e.writeHead(200), e.end(JSON.stringify({ components: Array.from(u.entries()) }))) : (e.writeHead(404), e.end(JSON.stringify({ error: "Not found" })));
318
+ }), k = d.default.createServer((o, e) => {
300
319
  if (o.url.includes("..")) {
301
320
  e.writeHead(403, { "Content-Type": "text/plain" }), e.end("Forbidden");
302
321
  return;
303
322
  }
304
- const i = new URL(o.url, `http://localhost:${v}`), n = i.pathname, r = n.split("/").filter((y) => y);
323
+ const t = new URL(o.url, `http://localhost:${S}`), n = t.pathname, c = n.split("/").filter((v) => v);
305
324
  if (n.startsWith("/consume")) {
306
- const y = i.searchParams.get("id");
307
- if (!y) {
325
+ const v = t.searchParams.get("id");
326
+ if (!v) {
308
327
  e.writeHead(400, { "Content-Type": "application/json" }), e.end(JSON.stringify({ error: "Component ID required. Use /consume?id=<componentId>" }));
309
328
  return;
310
329
  }
311
- const $ = g.get(y), P = $ ? $.path : null, te = (M) => {
312
- let d = "Unknown", O = "Unknown";
330
+ const b = u.get(v), M = b ? b.path : null, ie = (R) => {
331
+ let p = "Unknown", O = "Unknown";
313
332
  if (o.headers.referer || o.headers.referrer) {
314
333
  const f = o.headers.referer || o.headers.referrer;
315
334
  try {
316
- const j = new URL(f);
317
- d = j.origin, O = j.hostname || j.origin;
335
+ const A = new URL(f);
336
+ p = A.origin, O = A.hostname || A.origin;
318
337
  } catch {
319
- d = f, O = f;
338
+ p = f, O = f;
320
339
  }
321
340
  } else if (o.headers.origin)
322
341
  try {
323
342
  const f = new URL(o.headers.origin);
324
- d = f.origin, O = f.hostname || f.origin;
343
+ p = f.origin, O = f.hostname || f.origin;
325
344
  } catch {
326
- d = o.headers.origin, O = o.headers.origin;
345
+ p = o.headers.origin, O = o.headers.origin;
327
346
  }
328
347
  else if (o.socket.remoteAddress) {
329
348
  const f = o.socket.remoteAddress;
330
- f === "::1" || f === "::ffff:127.0.0.1" ? (d = "localhost", O = "localhost (direct)") : (d = f, O = f.replace("::ffff:", ""));
349
+ f === "::1" || f === "::ffff:127.0.0.1" ? (p = "localhost", O = "localhost (direct)") : (p = f, O = f.replace("::ffff:", ""));
331
350
  }
332
- const W = o.headers.referer || o.headers.referrer || d, G = {
351
+ const Q = o.headers.referer || o.headers.referrer || p, W = {
333
352
  type: "request",
334
- componentId: y,
353
+ componentId: v,
335
354
  timestamp: Date.now(),
336
- servedLocally: M,
337
- referrer: W,
338
- origin: d,
355
+ servedLocally: R,
356
+ referrer: Q,
357
+ origin: p,
339
358
  originLabel: O
340
359
  };
341
- A.has(d) || (A.set(d, {
342
- url: d,
360
+ T.has(p) || (T.set(p, {
361
+ url: p,
343
362
  label: O,
344
363
  firstSeen: Date.now(),
345
364
  requestCount: 0
346
- }), x.forEach((f) => {
365
+ }), $.forEach((f) => {
347
366
  try {
348
367
  f.write(`data: ${JSON.stringify({
349
368
  type: "origins",
350
- origins: Array.from(A.values())
369
+ origins: Array.from(T.values())
351
370
  })}
352
371
 
353
372
  `);
354
373
  } catch {
355
374
  }
356
375
  }));
357
- const ue = A.get(d);
358
- ue.requestCount++, x.forEach((f) => {
376
+ const Oe = T.get(p);
377
+ Oe.requestCount++, $.forEach((f) => {
359
378
  try {
360
379
  f.write(`data: ${JSON.stringify({
361
380
  type: "origins",
362
- origins: Array.from(A.values())
381
+ origins: Array.from(T.values())
363
382
  })}
364
383
 
365
384
  `);
366
385
  } catch {
367
386
  }
368
- }), L.push(G), L.length > pe && L.shift(), x.forEach((f) => {
387
+ }), U.push(W), U.length > ge && U.shift(), $.forEach((f) => {
369
388
  try {
370
- f.write(`data: ${JSON.stringify(G)}
389
+ f.write(`data: ${JSON.stringify(W)}
371
390
 
372
391
  `);
373
392
  } catch {
374
393
  }
375
394
  });
376
395
  };
377
- if (P) {
378
- const M = t.default.join(P, "index.html");
379
- s.default.readFile(M, "utf-8", (d, O) => {
380
- if (d) {
381
- console.log(`❌ File not found: ${M}`), e.writeHead(404, { "Content-Type": "application/json" }), e.end(JSON.stringify({ error: "index.html not found" }));
396
+ if (M) {
397
+ const R = s.default.join(M, "index.html");
398
+ i.default.readFile(R, "utf-8", (p, O) => {
399
+ if (p) {
400
+ console.log(`❌ File not found: ${R}`), e.writeHead(404, { "Content-Type": "application/json" }), e.end(JSON.stringify({ error: "index.html not found" }));
382
401
  return;
383
402
  }
384
- const W = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, G = {
403
+ const Q = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, W = {
385
404
  item: {
386
- name: y,
387
- id: y,
405
+ name: v,
406
+ id: v,
388
407
  consume_variant: [
389
408
  {
390
- id: W,
409
+ id: Q,
391
410
  name: "dev version",
392
411
  loader: {
393
412
  type: "HTMLLoader",
@@ -398,21 +417,21 @@ async function Ae() {
398
417
  ]
399
418
  }
400
419
  };
401
- console.log(`βœ… Serving consume JSON for: ${y}`), te(!0), e.writeHead(200, {
420
+ console.log(`βœ… Serving consume JSON for: ${v}`), ie(!0), e.writeHead(200, {
402
421
  "Content-Type": "application/json",
403
422
  "Access-Control-Allow-Origin": "*"
404
- }), e.end(JSON.stringify(G, null, 2));
423
+ }), e.end(JSON.stringify(W, null, 2));
405
424
  });
406
425
  } else {
407
- console.log(`πŸ“‘ Proxying consume request to cloud.myop.dev for: ${y}`);
408
- const M = `https://cloud.myop.dev/consume${i.search}`;
409
- te(!1), fetch(M).then((d) => d.text()).then((d) => {
426
+ console.log(`πŸ“‘ Proxying consume request to cloud.myop.dev for: ${v}`);
427
+ const R = `https://cloud.myop.dev/consume${t.search}`;
428
+ ie(!1), fetch(R).then((p) => p.text()).then((p) => {
410
429
  e.writeHead(200, {
411
430
  "Content-Type": "application/json",
412
431
  "Access-Control-Allow-Origin": "*"
413
- }), e.end(d);
414
- }).catch((d) => {
415
- console.error(`❌ Proxy error: ${d.message}`), e.writeHead(502, { "Content-Type": "application/json" }), e.end(JSON.stringify({ error: "Failed to fetch from cloud.myop.dev" }));
432
+ }), e.end(p);
433
+ }).catch((p) => {
434
+ console.error(`❌ Proxy error: ${p.message}`), e.writeHead(502, { "Content-Type": "application/json" }), e.end(JSON.stringify({ error: "Failed to fetch from cloud.myop.dev" }));
416
435
  });
417
436
  }
418
437
  return;
@@ -423,256 +442,422 @@ async function Ae() {
423
442
  "Cache-Control": "no-cache",
424
443
  Connection: "keep-alive",
425
444
  "Access-Control-Allow-Origin": "*"
426
- }), x.push(e);
427
- const y = Array.from(g.entries()).map(([$, P]) => ({
428
- id: $,
429
- path: P.path,
430
- name: P.name
445
+ }), $.push(e);
446
+ const v = Array.from(u.entries()).map(([b, M]) => ({
447
+ id: b,
448
+ path: M.path,
449
+ name: M.name
431
450
  }));
432
451
  e.write(`data: ${JSON.stringify({
433
452
  type: "components",
434
- components: y
453
+ components: v
435
454
  })}
436
455
 
437
456
  `), e.write(`data: ${JSON.stringify({
438
457
  type: "origins",
439
- origins: Array.from(A.values())
458
+ origins: Array.from(T.values())
440
459
  })}
441
460
 
442
461
  `), e.write(`data: ${JSON.stringify({
443
462
  type: "requestLog",
444
- log: L
463
+ log: U
445
464
  })}
446
465
 
447
466
  `), o.on("close", () => {
448
- const $ = x.indexOf(e);
449
- $ !== -1 && x.splice($, 1);
467
+ const b = $.indexOf(e);
468
+ b !== -1 && $.splice(b, 1);
450
469
  });
451
470
  return;
452
471
  }
453
- if (r.length === 0) {
454
- e.writeHead(200, { "Content-Type": "text/html" }), e.end(Ie(v, S, E, D));
472
+ if (c.length === 0) {
473
+ e.writeHead(200, { "Content-Type": "text/html" }), e.end(Fe(S, h, E, J));
455
474
  return;
456
475
  }
457
- if (r[0] !== "view") {
476
+ if (c[0] !== "view") {
458
477
  e.writeHead(404, { "Content-Type": "text/plain" }), e.end("Not found. Use /view/<componentId>/ to access components.");
459
478
  return;
460
479
  }
461
- if (r.length < 2) {
480
+ if (c.length < 2) {
462
481
  e.writeHead(400, { "Content-Type": "text/plain" }), e.end("Component ID required. Use /view/<componentId>/");
463
482
  return;
464
483
  }
465
- const c = r[1], p = g.get(c);
466
- if (!p) {
467
- e.writeHead(404, { "Content-Type": "text/plain" }), e.end(`Component not found: ${c}`);
484
+ const r = c[1], l = u.get(r);
485
+ if (!l) {
486
+ e.writeHead(404, { "Content-Type": "text/plain" }), e.end(`Component not found: ${r}`);
468
487
  return;
469
488
  }
470
- const h = p.path, C = r.slice(2), J = C.length === 0 ? "index.html" : C.join("/"), F = t.default.join(h, J);
471
- console.log(`πŸ“₯ Request: ${o.url} -> ${F}`), s.default.readFile(F, (y, $) => {
472
- if (y) {
489
+ const w = l.path, C = c.slice(2), j = C.length === 0 ? "index.html" : C.join("/"), F = s.default.join(w, j);
490
+ console.log(`πŸ“₯ Request: ${o.url} -> ${F}`), i.default.readFile(F, (v, b) => {
491
+ if (v) {
473
492
  console.log(`❌ File not found: ${F}`), e.writeHead(404, { "Content-Type": "text/plain" }), e.end("Not Found");
474
493
  return;
475
494
  }
476
- const P = de(F);
477
- console.log(`βœ… Serving: ${F} (${P})`), e.writeHead(200, {
478
- "Content-Type": P,
495
+ const M = fe(F);
496
+ console.log(`βœ… Serving: ${F} (${M})`), e.writeHead(200, {
497
+ "Content-Type": M,
479
498
  "Access-Control-Allow-Origin": "*"
480
- }), e.end($);
499
+ }), e.end(b);
481
500
  });
482
- }), X = () => new Promise((o, e) => {
483
- const i = JSON.stringify({
484
- componentId: u,
485
- distPath: t.default.resolve(R, b),
486
- componentName: T
501
+ }), ee = () => new Promise((o, e) => {
502
+ const t = JSON.stringify({
503
+ componentId: g,
504
+ distPath: s.default.resolve(L, y),
505
+ componentName: x
487
506
  }), n = {
488
507
  hostname: "localhost",
489
- port: S,
508
+ port: h,
490
509
  path: "/_register",
491
510
  method: "POST",
492
511
  headers: {
493
512
  "Content-Type": "application/json",
494
- "Content-Length": Buffer.byteLength(i)
513
+ "Content-Length": Buffer.byteLength(t)
495
514
  }
496
- }, r = l.default.request(n, (c) => {
497
- let p = "";
498
- c.on("data", (h) => p += h), c.on("end", () => {
499
- c.statusCode === 200 ? o(JSON.parse(p)) : e(new Error(`Registration failed: ${c.statusCode}`));
515
+ }, c = d.default.request(n, (r) => {
516
+ let l = "";
517
+ r.on("data", (w) => l += w), r.on("end", () => {
518
+ r.statusCode === 200 ? o(JSON.parse(l)) : e(new Error(`Registration failed: ${r.statusCode}`));
500
519
  });
501
520
  });
502
- r.on("error", e), r.write(i), r.end();
503
- }), me = () => new Promise((o, e) => {
504
- const i = JSON.stringify({ componentId: u }), n = {
521
+ c.on("error", e), c.write(t), c.end();
522
+ }), he = () => new Promise((o, e) => {
523
+ const t = JSON.stringify({ componentId: g }), n = {
505
524
  hostname: "localhost",
506
- port: S,
525
+ port: h,
507
526
  path: "/_unregister",
508
527
  method: "POST",
509
528
  headers: {
510
529
  "Content-Type": "application/json",
511
- "Content-Length": Buffer.byteLength(i)
530
+ "Content-Length": Buffer.byteLength(t)
512
531
  }
513
- }, r = l.default.request(n, (c) => {
532
+ }, c = d.default.request(n, (r) => {
514
533
  o();
515
534
  });
516
- r.on("error", () => o()), r.write(i), r.end();
517
- }), U = () => {
518
- if (w) {
519
- H = !0;
535
+ c.on("error", () => o()), c.write(t), c.end();
536
+ }), ye = () => {
537
+ if (!D) return;
538
+ const o = s.default.join(y, "index.html");
539
+ try {
540
+ let e = i.default.readFileSync(o, "utf-8");
541
+ if (e.includes("<!-- MYOP HMR -->")) {
542
+ const n = e.indexOf("<!-- MYOP HMR -->"), c = e.indexOf("<\/script>", n) + 9;
543
+ e = e.slice(0, n) + e.slice(c);
544
+ }
545
+ const t = `
546
+ <!-- MYOP HMR -->
547
+ <script>
548
+ (function() {
549
+ const componentId = '${g}';
550
+ const wsUrl = 'ws://localhost:${h}/_hmr/' + componentId;
551
+ let ws;
552
+ let reconnectAttempts = 0;
553
+ const maxReconnectAttempts = 10;
554
+
555
+ // Capture all myop_init_interface calls
556
+ const initCalls = [];
557
+ const originalMyopInit = window.myop_init_interface;
558
+
559
+ // Preserve myop_cta_handler reference
560
+ let preservedCtaHandler = window.myop_cta_handler;
561
+
562
+ // Proxy myop_init_interface to capture all calls
563
+ window.myop_init_interface = function(...args) {
564
+ // Store the call arguments
565
+ initCalls.push(args);
566
+ console.log('πŸ”₯ HMR: Captured myop_init_interface call', args);
567
+
568
+ // Call original function if it exists
569
+ if (originalMyopInit && typeof originalMyopInit === 'function') {
570
+ return originalMyopInit.apply(this, args);
571
+ }
572
+ };
573
+
574
+ function connect() {
575
+ ws = new WebSocket(wsUrl);
576
+
577
+ ws.onopen = () => {
578
+ console.log('πŸ”₯ HMR connected');
579
+ reconnectAttempts = 0;
580
+ };
581
+
582
+ ws.onmessage = (event) => {
583
+ const data = JSON.parse(event.data);
584
+ if (data.type === 'update') {
585
+ console.log('πŸ”„ HMR: Updating document...');
586
+
587
+ // Get current scroll position
588
+ const scrollX = window.scrollX;
589
+ const scrollY = window.scrollY;
590
+
591
+ // Store the captured init calls
592
+ const capturedCalls = [...initCalls];
593
+ console.log('πŸ”₯ HMR: Stored', capturedCalls.length, 'myop_init_interface calls');
594
+
595
+ // Preserve myop_cta_handler before document replacement
596
+ if (window.myop_cta_handler) {
597
+ preservedCtaHandler = window.myop_cta_handler;
598
+ console.log('πŸ”₯ HMR: Preserved myop_cta_handler reference');
599
+ }
600
+
601
+ // Replace document content
602
+ document.open();
603
+ document.write(data.html);
604
+ document.close();
605
+
606
+ // Restore scroll position
607
+ window.scrollTo(scrollX, scrollY);
608
+
609
+ // Restore myop_cta_handler reference immediately
610
+ if (preservedCtaHandler) {
611
+ window.myop_cta_handler = preservedCtaHandler;
612
+ console.log('πŸ”₯ HMR: Restored myop_cta_handler reference');
613
+ }
614
+
615
+ // Wait for new document to be ready and replay init calls
616
+ setTimeout(() => {
617
+ console.log('πŸ”₯ HMR: Replaying', capturedCalls.length, 'myop_init_interface calls');
618
+
619
+ capturedCalls.forEach((args, index) => {
620
+ if (window.myop_init_interface && typeof window.myop_init_interface === 'function') {
621
+ console.log('πŸ”₯ HMR: Replaying call', index + 1, args);
622
+ window.myop_init_interface.apply(window, args);
623
+ }
624
+ });
625
+
626
+ // Reconnect HMR after replaying calls
627
+ if (ws.readyState === WebSocket.CLOSED) {
628
+ connect();
629
+ }
630
+ }, 100);
631
+ }
632
+ };
633
+
634
+ ws.onclose = () => {
635
+ console.log('πŸ”₯ HMR disconnected');
636
+ if (reconnectAttempts < maxReconnectAttempts) {
637
+ reconnectAttempts++;
638
+ setTimeout(connect, 1000 * reconnectAttempts);
639
+ }
640
+ };
641
+
642
+ ws.onerror = (error) => {
643
+ console.error('πŸ”₯ HMR error:', error);
644
+ };
645
+ }
646
+
647
+ connect();
648
+ })();
649
+ <\/script>
650
+ `;
651
+ e.includes("</body>") ? e = e.replace("</body>", `${t}</body>`) : e.includes("</html>") ? e = e.replace("</html>", `${t}</html>`) : e += t, i.default.writeFileSync(o, e, "utf-8"), console.log("πŸ”₯ HMR script injected");
652
+ } catch (e) {
653
+ console.error("❌ Failed to inject HMR script:", e.message);
654
+ }
655
+ }, we = (o) => {
656
+ const e = Buffer.from(o), t = e.length;
657
+ let n;
658
+ return t < 126 ? n = Buffer.concat([
659
+ Buffer.from([129, t]),
660
+ // FIN + text frame, length
661
+ e
662
+ ]) : t < 65536 ? n = Buffer.concat([
663
+ Buffer.from([129, 126]),
664
+ // FIN + text frame, extended length
665
+ Buffer.from([t >> 8, t & 255]),
666
+ // 16-bit length
667
+ e
668
+ ]) : n = Buffer.concat([
669
+ Buffer.from([129, 127]),
670
+ // FIN + text frame, extended length
671
+ Buffer.from([0, 0, 0, 0, t >> 24, t >> 16 & 255, t >> 8 & 255, t & 255]),
672
+ // 64-bit length
673
+ e
674
+ ]), n;
675
+ }, ve = () => {
676
+ if (!D) return;
677
+ const o = H.get(g);
678
+ if (!o || o.size === 0)
679
+ return;
680
+ console.log(`πŸ”₯ Notifying ${o.size} HMR client(s)`);
681
+ const e = s.default.join(y, "index.html");
682
+ try {
683
+ let t = i.default.readFileSync(e, "utf-8");
684
+ if (t.includes("<!-- MYOP HMR -->")) {
685
+ const r = t.indexOf("<!-- MYOP HMR -->"), l = t.indexOf("<\/script>", r) + 9;
686
+ t = t.slice(0, r) + t.slice(l);
687
+ }
688
+ const n = JSON.stringify({
689
+ type: "update",
690
+ html: t
691
+ }), c = we(n);
692
+ o.forEach((r) => {
693
+ try {
694
+ r.write(c);
695
+ } catch {
696
+ o.delete(r);
697
+ }
698
+ });
699
+ } catch (t) {
700
+ console.error("❌ Failed to read HTML for HMR:", t.message);
701
+ }
702
+ }, B = () => {
703
+ if (N) {
704
+ Y = !0;
520
705
  return;
521
706
  }
522
- w = !0, console.log(`
523
- πŸ”¨ Building...`), m("npm run build", (o, e, i) => {
524
- w = !1, o ? (console.error("❌ Build failed:", o.message), i && console.error(i)) : (console.log("βœ… Build completed"), e && console.log(e)), H && (H = !1, U());
707
+ N = !0, console.log(`
708
+ πŸ”¨ Building...`), m("npm run build", (o, e, t) => {
709
+ N = !1, o ? (console.error("❌ Build failed:", o.message), t && console.error(t)) : (console.log("βœ… Build completed"), e && console.log(e), ye(), ve()), Y && (Y = !1, B());
525
710
  });
526
- }, K = (o) => {
527
- s.default.readdir(o, { withFileTypes: !0 }, (e, i) => {
528
- e || i.forEach((n) => {
529
- const r = t.default.join(o, n.name);
711
+ }, oe = (o) => {
712
+ i.default.readdir(o, { withFileTypes: !0 }, (e, t) => {
713
+ e || t.forEach((n) => {
714
+ const c = s.default.join(o, n.name);
530
715
  if (n.isDirectory())
531
- n.name !== "node_modules" && n.name !== "dist" && !n.name.startsWith(".") && K(r);
716
+ n.name !== "node_modules" && n.name !== "dist" && !n.name.startsWith(".") && oe(c);
532
717
  else if (n.isFile()) {
533
- const c = t.default.extname(n.name);
534
- if (c === ".js" || c === ".css") {
718
+ const r = s.default.extname(n.name);
719
+ if (r === ".js" || r === ".css" || r === ".html") {
535
720
  try {
536
- const p = s.default.readFileSync(r, "utf-8");
537
- B.set(r, p);
721
+ const l = i.default.readFileSync(c, "utf-8");
722
+ V.set(c, l);
538
723
  } catch {
539
724
  }
540
- s.default.watch(r, (p) => {
541
- if (p === "change")
725
+ i.default.watch(c, (l) => {
726
+ if (l === "change")
542
727
  try {
543
- const h = s.default.readFileSync(r, "utf-8"), C = B.get(r);
544
- h !== C && (B.set(r, h), console.log(`πŸ“ File changed: ${r}`), U());
728
+ const w = i.default.readFileSync(c, "utf-8"), C = V.get(c);
729
+ w !== C && (V.set(c, w), console.log(`πŸ“ File changed: ${c}`), B());
545
730
  } catch {
546
- console.log(`πŸ“ File changed: ${r}`), U();
731
+ console.log(`πŸ“ File changed: ${c}`), B();
547
732
  }
548
733
  });
549
734
  }
550
735
  }
551
736
  });
552
737
  });
553
- }, q = () => {
738
+ }, te = () => {
554
739
  console.log(`
555
- πŸ”¨ Component: ${u}`), U(), K(R), console.log("πŸ‘€ Watching .js and .css files for changes..."), console.log(`Press Ctrl+C to stop
740
+ πŸ”¨ Component: ${g}`), B(), oe(L), console.log("πŸ‘€ Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
556
741
  `);
557
- }, fe = () => new Promise((o) => {
742
+ }, Se = () => new Promise((o) => {
558
743
  const e = {
559
744
  hostname: "localhost",
560
- port: S,
745
+ port: h,
561
746
  path: "/_list",
562
747
  method: "GET",
563
748
  timeout: 1e3
564
- }, i = l.default.request(e, (n) => {
749
+ }, t = d.default.request(e, (n) => {
565
750
  o(!0);
566
751
  });
567
- i.on("error", () => o(!1)), i.on("timeout", () => {
568
- i.destroy(), o(!1);
569
- }), i.end();
570
- }), ge = () => new Promise((o) => {
571
- const e = l.default.createServer((i, n) => {
572
- if (n.setHeader("Content-Type", "application/json"), i.method === "POST" && i.url === "/_register") {
573
- let r = "";
574
- i.on("data", (c) => r += c), i.on("end", () => {
752
+ t.on("error", () => o(!1)), t.on("timeout", () => {
753
+ t.destroy(), o(!1);
754
+ }), t.end();
755
+ }), Ce = () => new Promise((o) => {
756
+ const e = d.default.createServer((t, n) => {
757
+ if (n.setHeader("Content-Type", "application/json"), t.method === "POST" && t.url === "/_register") {
758
+ let c = "";
759
+ t.on("data", (r) => c += r), t.on("end", () => {
575
760
  try {
576
- const { componentId: c, distPath: p, componentName: h } = JSON.parse(r);
577
- g.set(c, { path: p, name: h || null });
578
- const C = h ? ` (${h})` : "";
579
- console.log(`βœ… Registered: ${c}${C} -> ${p}`), n.writeHead(200), n.end(JSON.stringify({ success: !0, registered: Array.from(g.keys()) }));
580
- } catch (c) {
581
- n.writeHead(400), n.end(JSON.stringify({ error: c.message }));
761
+ const { componentId: r, distPath: l, componentName: w } = JSON.parse(c);
762
+ u.set(r, { path: l, name: w || null });
763
+ const C = w ? ` (${w})` : "";
764
+ console.log(`βœ… Registered: ${r}${C} -> ${l}`), n.writeHead(200), n.end(JSON.stringify({ success: !0, registered: Array.from(u.keys()) }));
765
+ } catch (r) {
766
+ n.writeHead(400), n.end(JSON.stringify({ error: r.message }));
582
767
  }
583
768
  });
584
- } else if (i.method === "POST" && i.url === "/_unregister") {
585
- let r = "";
586
- i.on("data", (c) => r += c), i.on("end", () => {
769
+ } else if (t.method === "POST" && t.url === "/_unregister") {
770
+ let c = "";
771
+ t.on("data", (r) => c += r), t.on("end", () => {
587
772
  try {
588
- const { componentId: c } = JSON.parse(r);
589
- g.delete(c), console.log(`❌ Unregistered: ${c}`), n.writeHead(200), n.end(JSON.stringify({ success: !0 }));
590
- } catch (c) {
591
- n.writeHead(400), n.end(JSON.stringify({ error: c.message }));
773
+ const { componentId: r } = JSON.parse(c);
774
+ u.delete(r), console.log(`❌ Unregistered: ${r}`), n.writeHead(200), n.end(JSON.stringify({ success: !0 }));
775
+ } catch (r) {
776
+ n.writeHead(400), n.end(JSON.stringify({ error: r.message }));
592
777
  }
593
778
  });
594
- } else i.method === "GET" && i.url === "/_list" ? (n.writeHead(200), n.end(JSON.stringify({ components: Array.from(g.entries()) }))) : (n.writeHead(404), n.end(JSON.stringify({ error: "Not found" })));
779
+ } else t.method === "GET" && t.url === "/_list" ? (n.writeHead(200), n.end(JSON.stringify({ components: Array.from(u.entries()) }))) : (n.writeHead(404), n.end(JSON.stringify({ error: "Not found" })));
595
780
  });
596
781
  e.on("error", () => {
597
782
  o(!1);
598
- }), e.listen(S, () => {
783
+ }), e.listen(h, () => {
599
784
  console.log(`
600
- πŸ”„ Taking over as server...`), console.log(`πŸ“‘ Management server on port ${S}`), _.on("error", () => {
785
+ πŸ”„ Taking over as server...`), console.log(`πŸ“‘ Management server on port ${h}`), k.on("error", () => {
601
786
  e.close(), o(!1);
602
- }), _.listen(v, () => {
603
- console.log(`πŸ“‘ Main server running at http://localhost:${v}`), g.set(u, {
604
- path: t.default.resolve(R, b),
605
- name: T
787
+ }), k.listen(S, () => {
788
+ console.log(`πŸ“‘ Main server running at http://localhost:${S}`), u.set(g, {
789
+ path: s.default.resolve(L, y),
790
+ name: x
606
791
  });
607
- const i = T ? ` (${T})` : "";
608
- console.log(`βœ… Registered component: ${u}${i}`), console.log(`πŸ“‘ Access at: http://localhost:${v}/view/${u}/`), o(!0);
792
+ const t = x ? ` (${x})` : "";
793
+ console.log(`βœ… Registered component: ${g}${t}`), console.log(`πŸ“‘ Access at: http://localhost:${S}/view/${g}/`), o(!0);
609
794
  });
610
795
  });
611
796
  });
612
- let k;
613
- const ee = () => {
614
- k = setInterval(async () => {
615
- await fe() || (clearInterval(k), console.log(`
616
- ⚠️ 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 () => {
797
+ let G;
798
+ const ne = () => {
799
+ G = setInterval(async () => {
800
+ await Se() || (clearInterval(G), console.log(`
801
+ ⚠️ Server appears to be down, attempting to take over...`), await Ce() ? console.log("βœ… Successfully took over as server") : (console.log("ℹ️ Another instance took over, re-registering..."), setTimeout(async () => {
617
802
  try {
618
- await X(), console.log(`βœ… Re-registered component: ${u}`), ee();
619
- } catch (i) {
620
- console.error("❌ Failed to re-register:", i.message);
803
+ await ee(), console.log(`βœ… Re-registered component: ${g}`), ne();
804
+ } catch (t) {
805
+ console.error("❌ Failed to re-register:", t.message);
621
806
  }
622
807
  }, 2e3)));
623
808
  }, 3e3);
624
- }, oe = async () => {
809
+ }, se = async () => {
625
810
  console.log(`
626
811
 
627
- πŸ›‘ Shutting down...`), k && clearInterval(k), await me(), process.exit(0);
812
+ πŸ›‘ Shutting down...`), G && clearInterval(G), await he(), process.exit(0);
628
813
  };
629
- process.on("SIGINT", oe), process.on("SIGTERM", oe), Y.on("error", async (o) => {
814
+ process.on("SIGINT", se), process.on("SIGTERM", se), X.on("error", async (o) => {
630
815
  if (o.code === "EADDRINUSE") {
631
816
  console.log(`
632
817
  πŸ”— Connecting to existing dev server...`);
633
818
  try {
634
- const e = await X();
635
- console.log(`βœ… Registered component: ${u}`), console.log(`πŸ“‘ Access at: http://localhost:${v}/view/${u}/`), console.log(`πŸ“‹ All registered components: ${e.registered.join(", ")}`), q(), ee();
819
+ const e = await ee();
820
+ console.log(`βœ… Registered component: ${g}`), console.log(`πŸ“‘ Access at: http://localhost:${S}/view/${g}/`), console.log(`πŸ“‹ All registered components: ${e.registered.join(", ")}`), te(), ne();
636
821
  } catch (e) {
637
822
  console.error("❌ Failed to register component:", e.message), process.exit(1);
638
823
  }
639
824
  } else
640
825
  console.error("❌ Management server error:", o.message), process.exit(1);
641
- }), Y.listen(S, async () => {
826
+ }), X.on("upgrade", ue), X.listen(h, async () => {
642
827
  console.log(`
643
- πŸš€ Starting shared dev server...`), console.log(`πŸ“‘ Management server on port ${S}`), _.on("error", (o) => {
828
+ πŸš€ Starting shared dev server...`), console.log(`πŸ“‘ Management server on port ${h}`), k.on("error", (o) => {
644
829
  console.error("❌ Main server error:", o.message), process.exit(1);
645
- }), _.listen(v, async () => {
646
- console.log(`πŸ“‘ Main server running at http://localhost:${v}`), g.set(u, {
647
- path: t.default.resolve(R, b),
648
- name: T
830
+ }), k.listen(S, async () => {
831
+ console.log(`πŸ“‘ Main server running at http://localhost:${S}`), u.set(g, {
832
+ path: s.default.resolve(L, y),
833
+ name: x
649
834
  });
650
- const o = T ? ` (${T})` : "";
651
- console.log(`βœ… Registered component: ${u}${o}`), console.log(`πŸ“‘ Access at: http://localhost:${v}/view/${u}/`), q();
835
+ const o = x ? ` (${x})` : "";
836
+ console.log(`βœ… Registered component: ${g}${o}`), console.log(`πŸ“‘ Access at: http://localhost:${S}/view/${g}/`), te();
652
837
  });
653
838
  });
654
839
  }
655
- const Me = (s) => new Promise((t) => setTimeout(t, s));
840
+ const Je = (i) => new Promise((s) => setTimeout(s, i));
656
841
  a.executionPath = process.cwd();
657
- const z = (s = !1) => {
658
- const t = a.program.getOptionValue("verbose");
659
- t || (console.info = () => {
842
+ const z = (i = !1) => {
843
+ const s = a.program.getOptionValue("verbose");
844
+ s || (console.info = () => {
660
845
  }), console.info("πŸ“ verbose mode on"), a.options = {
661
846
  configPath: a.program.getOptionValue("config"),
662
- verbose: t
847
+ verbose: s
663
848
  };
664
849
  try {
665
- a.myopConfig = Ce(a.options.configPath);
850
+ a.myopConfig = He(a.options.configPath);
666
851
  } catch (m) {
667
- if (s) {
852
+ if (i) {
668
853
  console.info(`
669
854
  ⚠️ failed read config file from ${a.options.configPath}, trying to create new one`);
670
855
  try {
671
- const l = {
856
+ const d = {
672
857
  author: "@myop-cli",
673
858
  flows: []
674
859
  };
675
- Z(a.options.configPath, l), a.myopConfig = l;
860
+ q(a.options.configPath, d), a.myopConfig = d;
676
861
  } catch {
677
862
  console.log(`
678
863
  ⚠️ failed read config file from ${a.options.configPath}, for more details use verbose flag`), console.info("Error details :", m), process.exit();
@@ -681,61 +866,61 @@ const z = (s = !1) => {
681
866
  console.log(`
682
867
  ⚠️ failed read config file from ${a.options.configPath}, for more details use verbose flag`), console.info("Error details :", m), process.exit();
683
868
  }
684
- }, re = [
685
- se,
686
- ie,
869
+ }, de = [
687
870
  ae,
688
- Oe,
689
- new ye(),
690
- ...Ne
691
- ], je = async () => ve({
871
+ ce,
872
+ le,
873
+ Te,
874
+ new xe(),
875
+ ...je
876
+ ], De = async () => $e({
692
877
  message: "Select an operation",
693
- choices: re
694
- }), ce = async () => {
695
- const s = await je(), t = re.find((m) => m.value === s);
696
- t ? t.action ? await t.action() : console.log(`⚠️ Operation ${s} has no action`) : console.log(`⚠️ Operation ${s} not found`), await ce();
878
+ choices: de
879
+ }), pe = async () => {
880
+ const i = await De(), s = de.find((m) => m.value === i);
881
+ s ? s.action ? await s.action() : console.log(`⚠️ Operation ${i} has no action`) : console.log(`⚠️ Operation ${i} not found`), await pe();
697
882
  };
698
- a.program = new we();
883
+ a.program = new Me();
699
884
  a.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version("0.0.55");
700
- a.program.addOption(new V("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
701
- a.program.addOption(new V("-h, --help", "Show helpful information"));
702
- a.program.addOption(new V("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
703
- a.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((s, t) => {
704
- z(!0), console.info("adding ", s, t, a.options.configPath), s === "flow" && ie._action(t), process.exit();
885
+ a.program.addOption(new Z("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
886
+ a.program.addOption(new Z("-h, --help", "Show helpful information"));
887
+ a.program.addOption(new Z("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
888
+ a.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((i, s) => {
889
+ z(!0), console.info("adding ", i, s, a.options.configPath), i === "flow" && ce._action(s), process.exit();
705
890
  });
706
- a.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((s, t) => {
707
- z(), console.info("removing ", s, t, a.options.configPath), s === "flow" && ae._action(t), process.exit();
891
+ a.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((i, s) => {
892
+ z(), console.info("removing ", i, s, a.options.configPath), i === "flow" && le._action(s), process.exit();
708
893
  });
709
894
  a.program.command("install").description("Install Myop assets").action(async () => {
710
- z(), await se.action();
895
+ z(), await ae.action();
711
896
  });
712
897
  a.program.command("sync").description("Sync Myop configuration").action(async () => {
713
- const s = a.program.getOptionValue("config") || "./myop.config.json", t = await import("fs"), { execSync: m } = await import("child_process"), l = await import("http");
714
- if (t.existsSync(s)) {
898
+ const i = a.program.getOptionValue("config") || "./myop.config.json", s = await import("fs"), { execSync: m } = await import("child_process"), d = await import("http");
899
+ if (s.existsSync(i)) {
715
900
  console.log("yes");
716
901
  try {
717
- const N = t.readFileSync(s, "utf-8"), I = JSON.parse(N);
718
- I.componentId && console.log(I.componentId), console.log("Running npm run build..."), m("npm run build", { stdio: "inherit" });
719
- const E = "./dist/index.html";
720
- if (t.existsSync(E)) {
721
- const D = t.readFileSync(E, "utf-8");
902
+ const I = s.readFileSync(i, "utf-8"), P = JSON.parse(I);
903
+ P.componentId && console.log(P.componentId), console.log("Running npm run build..."), m("npm run build", { stdio: "inherit" });
904
+ const _ = "./dist/index.html";
905
+ if (s.existsSync(_)) {
906
+ const E = s.readFileSync(_, "utf-8");
722
907
  console.log(`
723
- Content of ./dist/index.html:`), console.log(D);
724
- const v = 3302, S = l.default.createServer((b, w) => {
725
- if (b.method === "OPTIONS") {
726
- w.writeHead(200, {
908
+ Content of ./dist/index.html:`), console.log(E);
909
+ const J = 3302, S = d.default.createServer((h, y) => {
910
+ if (h.method === "OPTIONS") {
911
+ y.writeHead(200, {
727
912
  "Access-Control-Allow-Origin": "*",
728
913
  "Access-Control-Allow-Methods": "GET, OPTIONS",
729
914
  "Access-Control-Allow-Headers": "Content-Type"
730
- }), w.end();
915
+ }), y.end();
731
916
  return;
732
917
  }
733
- w.writeHead(200, {
918
+ y.writeHead(200, {
734
919
  "Content-Type": "text/plain",
735
920
  "Access-Control-Allow-Origin": "*",
736
921
  "Access-Control-Allow-Methods": "GET, OPTIONS",
737
922
  "Access-Control-Allow-Headers": "Content-Type"
738
- }), w.end(D), console.log(`
923
+ }), y.end(E), console.log(`
739
924
  Content served successfully, closing server...`), setTimeout(() => {
740
925
  S.close(() => {
741
926
  console.log("Server closed. Sync process completed.");
@@ -744,37 +929,37 @@ Content served successfully, closing server...`), setTimeout(() => {
744
929
  }, 100);
745
930
  }, 100);
746
931
  });
747
- S.listen(v, () => {
748
- const b = `http://localhost:${v}`;
932
+ S.listen(J, () => {
933
+ const h = `http://localhost:${J}`;
749
934
  console.log(`
750
- Server running at ${b}`), console.log("Waiting for request...");
751
- const w = `http://localhost:9200/dashboard/2.0/component/${I.componentId}?upload=${encodeURIComponent(b)}`;
935
+ Server running at ${h}`), console.log("Waiting for request...");
936
+ const y = `http://localhost:9200/dashboard/2.0/component/${P.componentId}?upload=${encodeURIComponent(h)}`;
752
937
  console.log(`
753
- Opening Chrome with: ${w}`);
938
+ Opening Chrome with: ${y}`);
754
939
  try {
755
- m(`open -a "Google Chrome" "${w}"`, { stdio: "inherit" });
756
- } catch (H) {
757
- console.error("Error opening Chrome:", H.message), console.log(`Please open this URL manually: ${w}`);
940
+ m(`open -a "Google Chrome" "${y}"`, { stdio: "inherit" });
941
+ } catch (N) {
942
+ console.error("Error opening Chrome:", N.message), console.log(`Please open this URL manually: ${y}`);
758
943
  }
759
944
  });
760
945
  return;
761
946
  } else
762
947
  console.error("Error: ./dist/index.html not found");
763
- } catch (N) {
764
- console.error("Error:", N.message);
948
+ } catch (I) {
949
+ console.error("Error:", I.message);
765
950
  }
766
951
  } else
767
952
  console.log("no");
768
953
  process.exit();
769
954
  });
770
- a.program.command("dev").description("Start development server with file watching").action(Ae);
955
+ a.program.command("dev").description("Start development server with file watching").action(Ee);
771
956
  a.program.command("default", { isDefault: !0 }).action(async () => {
772
- a.program.getOptionValue("help") && (console.log(Se), process.exit());
773
- let t = he({
957
+ a.program.getOptionValue("help") && (console.log(Pe), process.exit());
958
+ let s = be({
774
959
  text: "Loading Myop CLI...",
775
960
  color: "green"
776
961
  }).start();
777
- z(), await Me(1e3), t.succeed("Myop CLI Loaded"), await ce();
962
+ z(), await Je(1e3), s.succeed("Myop CLI Loaded"), await pe();
778
963
  });
779
964
  a.program.parse(process.argv);
780
965
  a.program.opts();