@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
|
|
3
|
-
import { Separator as
|
|
4
|
-
import { Command as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
const
|
|
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
|
-
},
|
|
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
|
|
56
|
-
const
|
|
57
|
-
console.info(`Generate flow at ${
|
|
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
|
-
},
|
|
62
|
-
const
|
|
63
|
-
console.info(`reading config file from: ${
|
|
64
|
-
const m =
|
|
65
|
-
return console.info("config file loaded, ",
|
|
66
|
-
},
|
|
67
|
-
const m =
|
|
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
|
|
71
|
-
|
|
72
|
-
} catch (
|
|
73
|
-
throw console.info(`error ${
|
|
74
|
-
β οΈ Failed write config file to ${m}, for more info use verbose flag`),
|
|
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
|
-
},
|
|
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: (
|
|
81
|
-
a.myopConfig.flows.includes(
|
|
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
|
-
},
|
|
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: (
|
|
90
|
-
a.myopConfig.flows = a.myopConfig.flows.filter((
|
|
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
|
-
},
|
|
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
|
-
},
|
|
101
|
+
}, Re = {
|
|
102
102
|
name: "π’ Create new component",
|
|
103
103
|
value: "-",
|
|
104
104
|
disabled: "(not available yet)"
|
|
105
|
-
},
|
|
105
|
+
}, Ae = {
|
|
106
106
|
name: "π΅ Create new experience",
|
|
107
107
|
value: "-",
|
|
108
108
|
disabled: "(not available yet)"
|
|
109
|
-
},
|
|
109
|
+
}, Ie = {
|
|
110
110
|
name: "π‘ Create new skin",
|
|
111
111
|
value: "-",
|
|
112
112
|
disabled: "(not available yet)"
|
|
113
|
-
},
|
|
113
|
+
}, _e = {
|
|
114
114
|
name: "π΄ Create new flow",
|
|
115
115
|
value: "-",
|
|
116
116
|
disabled: "(not available yet)"
|
|
117
|
-
},
|
|
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
|
-
},
|
|
123
|
-
function
|
|
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:${
|
|
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:${
|
|
140
|
-
<span>Management: ${
|
|
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 = ${
|
|
206
|
+
window.PORT = ${i};
|
|
206
207
|
|
|
207
|
-
${
|
|
208
|
+
${d}
|
|
208
209
|
<\/script>
|
|
209
210
|
</body>
|
|
210
211
|
</html>`;
|
|
211
212
|
}
|
|
212
|
-
async function
|
|
213
|
-
const
|
|
214
|
-
let
|
|
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
|
-
|
|
218
|
+
P = s.default.dirname(o);
|
|
218
219
|
} else
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
let
|
|
222
|
-
const
|
|
223
|
-
let
|
|
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 =
|
|
226
|
-
|
|
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
|
|
231
|
-
const e =
|
|
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
|
-
},
|
|
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
|
|
246
|
-
o.on("data", (n) =>
|
|
264
|
+
let t = "";
|
|
265
|
+
o.on("data", (n) => t += n), o.on("end", () => {
|
|
247
266
|
try {
|
|
248
|
-
const { componentId: n, distPath:
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
console.log(`β
Registered: ${n}${
|
|
252
|
-
const
|
|
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:
|
|
255
|
-
name:
|
|
273
|
+
path: j.path,
|
|
274
|
+
name: j.name
|
|
256
275
|
}));
|
|
257
|
-
|
|
276
|
+
$.forEach((C) => {
|
|
258
277
|
try {
|
|
259
278
|
C.write(`data: ${JSON.stringify({
|
|
260
279
|
type: "components",
|
|
261
|
-
components:
|
|
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
|
|
274
|
-
o.on("data", (n) =>
|
|
292
|
+
let t = "";
|
|
293
|
+
o.on("data", (n) => t += n), o.on("end", () => {
|
|
275
294
|
try {
|
|
276
|
-
const { componentId: n } = JSON.parse(
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
id:
|
|
280
|
-
path:
|
|
281
|
-
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
|
-
|
|
302
|
+
$.forEach((r) => {
|
|
284
303
|
try {
|
|
285
|
-
|
|
304
|
+
r.write(`data: ${JSON.stringify({
|
|
286
305
|
type: "components",
|
|
287
|
-
components:
|
|
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(
|
|
299
|
-
}),
|
|
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
|
|
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
|
|
307
|
-
if (!
|
|
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
|
|
312
|
-
let
|
|
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
|
|
317
|
-
|
|
335
|
+
const A = new URL(f);
|
|
336
|
+
p = A.origin, O = A.hostname || A.origin;
|
|
318
337
|
} catch {
|
|
319
|
-
|
|
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
|
-
|
|
343
|
+
p = f.origin, O = f.hostname || f.origin;
|
|
325
344
|
} catch {
|
|
326
|
-
|
|
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" ? (
|
|
349
|
+
f === "::1" || f === "::ffff:127.0.0.1" ? (p = "localhost", O = "localhost (direct)") : (p = f, O = f.replace("::ffff:", ""));
|
|
331
350
|
}
|
|
332
|
-
const
|
|
351
|
+
const Q = o.headers.referer || o.headers.referrer || p, W = {
|
|
333
352
|
type: "request",
|
|
334
|
-
componentId:
|
|
353
|
+
componentId: v,
|
|
335
354
|
timestamp: Date.now(),
|
|
336
|
-
servedLocally:
|
|
337
|
-
referrer:
|
|
338
|
-
origin:
|
|
355
|
+
servedLocally: R,
|
|
356
|
+
referrer: Q,
|
|
357
|
+
origin: p,
|
|
339
358
|
originLabel: O
|
|
340
359
|
};
|
|
341
|
-
|
|
342
|
-
url:
|
|
360
|
+
T.has(p) || (T.set(p, {
|
|
361
|
+
url: p,
|
|
343
362
|
label: O,
|
|
344
363
|
firstSeen: Date.now(),
|
|
345
364
|
requestCount: 0
|
|
346
|
-
}),
|
|
365
|
+
}), $.forEach((f) => {
|
|
347
366
|
try {
|
|
348
367
|
f.write(`data: ${JSON.stringify({
|
|
349
368
|
type: "origins",
|
|
350
|
-
origins: Array.from(
|
|
369
|
+
origins: Array.from(T.values())
|
|
351
370
|
})}
|
|
352
371
|
|
|
353
372
|
`);
|
|
354
373
|
} catch {
|
|
355
374
|
}
|
|
356
375
|
}));
|
|
357
|
-
const
|
|
358
|
-
|
|
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(
|
|
381
|
+
origins: Array.from(T.values())
|
|
363
382
|
})}
|
|
364
383
|
|
|
365
384
|
`);
|
|
366
385
|
} catch {
|
|
367
386
|
}
|
|
368
|
-
}),
|
|
387
|
+
}), U.push(W), U.length > ge && U.shift(), $.forEach((f) => {
|
|
369
388
|
try {
|
|
370
|
-
f.write(`data: ${JSON.stringify(
|
|
389
|
+
f.write(`data: ${JSON.stringify(W)}
|
|
371
390
|
|
|
372
391
|
`);
|
|
373
392
|
} catch {
|
|
374
393
|
}
|
|
375
394
|
});
|
|
376
395
|
};
|
|
377
|
-
if (
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
if (
|
|
381
|
-
console.log(`β File 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
|
|
403
|
+
const Q = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, W = {
|
|
385
404
|
item: {
|
|
386
|
-
name:
|
|
387
|
-
id:
|
|
405
|
+
name: v,
|
|
406
|
+
id: v,
|
|
388
407
|
consume_variant: [
|
|
389
408
|
{
|
|
390
|
-
id:
|
|
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: ${
|
|
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(
|
|
423
|
+
}), e.end(JSON.stringify(W, null, 2));
|
|
405
424
|
});
|
|
406
425
|
} else {
|
|
407
|
-
console.log(`π‘ Proxying consume request to cloud.myop.dev for: ${
|
|
408
|
-
const
|
|
409
|
-
|
|
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(
|
|
414
|
-
}).catch((
|
|
415
|
-
console.error(`β Proxy error: ${
|
|
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
|
-
}),
|
|
427
|
-
const
|
|
428
|
-
id:
|
|
429
|
-
path:
|
|
430
|
-
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:
|
|
453
|
+
components: v
|
|
435
454
|
})}
|
|
436
455
|
|
|
437
456
|
`), e.write(`data: ${JSON.stringify({
|
|
438
457
|
type: "origins",
|
|
439
|
-
origins: Array.from(
|
|
458
|
+
origins: Array.from(T.values())
|
|
440
459
|
})}
|
|
441
460
|
|
|
442
461
|
`), e.write(`data: ${JSON.stringify({
|
|
443
462
|
type: "requestLog",
|
|
444
|
-
log:
|
|
463
|
+
log: U
|
|
445
464
|
})}
|
|
446
465
|
|
|
447
466
|
`), o.on("close", () => {
|
|
448
|
-
const
|
|
449
|
-
|
|
467
|
+
const b = $.indexOf(e);
|
|
468
|
+
b !== -1 && $.splice(b, 1);
|
|
450
469
|
});
|
|
451
470
|
return;
|
|
452
471
|
}
|
|
453
|
-
if (
|
|
454
|
-
e.writeHead(200, { "Content-Type": "text/html" }), e.end(
|
|
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 (
|
|
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 (
|
|
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
|
|
466
|
-
if (!
|
|
467
|
-
e.writeHead(404, { "Content-Type": "text/plain" }), e.end(`Component not found: ${
|
|
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
|
|
471
|
-
console.log(`π₯ Request: ${o.url} -> ${F}`),
|
|
472
|
-
if (
|
|
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
|
|
477
|
-
console.log(`β
Serving: ${F} (${
|
|
478
|
-
"Content-Type":
|
|
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
|
-
}),
|
|
483
|
-
const
|
|
484
|
-
componentId:
|
|
485
|
-
distPath:
|
|
486
|
-
componentName:
|
|
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:
|
|
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(
|
|
513
|
+
"Content-Length": Buffer.byteLength(t)
|
|
495
514
|
}
|
|
496
|
-
},
|
|
497
|
-
let
|
|
498
|
-
|
|
499
|
-
|
|
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
|
-
|
|
503
|
-
}),
|
|
504
|
-
const
|
|
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:
|
|
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(
|
|
530
|
+
"Content-Length": Buffer.byteLength(t)
|
|
512
531
|
}
|
|
513
|
-
},
|
|
532
|
+
}, c = d.default.request(n, (r) => {
|
|
514
533
|
o();
|
|
515
534
|
});
|
|
516
|
-
|
|
517
|
-
}),
|
|
518
|
-
if (
|
|
519
|
-
|
|
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
|
-
|
|
523
|
-
π¨ Building...`), m("npm run build", (o, e,
|
|
524
|
-
|
|
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
|
-
},
|
|
527
|
-
|
|
528
|
-
e ||
|
|
529
|
-
const
|
|
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(".") &&
|
|
716
|
+
n.name !== "node_modules" && n.name !== "dist" && !n.name.startsWith(".") && oe(c);
|
|
532
717
|
else if (n.isFile()) {
|
|
533
|
-
const
|
|
534
|
-
if (
|
|
718
|
+
const r = s.default.extname(n.name);
|
|
719
|
+
if (r === ".js" || r === ".css" || r === ".html") {
|
|
535
720
|
try {
|
|
536
|
-
const
|
|
537
|
-
|
|
721
|
+
const l = i.default.readFileSync(c, "utf-8");
|
|
722
|
+
V.set(c, l);
|
|
538
723
|
} catch {
|
|
539
724
|
}
|
|
540
|
-
|
|
541
|
-
if (
|
|
725
|
+
i.default.watch(c, (l) => {
|
|
726
|
+
if (l === "change")
|
|
542
727
|
try {
|
|
543
|
-
const
|
|
544
|
-
|
|
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: ${
|
|
731
|
+
console.log(`π File changed: ${c}`), B();
|
|
547
732
|
}
|
|
548
733
|
});
|
|
549
734
|
}
|
|
550
735
|
}
|
|
551
736
|
});
|
|
552
737
|
});
|
|
553
|
-
},
|
|
738
|
+
}, te = () => {
|
|
554
739
|
console.log(`
|
|
555
|
-
π¨ Component: ${
|
|
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
|
-
},
|
|
742
|
+
}, Se = () => new Promise((o) => {
|
|
558
743
|
const e = {
|
|
559
744
|
hostname: "localhost",
|
|
560
|
-
port:
|
|
745
|
+
port: h,
|
|
561
746
|
path: "/_list",
|
|
562
747
|
method: "GET",
|
|
563
748
|
timeout: 1e3
|
|
564
|
-
},
|
|
749
|
+
}, t = d.default.request(e, (n) => {
|
|
565
750
|
o(!0);
|
|
566
751
|
});
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}),
|
|
570
|
-
}),
|
|
571
|
-
const e =
|
|
572
|
-
if (n.setHeader("Content-Type", "application/json"),
|
|
573
|
-
let
|
|
574
|
-
|
|
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:
|
|
577
|
-
|
|
578
|
-
const C =
|
|
579
|
-
console.log(`β
Registered: ${
|
|
580
|
-
} catch (
|
|
581
|
-
n.writeHead(400), n.end(JSON.stringify({ error:
|
|
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 (
|
|
585
|
-
let
|
|
586
|
-
|
|
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:
|
|
589
|
-
|
|
590
|
-
} catch (
|
|
591
|
-
n.writeHead(400), n.end(JSON.stringify({ error:
|
|
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
|
|
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(
|
|
783
|
+
}), e.listen(h, () => {
|
|
599
784
|
console.log(`
|
|
600
|
-
π Taking over as server...`), console.log(`π‘ Management server on port ${
|
|
785
|
+
π Taking over as server...`), console.log(`π‘ Management server on port ${h}`), k.on("error", () => {
|
|
601
786
|
e.close(), o(!1);
|
|
602
|
-
}),
|
|
603
|
-
console.log(`π‘ Main server running at http://localhost:${
|
|
604
|
-
path:
|
|
605
|
-
name:
|
|
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
|
|
608
|
-
console.log(`β
Registered component: ${
|
|
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
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
await
|
|
616
|
-
β οΈ Server appears to be down, attempting to take over...`), await
|
|
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
|
|
619
|
-
} catch (
|
|
620
|
-
console.error("β Failed to re-register:",
|
|
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
|
-
},
|
|
809
|
+
}, se = async () => {
|
|
625
810
|
console.log(`
|
|
626
811
|
|
|
627
|
-
π Shutting down...`),
|
|
812
|
+
π Shutting down...`), G && clearInterval(G), await he(), process.exit(0);
|
|
628
813
|
};
|
|
629
|
-
process.on("SIGINT",
|
|
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
|
|
635
|
-
console.log(`β
Registered component: ${
|
|
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
|
-
}),
|
|
826
|
+
}), X.on("upgrade", ue), X.listen(h, async () => {
|
|
642
827
|
console.log(`
|
|
643
|
-
π Starting shared dev server...`), console.log(`π‘ Management server on port ${
|
|
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
|
-
}),
|
|
646
|
-
console.log(`π‘ Main server running at http://localhost:${
|
|
647
|
-
path:
|
|
648
|
-
name:
|
|
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 =
|
|
651
|
-
console.log(`β
Registered component: ${
|
|
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
|
|
840
|
+
const Je = (i) => new Promise((s) => setTimeout(s, i));
|
|
656
841
|
a.executionPath = process.cwd();
|
|
657
|
-
const z = (
|
|
658
|
-
const
|
|
659
|
-
|
|
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:
|
|
847
|
+
verbose: s
|
|
663
848
|
};
|
|
664
849
|
try {
|
|
665
|
-
a.myopConfig =
|
|
850
|
+
a.myopConfig = He(a.options.configPath);
|
|
666
851
|
} catch (m) {
|
|
667
|
-
if (
|
|
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
|
|
856
|
+
const d = {
|
|
672
857
|
author: "@myop-cli",
|
|
673
858
|
flows: []
|
|
674
859
|
};
|
|
675
|
-
|
|
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
|
-
},
|
|
685
|
-
se,
|
|
686
|
-
ie,
|
|
869
|
+
}, de = [
|
|
687
870
|
ae,
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
871
|
+
ce,
|
|
872
|
+
le,
|
|
873
|
+
Te,
|
|
874
|
+
new xe(),
|
|
875
|
+
...je
|
|
876
|
+
], De = async () => $e({
|
|
692
877
|
message: "Select an operation",
|
|
693
|
-
choices:
|
|
694
|
-
}),
|
|
695
|
-
const
|
|
696
|
-
|
|
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
|
|
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
|
|
701
|
-
a.program.addOption(new
|
|
702
|
-
a.program.addOption(new
|
|
703
|
-
a.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((
|
|
704
|
-
z(!0), console.info("adding ",
|
|
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((
|
|
707
|
-
z(), console.info("removing ",
|
|
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
|
|
895
|
+
z(), await ae.action();
|
|
711
896
|
});
|
|
712
897
|
a.program.command("sync").description("Sync Myop configuration").action(async () => {
|
|
713
|
-
const
|
|
714
|
-
if (
|
|
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
|
|
718
|
-
|
|
719
|
-
const
|
|
720
|
-
if (
|
|
721
|
-
const
|
|
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(
|
|
724
|
-
const
|
|
725
|
-
if (
|
|
726
|
-
|
|
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
|
-
}),
|
|
915
|
+
}), y.end();
|
|
731
916
|
return;
|
|
732
917
|
}
|
|
733
|
-
|
|
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
|
-
}),
|
|
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(
|
|
748
|
-
const
|
|
932
|
+
S.listen(J, () => {
|
|
933
|
+
const h = `http://localhost:${J}`;
|
|
749
934
|
console.log(`
|
|
750
|
-
Server running at ${
|
|
751
|
-
const
|
|
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: ${
|
|
938
|
+
Opening Chrome with: ${y}`);
|
|
754
939
|
try {
|
|
755
|
-
m(`open -a "Google Chrome" "${
|
|
756
|
-
} catch (
|
|
757
|
-
console.error("Error opening Chrome:",
|
|
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 (
|
|
764
|
-
console.error("Error:",
|
|
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(
|
|
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(
|
|
773
|
-
let
|
|
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
|
|
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();
|