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