@myop/cli 0.1.19 β 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 +591 -581
- 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 s =
|
|
71
|
-
return console.info("config file loaded, ",
|
|
72
|
-
},
|
|
73
|
-
const s =
|
|
67
|
+
}, et = (e) => {
|
|
68
|
+
const n = q.join(d.executionPath, e);
|
|
69
|
+
console.info(`reading config file from: ${n}`);
|
|
70
|
+
const s = R.readFileSync(n, "utf8"), a = JSON.parse(s);
|
|
71
|
+
return console.info("config file loaded, ", a), a;
|
|
72
|
+
}, ye = (e, n) => {
|
|
73
|
+
const s = q.join(d.executionPath, e);
|
|
74
74
|
console.info(`writing config file to: ${s}`);
|
|
75
75
|
try {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
} catch (
|
|
79
|
-
throw console.info(`error ${
|
|
80
|
-
β οΈ Failed write config file to ${s}, for more info use verbose flag`),
|
|
76
|
+
const a = JSON.stringify(n, null, 2);
|
|
77
|
+
R.writeFileSync(s, a), console.info(`config file updated ${a}`);
|
|
78
|
+
} catch (a) {
|
|
79
|
+
throw console.info(`error ${a} while writing to ${s}, JSON: ${n}`), console.log(`
|
|
80
|
+
β οΈ Failed write config file to ${s}, for more info use verbose flag`), a;
|
|
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>
|
|
@@ -143,7 +143,7 @@ ${s}
|
|
|
143
143
|
<div class="toolbar-title">Myop DevTools</div>
|
|
144
144
|
<div class="toolbar-info">
|
|
145
145
|
<span><div class="status-dot"></div> localhost:${e}</span>
|
|
146
|
-
<span>Management: ${
|
|
146
|
+
<span>Management: ${n}</span>
|
|
147
147
|
</div>
|
|
148
148
|
</div>
|
|
149
149
|
|
|
@@ -211,30 +211,35 @@ ${s}
|
|
|
211
211
|
// Inject PORT as a global variable for the app to use
|
|
212
212
|
window.PORT = ${e};
|
|
213
213
|
|
|
214
|
-
${
|
|
214
|
+
${a}
|
|
215
215
|
<\/script>
|
|
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
|
-
const t = new URL(import.meta.url).pathname,
|
|
224
|
-
c =
|
|
223
|
+
const t = new URL(import.meta.url).pathname, r = process.platform === "win32" && t.startsWith("/") ? t.slice(1) : t;
|
|
224
|
+
c = n.default.dirname(r);
|
|
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
|
-
S = t.componentId || "DEV",
|
|
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
|
|
242
|
+
const A = async () => {
|
|
238
243
|
if (S !== "DEV" && S !== "NEW")
|
|
239
244
|
return S;
|
|
240
245
|
try {
|
|
@@ -245,33 +250,33 @@ async function Re() {
|
|
|
245
250
|
path: "/_list",
|
|
246
251
|
method: "GET",
|
|
247
252
|
timeout: 1e3
|
|
248
|
-
},
|
|
249
|
-
let
|
|
250
|
-
N.on("data", (
|
|
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";
|
|
264
|
-
const
|
|
269
|
+
const r = t.map((l) => {
|
|
265
270
|
if (l === "DEV" || l === "NEW") return 1;
|
|
266
271
|
const p = l.match(/^DEV(\d+)$/), g = l.match(/^NEW(\d+)$/);
|
|
267
272
|
return p ? parseInt(p[1], 10) : g ? parseInt(g[1], 10) : 0;
|
|
268
273
|
}).filter((l) => l > 0);
|
|
269
|
-
return `DEV${Math.max(...
|
|
274
|
+
return `DEV${Math.max(...r, 0) + 1}`;
|
|
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 Re() {
|
|
|
283
288
|
".svg": "image/svg+xml",
|
|
284
289
|
".ico": "image/x-icon"
|
|
285
290
|
}[t] || "application/octet-stream";
|
|
286
|
-
},
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
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,55 +298,55 @@ 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"),
|
|
306
|
-
let
|
|
307
|
-
|
|
309
|
+
}, pe = a.default.createServer((o, t) => {
|
|
310
|
+
if (t.setHeader("Content-Type", "application/json"), o.method === "POST" && o.url === "/_register") {
|
|
311
|
+
let r = "";
|
|
312
|
+
o.on("data", (i) => r += i), o.on("end", () => {
|
|
308
313
|
try {
|
|
309
|
-
const { componentId:
|
|
310
|
-
|
|
314
|
+
const { componentId: i, distPath: l, componentName: p } = JSON.parse(r);
|
|
315
|
+
j.set(i, { path: l, name: p || null });
|
|
311
316
|
const g = p ? ` (${p})` : "";
|
|
312
|
-
console.log(`β
Registered: ${
|
|
313
|
-
const
|
|
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]) => ({
|
|
314
319
|
id: N,
|
|
315
|
-
path:
|
|
316
|
-
name:
|
|
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
|
`);
|
|
326
331
|
} catch {
|
|
327
332
|
}
|
|
328
333
|
});
|
|
329
|
-
} catch (
|
|
330
|
-
t.writeHead(400), t.end(JSON.stringify({ error:
|
|
334
|
+
} catch (i) {
|
|
335
|
+
t.writeHead(400), t.end(JSON.stringify({ error: i.message }));
|
|
331
336
|
}
|
|
332
337
|
});
|
|
333
|
-
} else if (
|
|
334
|
-
let
|
|
335
|
-
|
|
338
|
+
} else if (o.method === "POST" && o.url === "/_unregister") {
|
|
339
|
+
let r = "";
|
|
340
|
+
o.on("data", (i) => r += i), o.on("end", () => {
|
|
336
341
|
try {
|
|
337
|
-
const { componentId:
|
|
338
|
-
|
|
339
|
-
const l = Array.from(
|
|
342
|
+
const { componentId: i } = JSON.parse(r);
|
|
343
|
+
j.delete(i), console.log(`β Unregistered: ${i}`), t.writeHead(200), t.end(JSON.stringify({ success: !0 }));
|
|
344
|
+
const l = Array.from(j.entries()).map(([p, g]) => ({
|
|
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",
|
|
@@ -352,143 +357,143 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
352
357
|
} catch {
|
|
353
358
|
}
|
|
354
359
|
});
|
|
355
|
-
} catch (
|
|
356
|
-
t.writeHead(400), t.end(JSON.stringify({ error:
|
|
360
|
+
} catch (i) {
|
|
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
|
|
366
|
-
if (
|
|
367
|
-
const _ =
|
|
370
|
+
const r = new URL(o.url, `http://localhost:${m}`), i = r.pathname, l = i.split("/").filter((_) => _);
|
|
371
|
+
if (i.startsWith("/consume")) {
|
|
372
|
+
const _ = r.searchParams.get("id");
|
|
368
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
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
452
|
name: _,
|
|
448
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
473
|
console.log(`π‘ Proxying consume request to cloud.myop.dev for: ${_}`);
|
|
469
|
-
const
|
|
470
|
-
|
|
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;
|
|
480
485
|
}
|
|
481
|
-
if (
|
|
486
|
+
if (i === "/events") {
|
|
482
487
|
t.writeHead(200, {
|
|
483
488
|
"Content-Type": "text/event-stream",
|
|
484
489
|
"Cache-Control": "no-cache",
|
|
485
490
|
Connection: "keep-alive",
|
|
486
491
|
"Access-Control-Allow-Origin": "*"
|
|
487
|
-
}),
|
|
488
|
-
const _ = Array.from(
|
|
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",
|
|
@@ -497,22 +502,22 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
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,63 +528,63 @@ 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: ${
|
|
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) => {
|
|
533
538
|
if (_) {
|
|
534
|
-
console.log(`β File not found: ${
|
|
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
|
-
}),
|
|
544
|
-
const
|
|
548
|
+
}), be = () => new Promise((o, t) => {
|
|
549
|
+
const r = JSON.stringify({
|
|
545
550
|
componentId: S,
|
|
546
|
-
distPath:
|
|
547
|
-
componentName:
|
|
548
|
-
}),
|
|
551
|
+
distPath: n.default.resolve(D, b),
|
|
552
|
+
componentName: h
|
|
553
|
+
}), i = {
|
|
549
554
|
hostname: "localhost",
|
|
550
555
|
port: y,
|
|
551
556
|
path: "/_register",
|
|
552
557
|
method: "POST",
|
|
553
558
|
headers: {
|
|
554
559
|
"Content-Type": "application/json",
|
|
555
|
-
"Content-Length": Buffer.byteLength(
|
|
560
|
+
"Content-Length": Buffer.byteLength(r)
|
|
556
561
|
}
|
|
557
|
-
}, l =
|
|
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
|
-
l.on("error", t), l.write(
|
|
564
|
-
}),
|
|
565
|
-
const
|
|
568
|
+
l.on("error", t), l.write(r), l.end();
|
|
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",
|
|
569
574
|
method: "POST",
|
|
570
575
|
headers: {
|
|
571
576
|
"Content-Type": "application/json",
|
|
572
|
-
"Content-Length": Buffer.byteLength(
|
|
577
|
+
"Content-Length": Buffer.byteLength(r)
|
|
573
578
|
}
|
|
574
|
-
}, l =
|
|
575
|
-
|
|
579
|
+
}, l = a.default.request(i, (p) => {
|
|
580
|
+
o();
|
|
576
581
|
});
|
|
577
|
-
l.on("error", () =>
|
|
578
|
-
}),
|
|
582
|
+
l.on("error", () => o()), l.write(r), l.end();
|
|
583
|
+
}), Be = (o) => `
|
|
579
584
|
<!-- MYOP HMR -->
|
|
580
585
|
<script>
|
|
581
586
|
(function() {
|
|
582
|
-
const componentId = '${
|
|
587
|
+
const componentId = '${o}';
|
|
583
588
|
const wsUrl = 'ws://localhost:${y}/_hmr/' + componentId;
|
|
584
589
|
let ws;
|
|
585
590
|
let reconnectAttempts = 0;
|
|
@@ -680,276 +685,280 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
680
685
|
connect();
|
|
681
686
|
})();
|
|
682
687
|
<\/script>
|
|
683
|
-
`,
|
|
684
|
-
if (!
|
|
685
|
-
const
|
|
686
|
-
return
|
|
687
|
-
},
|
|
688
|
-
const t = Buffer.from(
|
|
689
|
-
let
|
|
690
|
-
return
|
|
691
|
-
Buffer.from([129,
|
|
688
|
+
`, xe = (o, t) => {
|
|
689
|
+
if (!C) return o;
|
|
690
|
+
const r = Be(t);
|
|
691
|
+
return o.includes("</body>") ? o.replace("</body>", `${r}</body>`) : o.includes("</html>") ? o.replace("</html>", `${r}</html>`) : o + r;
|
|
692
|
+
}, ze = (o) => {
|
|
693
|
+
const t = Buffer.from(o), r = t.length;
|
|
694
|
+
let i;
|
|
695
|
+
return r < 126 ? i = Buffer.concat([
|
|
696
|
+
Buffer.from([129, r]),
|
|
692
697
|
// FIN + text frame, length
|
|
693
698
|
t
|
|
694
|
-
]) :
|
|
699
|
+
]) : r < 65536 ? i = Buffer.concat([
|
|
695
700
|
Buffer.from([129, 126]),
|
|
696
701
|
// FIN + text frame, extended length
|
|
697
|
-
Buffer.from([
|
|
702
|
+
Buffer.from([r >> 8, r & 255]),
|
|
698
703
|
// 16-bit length
|
|
699
704
|
t
|
|
700
|
-
]) :
|
|
705
|
+
]) : i = Buffer.concat([
|
|
701
706
|
Buffer.from([129, 127]),
|
|
702
707
|
// FIN + text frame, extended length
|
|
703
|
-
Buffer.from([0, 0, 0, 0,
|
|
708
|
+
Buffer.from([0, 0, 0, 0, r >> 24, r >> 16 & 255, r >> 8 & 255, r & 255]),
|
|
704
709
|
// 64-bit length
|
|
705
710
|
t
|
|
706
|
-
]),
|
|
707
|
-
},
|
|
708
|
-
if (!
|
|
709
|
-
const
|
|
710
|
-
if (!
|
|
711
|
+
]), i;
|
|
712
|
+
}, We = () => {
|
|
713
|
+
if (!C) return;
|
|
714
|
+
const o = B.get(S);
|
|
715
|
+
if (!o || o.size === 0)
|
|
711
716
|
return;
|
|
712
|
-
console.log(`π₯ Notifying ${
|
|
713
|
-
const t =
|
|
717
|
+
console.log(`π₯ Notifying ${o.size} HMR client(s)`);
|
|
718
|
+
const t = n.default.join(b, "index.html");
|
|
714
719
|
try {
|
|
715
|
-
const
|
|
720
|
+
const r = e.default.readFileSync(t, "utf-8"), i = xe(r, S), l = JSON.stringify({
|
|
716
721
|
type: "update",
|
|
717
|
-
html:
|
|
718
|
-
}), p =
|
|
719
|
-
|
|
722
|
+
html: i
|
|
723
|
+
}), p = ze(l);
|
|
724
|
+
o.forEach((g) => {
|
|
720
725
|
try {
|
|
721
726
|
g.write(p);
|
|
722
727
|
} catch {
|
|
723
|
-
|
|
728
|
+
o.delete(g);
|
|
724
729
|
}
|
|
725
730
|
});
|
|
726
|
-
} catch (
|
|
727
|
-
console.error("β Failed to read HTML for HMR:",
|
|
731
|
+
} catch (r) {
|
|
732
|
+
console.error("β Failed to read HTML for HMR:", r.message);
|
|
728
733
|
}
|
|
729
734
|
};
|
|
730
|
-
let
|
|
731
|
-
const
|
|
732
|
-
if (
|
|
735
|
+
let Ce = !1;
|
|
736
|
+
const oe = (o) => {
|
|
737
|
+
if (I) {
|
|
733
738
|
v = !0;
|
|
734
739
|
return;
|
|
735
740
|
}
|
|
736
|
-
|
|
737
|
-
π¨ Building...`), s("npm run build", (
|
|
738
|
-
if (
|
|
739
|
-
const
|
|
740
|
-
if (!
|
|
741
|
-
|
|
742
|
-
|
|
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));
|
|
743
748
|
});
|
|
744
749
|
return;
|
|
745
750
|
}
|
|
746
|
-
console.error("β Build failed:",
|
|
751
|
+
console.error("β Build failed:", t.message), i && console.error(i);
|
|
747
752
|
} else
|
|
748
|
-
console.log("β
Build completed"),
|
|
749
|
-
v && (v = !1,
|
|
753
|
+
console.log("β
Build completed"), r && console.log(r), We(), o && o();
|
|
754
|
+
v && (v = !1, oe());
|
|
750
755
|
});
|
|
751
|
-
},
|
|
752
|
-
e.default.readdir(
|
|
753
|
-
t || (
|
|
754
|
-
const l =
|
|
755
|
-
if (
|
|
756
|
-
|
|
757
|
-
else if (
|
|
758
|
-
const p =
|
|
756
|
+
}, $e = /* @__PURE__ */ new Set(), Me = (o) => {
|
|
757
|
+
e.default.readdir(o, { withFileTypes: !0 }, (t, r) => {
|
|
758
|
+
t || (r.forEach((i) => {
|
|
759
|
+
const l = n.default.join(o, i.name);
|
|
760
|
+
if (i.isDirectory())
|
|
761
|
+
i.name !== "node_modules" && i.name !== "dist" && !i.name.startsWith(".") && Me(l);
|
|
762
|
+
else if (i.isFile()) {
|
|
763
|
+
const p = n.default.extname(i.name);
|
|
759
764
|
if (p === ".js" || p === ".css" || p === ".html")
|
|
760
765
|
try {
|
|
761
766
|
const g = e.default.readFileSync(l, "utf-8");
|
|
762
|
-
|
|
767
|
+
F.set(l, g);
|
|
763
768
|
} catch {
|
|
764
769
|
}
|
|
765
770
|
}
|
|
766
|
-
}),
|
|
771
|
+
}), $e.has(o) || ($e.add(o), e.default.watch(o, (i, l) => {
|
|
767
772
|
if (!l) return;
|
|
768
|
-
const p =
|
|
773
|
+
const p = n.default.extname(l);
|
|
769
774
|
if (p !== ".js" && p !== ".css" && p !== ".html") return;
|
|
770
|
-
const g =
|
|
775
|
+
const g = n.default.join(o, l);
|
|
771
776
|
setTimeout(() => {
|
|
772
777
|
try {
|
|
773
|
-
const
|
|
774
|
-
|
|
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());
|
|
775
780
|
} catch {
|
|
776
781
|
}
|
|
777
782
|
}, 50);
|
|
778
783
|
})));
|
|
779
784
|
});
|
|
780
|
-
},
|
|
785
|
+
}, Oe = (o) => {
|
|
781
786
|
console.log(`
|
|
782
|
-
π¨ Component: ${S}`),
|
|
787
|
+
π¨ Component: ${S}`), oe(o), Me(D), console.log("π Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
|
|
783
788
|
`);
|
|
784
|
-
},
|
|
789
|
+
}, Ve = () => new Promise((o) => {
|
|
785
790
|
const t = {
|
|
786
791
|
hostname: "localhost",
|
|
787
792
|
port: y,
|
|
788
793
|
path: "/_list",
|
|
789
794
|
method: "GET",
|
|
790
795
|
timeout: 1e3
|
|
791
|
-
},
|
|
792
|
-
|
|
796
|
+
}, r = a.default.request(t, (i) => {
|
|
797
|
+
o(!0);
|
|
793
798
|
});
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
}),
|
|
797
|
-
}),
|
|
798
|
-
const t =
|
|
799
|
-
if (
|
|
799
|
+
r.on("error", () => o(!1)), r.on("timeout", () => {
|
|
800
|
+
r.destroy(), o(!1);
|
|
801
|
+
}), r.end();
|
|
802
|
+
}), Ge = () => new Promise((o) => {
|
|
803
|
+
const t = a.default.createServer((r, i) => {
|
|
804
|
+
if (i.setHeader("Content-Type", "application/json"), r.method === "POST" && r.url === "/_register") {
|
|
800
805
|
let l = "";
|
|
801
|
-
|
|
806
|
+
r.on("data", (p) => l += p), r.on("end", () => {
|
|
802
807
|
try {
|
|
803
|
-
const { componentId: p, distPath: g, componentName:
|
|
804
|
-
|
|
805
|
-
const N =
|
|
806
|
-
console.log(`β
Registered: ${p}${N} -> ${g}`),
|
|
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()) }));
|
|
807
812
|
} catch (p) {
|
|
808
|
-
|
|
813
|
+
i.writeHead(400), i.end(JSON.stringify({ error: p.message }));
|
|
809
814
|
}
|
|
810
815
|
});
|
|
811
|
-
} else if (
|
|
816
|
+
} else if (r.method === "POST" && r.url === "/_unregister") {
|
|
812
817
|
let l = "";
|
|
813
|
-
|
|
818
|
+
r.on("data", (p) => l += p), r.on("end", () => {
|
|
814
819
|
try {
|
|
815
820
|
const { componentId: p } = JSON.parse(l);
|
|
816
|
-
|
|
821
|
+
j.delete(p), console.log(`β Unregistered: ${p}`), i.writeHead(200), i.end(JSON.stringify({ success: !0 }));
|
|
817
822
|
} catch (p) {
|
|
818
|
-
|
|
823
|
+
i.writeHead(400), i.end(JSON.stringify({ error: p.message }));
|
|
819
824
|
}
|
|
820
825
|
});
|
|
821
|
-
} else
|
|
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" })));
|
|
822
827
|
});
|
|
823
828
|
t.on("error", () => {
|
|
824
|
-
|
|
829
|
+
o(!1);
|
|
825
830
|
}), t.listen(y, () => {
|
|
826
831
|
console.log(`
|
|
827
|
-
π Taking over as server...`), console.log(`π‘ Management server on port ${y}`),
|
|
828
|
-
t.close(),
|
|
829
|
-
}),
|
|
830
|
-
console.log(`π‘ Main server running at http://localhost:${
|
|
831
|
-
path:
|
|
832
|
-
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
|
|
833
838
|
});
|
|
834
|
-
const
|
|
835
|
-
console.log(`β
Registered component: ${S}${
|
|
839
|
+
const r = h ? ` (${h})` : "";
|
|
840
|
+
console.log(`β
Registered component: ${S}${r}`), console.log(`π‘ Access at: http://localhost:${m}/view/${S}/`), o(!0);
|
|
836
841
|
});
|
|
837
842
|
});
|
|
838
843
|
});
|
|
839
|
-
let
|
|
840
|
-
const
|
|
841
|
-
|
|
842
|
-
await
|
|
843
|
-
β οΈ 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 () => {
|
|
844
849
|
try {
|
|
845
|
-
await
|
|
846
|
-
} catch (
|
|
847
|
-
console.error("β Failed to re-register:",
|
|
850
|
+
await be(), console.log(`β
Re-registered component: ${S}`), Ie();
|
|
851
|
+
} catch (r) {
|
|
852
|
+
console.error("β Failed to re-register:", r.message);
|
|
848
853
|
}
|
|
849
854
|
}, 2e3)));
|
|
850
855
|
}, 3e3);
|
|
851
|
-
},
|
|
856
|
+
}, je = async () => {
|
|
852
857
|
console.log(`
|
|
853
858
|
|
|
854
|
-
π Shutting down...`),
|
|
859
|
+
π Shutting down...`), ne && clearInterval(ne), await Ue(), process.exit(0);
|
|
855
860
|
};
|
|
856
|
-
process.on("SIGINT",
|
|
857
|
-
if (
|
|
861
|
+
process.on("SIGINT", je), process.on("SIGTERM", je), pe.on("error", async (o) => {
|
|
862
|
+
if (o.code === "EADDRINUSE") {
|
|
858
863
|
console.log(`
|
|
859
864
|
π Connecting to existing dev server...`);
|
|
860
865
|
try {
|
|
861
|
-
S = await
|
|
862
|
-
const t = await
|
|
863
|
-
console.log(`β
Registered component: ${S}`), console.log(`π‘ Access at: http://localhost:${
|
|
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();
|
|
864
871
|
} catch (t) {
|
|
865
872
|
console.error("β Failed to register component:", t.message), process.exit(1);
|
|
866
873
|
}
|
|
867
874
|
} else
|
|
868
|
-
console.error("β Management server error:",
|
|
869
|
-
}),
|
|
875
|
+
console.error("β Management server error:", o.message), process.exit(1);
|
|
876
|
+
}), pe.on("upgrade", Je), pe.listen(y, async () => {
|
|
870
877
|
console.log(`
|
|
871
|
-
π Starting shared dev server...`), console.log(`π‘ Management server on port ${y}`),
|
|
872
|
-
console.error("β Main server error:",
|
|
873
|
-
}),
|
|
874
|
-
console.log(`π‘ Main server running at http://localhost:${
|
|
875
|
-
path:
|
|
876
|
-
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}/`);
|
|
877
888
|
});
|
|
878
|
-
const n = k ? ` (${k})` : "";
|
|
879
|
-
console.log(`β
Registered component: ${S}${n}`), console.log(`π‘ Access at: http://localhost:${u}/view/${S}/`), Me();
|
|
880
889
|
});
|
|
881
890
|
});
|
|
882
891
|
}
|
|
883
|
-
const
|
|
884
|
-
function
|
|
885
|
-
|
|
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 });
|
|
886
895
|
}
|
|
887
|
-
function
|
|
896
|
+
function we() {
|
|
888
897
|
try {
|
|
889
|
-
if (!
|
|
898
|
+
if (!R.existsSync(Z))
|
|
890
899
|
return null;
|
|
891
|
-
const e =
|
|
900
|
+
const e = R.readFileSync(Z, "utf8");
|
|
892
901
|
return JSON.parse(e);
|
|
893
902
|
} catch (e) {
|
|
894
903
|
return console.info("Failed to read credentials:", e.message), null;
|
|
895
904
|
}
|
|
896
905
|
}
|
|
897
|
-
function
|
|
898
|
-
|
|
899
|
-
const
|
|
906
|
+
function Ae(e) {
|
|
907
|
+
lt();
|
|
908
|
+
const n = {
|
|
900
909
|
...e,
|
|
901
910
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
902
911
|
};
|
|
903
|
-
|
|
912
|
+
R.writeFileSync(Z, JSON.stringify(n, null, 2), {
|
|
904
913
|
mode: 384
|
|
905
914
|
// Read/write for owner only
|
|
906
915
|
});
|
|
907
916
|
}
|
|
908
|
-
function
|
|
917
|
+
function De() {
|
|
909
918
|
try {
|
|
910
|
-
return
|
|
919
|
+
return R.existsSync(Z) && R.unlinkSync(Z), !0;
|
|
911
920
|
} catch (e) {
|
|
912
921
|
return console.error("Failed to clear credentials:", e.message), !1;
|
|
913
922
|
}
|
|
914
923
|
}
|
|
915
|
-
function
|
|
924
|
+
function dt(e) {
|
|
916
925
|
if (!e || !e.expiresAt)
|
|
917
926
|
return !0;
|
|
918
|
-
const
|
|
919
|
-
return Date.now() > s -
|
|
927
|
+
const n = 5 * 60 * 1e3, s = new Date(e.expiresAt).getTime();
|
|
928
|
+
return Date.now() > s - n;
|
|
920
929
|
}
|
|
921
|
-
function
|
|
922
|
-
const e =
|
|
930
|
+
function ve() {
|
|
931
|
+
const e = we();
|
|
923
932
|
return e ? {
|
|
924
933
|
email: e.userEmail,
|
|
925
934
|
userId: e.userId
|
|
926
935
|
} : null;
|
|
927
936
|
}
|
|
928
|
-
const
|
|
929
|
-
function
|
|
930
|
-
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");
|
|
931
940
|
}
|
|
932
|
-
function
|
|
933
|
-
return
|
|
941
|
+
function ut(e) {
|
|
942
|
+
return he.createHash("sha256").update(e).digest("base64url");
|
|
934
943
|
}
|
|
935
|
-
async function
|
|
936
|
-
const e = await fetch(`${
|
|
944
|
+
async function ft() {
|
|
945
|
+
const e = await fetch(`${X}/oauth/register`, {
|
|
937
946
|
method: "POST",
|
|
938
947
|
headers: { "Content-Type": "application/json" },
|
|
939
948
|
body: JSON.stringify({
|
|
940
|
-
client_name:
|
|
941
|
-
redirect_uris: [
|
|
949
|
+
client_name: pt,
|
|
950
|
+
redirect_uris: [Se],
|
|
942
951
|
grant_types: ["authorization_code", "refresh_token"],
|
|
943
952
|
response_types: ["code"]
|
|
944
953
|
})
|
|
945
954
|
});
|
|
946
955
|
if (!e.ok) {
|
|
947
|
-
const
|
|
948
|
-
throw new Error(`Failed to register client: ${
|
|
956
|
+
const n = await e.text();
|
|
957
|
+
throw new Error(`Failed to register client: ${n}`);
|
|
949
958
|
}
|
|
950
959
|
return e.json();
|
|
951
960
|
}
|
|
952
|
-
function
|
|
961
|
+
function re(e, n, s, a = null) {
|
|
953
962
|
const f = {
|
|
954
963
|
success: `<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#4ade80" stroke-width="2">
|
|
955
964
|
<circle cx="12" cy="12" r="10"/>
|
|
@@ -967,13 +976,13 @@ function se(e, o, s, r = null) {
|
|
|
967
976
|
success: { accent: "#4ade80", glow: "rgba(74, 222, 128, 0.1)" },
|
|
968
977
|
error: { accent: "#f87171", glow: "rgba(248, 113, 113, 0.1)" },
|
|
969
978
|
warning: { accent: "#fbbf24", glow: "rgba(251, 191, 36, 0.1)" }
|
|
970
|
-
}, { accent:
|
|
979
|
+
}, { accent: u, glow: w } = c[e] || c.error;
|
|
971
980
|
return `<!DOCTYPE html>
|
|
972
981
|
<html lang="en">
|
|
973
982
|
<head>
|
|
974
983
|
<meta charset="UTF-8">
|
|
975
984
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
976
|
-
<title>myop-cli | ${
|
|
985
|
+
<title>myop-cli | ${n}</title>
|
|
977
986
|
<style>
|
|
978
987
|
* {
|
|
979
988
|
margin: 0;
|
|
@@ -1028,7 +1037,7 @@ function se(e, o, s, r = null) {
|
|
|
1028
1037
|
h1 {
|
|
1029
1038
|
font-size: 20px;
|
|
1030
1039
|
font-weight: 500;
|
|
1031
|
-
color: ${
|
|
1040
|
+
color: ${u};
|
|
1032
1041
|
margin-bottom: 12px;
|
|
1033
1042
|
letter-spacing: -0.5px;
|
|
1034
1043
|
}
|
|
@@ -1061,7 +1070,7 @@ function se(e, o, s, r = null) {
|
|
|
1061
1070
|
align-items: center;
|
|
1062
1071
|
gap: 8px;
|
|
1063
1072
|
background: ${w};
|
|
1064
|
-
border: 1px solid ${
|
|
1073
|
+
border: 1px solid ${u}33;
|
|
1065
1074
|
border-radius: 4px;
|
|
1066
1075
|
padding: 10px 16px;
|
|
1067
1076
|
font-size: 12px;
|
|
@@ -1100,9 +1109,9 @@ function se(e, o, s, r = null) {
|
|
|
1100
1109
|
<div class="icon">
|
|
1101
1110
|
${f[e] || f.error}
|
|
1102
1111
|
</div>
|
|
1103
|
-
<h1>${
|
|
1112
|
+
<h1>${n}</h1>
|
|
1104
1113
|
<p class="message">${s}</p>
|
|
1105
|
-
${
|
|
1114
|
+
${a ? `<div class="details"><code>Error:</code> ${a}</div>` : ""}
|
|
1106
1115
|
<div class="hint">
|
|
1107
1116
|
<span>Press</span>
|
|
1108
1117
|
<kbd>β</kbd><kbd>W</kbd>
|
|
@@ -1115,91 +1124,91 @@ function se(e, o, s, r = null) {
|
|
|
1115
1124
|
</body>
|
|
1116
1125
|
</html>`;
|
|
1117
1126
|
}
|
|
1118
|
-
function
|
|
1119
|
-
return new Promise((
|
|
1120
|
-
const
|
|
1121
|
-
const
|
|
1122
|
-
if (
|
|
1123
|
-
const w =
|
|
1124
|
-
if (
|
|
1125
|
-
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(
|
|
1126
1135
|
"error",
|
|
1127
1136
|
"Authentication Failed",
|
|
1128
1137
|
"Unable to complete the authentication process.",
|
|
1129
|
-
|
|
1130
|
-
)),
|
|
1138
|
+
m
|
|
1139
|
+
)), a.close(), s(new Error(`OAuth error: ${m}`));
|
|
1131
1140
|
return;
|
|
1132
1141
|
}
|
|
1133
|
-
if (
|
|
1134
|
-
c.writeHead(400, { "Content-Type": "text/html" }), c.end(
|
|
1142
|
+
if (O !== e) {
|
|
1143
|
+
c.writeHead(400, { "Content-Type": "text/html" }), c.end(re(
|
|
1135
1144
|
"warning",
|
|
1136
1145
|
"Security Error",
|
|
1137
1146
|
"State mismatch detected. This could indicate a CSRF attack. Please try authenticating again.",
|
|
1138
1147
|
"state_mismatch"
|
|
1139
|
-
)),
|
|
1148
|
+
)), a.close(), s(new Error("State mismatch"));
|
|
1140
1149
|
return;
|
|
1141
1150
|
}
|
|
1142
1151
|
if (!w) {
|
|
1143
|
-
c.writeHead(400, { "Content-Type": "text/html" }), c.end(
|
|
1152
|
+
c.writeHead(400, { "Content-Type": "text/html" }), c.end(re(
|
|
1144
1153
|
"error",
|
|
1145
1154
|
"Missing Authorization Code",
|
|
1146
1155
|
"No authorization code was received from the server.",
|
|
1147
1156
|
"missing_code"
|
|
1148
|
-
)),
|
|
1157
|
+
)), a.close(), s(new Error("No authorization code"));
|
|
1149
1158
|
return;
|
|
1150
1159
|
}
|
|
1151
|
-
c.writeHead(200, { "Content-Type": "text/html" }), c.end(
|
|
1160
|
+
c.writeHead(200, { "Content-Type": "text/html" }), c.end(re(
|
|
1152
1161
|
"success",
|
|
1153
1162
|
"Authentication Successful",
|
|
1154
1163
|
"You have been authenticated successfully. Return to the terminal to continue."
|
|
1155
|
-
)),
|
|
1164
|
+
)), a.close(), n(w);
|
|
1156
1165
|
} else
|
|
1157
1166
|
c.writeHead(404), c.end("Not found");
|
|
1158
1167
|
});
|
|
1159
|
-
|
|
1160
|
-
console.info(`OAuth callback server listening on port ${
|
|
1168
|
+
a.listen(ae, () => {
|
|
1169
|
+
console.info(`OAuth callback server listening on port ${ae}`);
|
|
1161
1170
|
}), setTimeout(() => {
|
|
1162
|
-
|
|
1171
|
+
a.close(), s(new Error("Authentication timed out"));
|
|
1163
1172
|
}, 5 * 60 * 1e3);
|
|
1164
1173
|
});
|
|
1165
1174
|
}
|
|
1166
|
-
async function
|
|
1167
|
-
const
|
|
1175
|
+
async function ht(e, n, s) {
|
|
1176
|
+
const a = await fetch(`${X}/oauth/token`, {
|
|
1168
1177
|
method: "POST",
|
|
1169
1178
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1170
|
-
body: new
|
|
1179
|
+
body: new Ee({
|
|
1171
1180
|
grant_type: "authorization_code",
|
|
1172
1181
|
code: e,
|
|
1173
|
-
client_id:
|
|
1174
|
-
redirect_uri:
|
|
1182
|
+
client_id: n,
|
|
1183
|
+
redirect_uri: Se,
|
|
1175
1184
|
code_verifier: s
|
|
1176
1185
|
})
|
|
1177
1186
|
});
|
|
1178
|
-
if (!
|
|
1179
|
-
const f = await
|
|
1187
|
+
if (!a.ok) {
|
|
1188
|
+
const f = await a.json();
|
|
1180
1189
|
throw new Error(f.error_description || f.error || "Token exchange failed");
|
|
1181
1190
|
}
|
|
1182
|
-
return
|
|
1191
|
+
return a.json();
|
|
1183
1192
|
}
|
|
1184
|
-
async function
|
|
1185
|
-
const s = await fetch(`${
|
|
1193
|
+
async function yt(e, n) {
|
|
1194
|
+
const s = await fetch(`${X}/oauth/token`, {
|
|
1186
1195
|
method: "POST",
|
|
1187
1196
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1188
|
-
body: new
|
|
1197
|
+
body: new Ee({
|
|
1189
1198
|
grant_type: "refresh_token",
|
|
1190
1199
|
refresh_token: e,
|
|
1191
|
-
client_id:
|
|
1200
|
+
client_id: n
|
|
1192
1201
|
})
|
|
1193
1202
|
});
|
|
1194
1203
|
if (!s.ok) {
|
|
1195
|
-
const
|
|
1196
|
-
throw new Error(
|
|
1204
|
+
const a = await s.json();
|
|
1205
|
+
throw new Error(a.error_description || a.error || "Token refresh failed");
|
|
1197
1206
|
}
|
|
1198
1207
|
return s.json();
|
|
1199
1208
|
}
|
|
1200
|
-
async function
|
|
1201
|
-
var f, c,
|
|
1202
|
-
const
|
|
1209
|
+
async function wt(e) {
|
|
1210
|
+
var f, c, u;
|
|
1211
|
+
const n = await fetch(`${X}/mcp`, {
|
|
1203
1212
|
method: "POST",
|
|
1204
1213
|
headers: {
|
|
1205
1214
|
"Content-Type": "application/json",
|
|
@@ -1215,62 +1224,62 @@ async function yt(e) {
|
|
|
1215
1224
|
}
|
|
1216
1225
|
})
|
|
1217
1226
|
});
|
|
1218
|
-
if (!
|
|
1227
|
+
if (!n.ok)
|
|
1219
1228
|
throw new Error("Failed to get user info");
|
|
1220
|
-
const s = await
|
|
1229
|
+
const s = await n.json();
|
|
1221
1230
|
if (s.error)
|
|
1222
1231
|
throw new Error(s.error.message);
|
|
1223
|
-
const
|
|
1224
|
-
if (
|
|
1225
|
-
return JSON.parse(
|
|
1232
|
+
const a = (u = (c = (f = s.result) == null ? void 0 : f.content) == null ? void 0 : c[0]) == null ? void 0 : u.text;
|
|
1233
|
+
if (a)
|
|
1234
|
+
return JSON.parse(a);
|
|
1226
1235
|
throw new Error("Invalid response from whoami");
|
|
1227
1236
|
}
|
|
1228
|
-
async function
|
|
1229
|
-
const e =
|
|
1237
|
+
async function Q() {
|
|
1238
|
+
const e = P("Starting authentication...").start();
|
|
1230
1239
|
try {
|
|
1231
1240
|
e.text = "Registering OAuth client...";
|
|
1232
|
-
const s = (await
|
|
1241
|
+
const s = (await ft()).client_id, a = mt(), f = ut(a), c = he.randomBytes(16).toString("hex");
|
|
1233
1242
|
e.text = "Waiting for authorization...";
|
|
1234
|
-
const
|
|
1235
|
-
w.searchParams.set("response_type", "code"), w.searchParams.set("client_id", s), w.searchParams.set("redirect_uri",
|
|
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(`
|
|
1236
1245
|
π Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${w.toString()}
|
|
1237
|
-
`), await
|
|
1238
|
-
const
|
|
1246
|
+
`), await Qe(w.toString());
|
|
1247
|
+
const O = await u;
|
|
1239
1248
|
e.start("Exchanging authorization code...");
|
|
1240
|
-
const
|
|
1249
|
+
const m = await ht(O, s, a);
|
|
1241
1250
|
e.text = "Getting user info...";
|
|
1242
|
-
const y = await
|
|
1243
|
-
accessToken:
|
|
1244
|
-
refreshToken:
|
|
1245
|
-
expiresAt: new Date(Date.now() +
|
|
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(),
|
|
1246
1255
|
clientId: s,
|
|
1247
1256
|
userId: y.userId,
|
|
1248
1257
|
userEmail: y.email
|
|
1249
1258
|
};
|
|
1250
|
-
return
|
|
1251
|
-
} catch (
|
|
1252
|
-
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;
|
|
1253
1262
|
}
|
|
1254
1263
|
}
|
|
1255
|
-
async function
|
|
1256
|
-
const e =
|
|
1264
|
+
async function He() {
|
|
1265
|
+
const e = we();
|
|
1257
1266
|
if (!e) {
|
|
1258
1267
|
console.log("Not currently logged in.");
|
|
1259
1268
|
return;
|
|
1260
1269
|
}
|
|
1261
|
-
|
|
1270
|
+
De(), console.log(`β
Logged out (was: ${e.userEmail})`);
|
|
1262
1271
|
}
|
|
1263
|
-
async function
|
|
1264
|
-
let e =
|
|
1272
|
+
async function vt() {
|
|
1273
|
+
let e = we();
|
|
1265
1274
|
if (!e)
|
|
1266
1275
|
return console.log(`Not logged in. Starting authentication...
|
|
1267
|
-
`), await
|
|
1268
|
-
if (!
|
|
1276
|
+
`), await Q();
|
|
1277
|
+
if (!dt(e))
|
|
1269
1278
|
return e;
|
|
1270
1279
|
if (e.refreshToken) {
|
|
1271
|
-
const
|
|
1280
|
+
const n = P("Refreshing access token...").start();
|
|
1272
1281
|
try {
|
|
1273
|
-
const s = await
|
|
1282
|
+
const s = await yt(
|
|
1274
1283
|
e.refreshToken,
|
|
1275
1284
|
e.clientId
|
|
1276
1285
|
);
|
|
@@ -1279,48 +1288,48 @@ async function wt() {
|
|
|
1279
1288
|
accessToken: s.access_token,
|
|
1280
1289
|
refreshToken: s.refresh_token,
|
|
1281
1290
|
expiresAt: new Date(Date.now() + s.expires_in * 1e3).toISOString()
|
|
1282
|
-
},
|
|
1291
|
+
}, Ae(e), n.succeed("Token refreshed"), e;
|
|
1283
1292
|
} catch {
|
|
1284
|
-
return
|
|
1293
|
+
return n.warn("Token refresh failed, please log in again"), De(), await Q();
|
|
1285
1294
|
}
|
|
1286
1295
|
}
|
|
1287
1296
|
return console.log(`Session expired. Please log in again.
|
|
1288
|
-
`), await
|
|
1297
|
+
`), await Q();
|
|
1289
1298
|
}
|
|
1290
|
-
function
|
|
1291
|
-
return
|
|
1299
|
+
function St() {
|
|
1300
|
+
return X;
|
|
1292
1301
|
}
|
|
1293
|
-
const
|
|
1294
|
-
async function
|
|
1302
|
+
const ce = "@myop/cli";
|
|
1303
|
+
async function bt() {
|
|
1295
1304
|
try {
|
|
1296
|
-
const e = await fetch(`https://registry.npmjs.org/${
|
|
1305
|
+
const e = await fetch(`https://registry.npmjs.org/${ce}/latest`);
|
|
1297
1306
|
return e.ok ? (await e.json()).version : null;
|
|
1298
1307
|
} catch {
|
|
1299
1308
|
return null;
|
|
1300
1309
|
}
|
|
1301
1310
|
}
|
|
1302
|
-
function
|
|
1303
|
-
const s = e.split(".").map(Number),
|
|
1304
|
-
for (let f = 0; f < Math.max(s.length,
|
|
1305
|
-
const c = s[f] || 0,
|
|
1306
|
-
if (c >
|
|
1307
|
-
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;
|
|
1308
1317
|
}
|
|
1309
1318
|
return 0;
|
|
1310
1319
|
}
|
|
1311
|
-
async function
|
|
1312
|
-
const
|
|
1320
|
+
async function Ct(e) {
|
|
1321
|
+
const n = P({
|
|
1313
1322
|
text: "Checking for updates...",
|
|
1314
1323
|
color: "cyan"
|
|
1315
|
-
}).start(), s = await
|
|
1316
|
-
if (
|
|
1324
|
+
}).start(), s = await bt();
|
|
1325
|
+
if (n.stop(), !s || xt(s, e) <= 0)
|
|
1317
1326
|
return !1;
|
|
1318
1327
|
console.log(`
|
|
1319
1328
|
π¦ New version available: ${e} β ${s}
|
|
1320
1329
|
`);
|
|
1321
|
-
let
|
|
1330
|
+
let a;
|
|
1322
1331
|
try {
|
|
1323
|
-
|
|
1332
|
+
a = await Ne({
|
|
1324
1333
|
message: "Would you like to update now?",
|
|
1325
1334
|
choices: [
|
|
1326
1335
|
{ name: "Yes, update now", value: !0 },
|
|
@@ -1333,49 +1342,49 @@ async function xt(e) {
|
|
|
1333
1342
|
π Goodbye!
|
|
1334
1343
|
`), process.exit(0)), f;
|
|
1335
1344
|
}
|
|
1336
|
-
if (
|
|
1337
|
-
const f =
|
|
1338
|
-
text: `Updating ${
|
|
1345
|
+
if (a) {
|
|
1346
|
+
const f = P({
|
|
1347
|
+
text: `Updating ${ce} to v${s}...`,
|
|
1339
1348
|
color: "green"
|
|
1340
1349
|
}).start();
|
|
1341
1350
|
try {
|
|
1342
|
-
return
|
|
1351
|
+
return ie(`npm install -g ${ce}@latest`, { stdio: "pipe" }), f.succeed(`Updated to v${s}`), console.log(`
|
|
1343
1352
|
π Restarting with new version...
|
|
1344
|
-
`),
|
|
1353
|
+
`), Ke("myop", process.argv.slice(2), {
|
|
1345
1354
|
stdio: "inherit",
|
|
1346
1355
|
shell: !0
|
|
1347
|
-
}).on("close", (
|
|
1348
|
-
process.exit(
|
|
1356
|
+
}).on("close", (u) => {
|
|
1357
|
+
process.exit(u || 0);
|
|
1349
1358
|
}), !0;
|
|
1350
1359
|
} catch {
|
|
1351
1360
|
return f.fail("Update failed"), console.log(`
|
|
1352
|
-
You can manually update by running: npm install -g ${
|
|
1361
|
+
You can manually update by running: npm install -g ${ce}@latest
|
|
1353
1362
|
`), !1;
|
|
1354
1363
|
}
|
|
1355
1364
|
}
|
|
1356
1365
|
return !1;
|
|
1357
1366
|
}
|
|
1358
|
-
const
|
|
1367
|
+
const $t = (e) => new Promise((n) => setTimeout(n, e));
|
|
1359
1368
|
d.executionPath = process.cwd();
|
|
1360
|
-
const
|
|
1361
|
-
const
|
|
1362
|
-
|
|
1369
|
+
const de = (e = !1) => {
|
|
1370
|
+
const n = d.program.getOptionValue("verbose");
|
|
1371
|
+
n || (console.info = () => {
|
|
1363
1372
|
}), console.info("π verbose mode on"), d.options = {
|
|
1364
1373
|
configPath: d.program.getOptionValue("config"),
|
|
1365
|
-
verbose:
|
|
1374
|
+
verbose: n
|
|
1366
1375
|
};
|
|
1367
1376
|
try {
|
|
1368
|
-
return d.myopConfig =
|
|
1377
|
+
return d.myopConfig = et(d.options.configPath), { configFound: !0 };
|
|
1369
1378
|
} catch (s) {
|
|
1370
1379
|
if (e) {
|
|
1371
1380
|
console.info(`
|
|
1372
1381
|
β οΈ failed read config file from ${d.options.configPath}, trying to create new one`);
|
|
1373
1382
|
try {
|
|
1374
|
-
const
|
|
1383
|
+
const a = {
|
|
1375
1384
|
author: "@myop-cli",
|
|
1376
1385
|
flows: []
|
|
1377
1386
|
};
|
|
1378
|
-
return
|
|
1387
|
+
return ye(d.options.configPath, a), d.myopConfig = a, { configFound: !0 };
|
|
1379
1388
|
} catch {
|
|
1380
1389
|
return console.info("Error details :", s), { configFound: !1, error: s };
|
|
1381
1390
|
}
|
|
@@ -1384,75 +1393,75 @@ const le = (e = !1) => {
|
|
|
1384
1393
|
}
|
|
1385
1394
|
};
|
|
1386
1395
|
[
|
|
1387
|
-
new
|
|
1388
|
-
...
|
|
1396
|
+
new fe(),
|
|
1397
|
+
...at
|
|
1389
1398
|
];
|
|
1390
|
-
const
|
|
1391
|
-
d.program = new
|
|
1392
|
-
d.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(
|
|
1393
|
-
d.program.addOption(new
|
|
1394
|
-
d.program.addOption(new
|
|
1395
|
-
d.program.addOption(new
|
|
1396
|
-
d.program.addOption(new
|
|
1397
|
-
d.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((e,
|
|
1398
|
-
|
|
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();
|
|
1399
1408
|
});
|
|
1400
|
-
d.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((e,
|
|
1401
|
-
|
|
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();
|
|
1402
1411
|
});
|
|
1403
1412
|
d.program.command("install").description("Install Myop assets").action(async () => {
|
|
1404
|
-
|
|
1413
|
+
de(), await Te.action();
|
|
1405
1414
|
});
|
|
1406
1415
|
d.program.command("login").description("Authenticate with Myop platform").action(async () => {
|
|
1407
1416
|
try {
|
|
1408
|
-
await
|
|
1417
|
+
await Q();
|
|
1409
1418
|
} catch (e) {
|
|
1410
1419
|
console.error("Login failed:", e.message), process.exit(1);
|
|
1411
1420
|
}
|
|
1412
1421
|
process.exit(0);
|
|
1413
1422
|
});
|
|
1414
1423
|
d.program.command("logout").description("Clear stored credentials").action(async () => {
|
|
1415
|
-
await
|
|
1424
|
+
await He(), process.exit(0);
|
|
1416
1425
|
});
|
|
1417
1426
|
d.program.command("whoami").description("Show current authenticated user").action(async () => {
|
|
1418
|
-
const e =
|
|
1427
|
+
const e = ve();
|
|
1419
1428
|
e && e.email ? console.log(`Logged in as: ${e.email}`) : console.log("Not logged in. Run `myop login` to authenticate."), process.exit(0);
|
|
1420
1429
|
});
|
|
1421
1430
|
d.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (e) => {
|
|
1422
|
-
var
|
|
1423
|
-
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");
|
|
1424
1433
|
let c = {};
|
|
1425
|
-
if (s.existsSync(
|
|
1434
|
+
if (s.existsSync(n))
|
|
1426
1435
|
try {
|
|
1427
|
-
const h = s.readFileSync(
|
|
1436
|
+
const h = s.readFileSync(n, "utf-8");
|
|
1428
1437
|
c = JSON.parse(h);
|
|
1429
|
-
const
|
|
1430
|
-
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}`);
|
|
1431
1440
|
} catch (h) {
|
|
1432
|
-
console.error(`β οΈ Failed to parse ${
|
|
1441
|
+
console.error(`β οΈ Failed to parse ${n}:`, h.message);
|
|
1433
1442
|
}
|
|
1434
1443
|
else
|
|
1435
1444
|
console.log("β οΈ No myop.config.json found. A new component will be created.");
|
|
1436
1445
|
if (!e.skipBuild) {
|
|
1437
|
-
const h =
|
|
1446
|
+
const h = P("Building project...").start();
|
|
1438
1447
|
try {
|
|
1439
|
-
|
|
1440
|
-
} catch (
|
|
1441
|
-
h.fail("Build failed"), console.error(
|
|
1448
|
+
a("npm run build", { stdio: "pipe" }), h.succeed("Build completed");
|
|
1449
|
+
} catch (C) {
|
|
1450
|
+
h.fail("Build failed"), console.error(C.message), process.exit(1);
|
|
1442
1451
|
}
|
|
1443
1452
|
}
|
|
1444
|
-
const
|
|
1445
|
-
s.existsSync(
|
|
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));
|
|
1446
1455
|
let w;
|
|
1447
1456
|
try {
|
|
1448
|
-
w = await
|
|
1457
|
+
w = await vt();
|
|
1449
1458
|
} catch (h) {
|
|
1450
1459
|
console.error("β Authentication failed:", h.message), process.exit(1);
|
|
1451
1460
|
}
|
|
1452
|
-
const
|
|
1453
|
-
let
|
|
1461
|
+
const O = St();
|
|
1462
|
+
let m = P("Requesting upload URL...").start(), y;
|
|
1454
1463
|
try {
|
|
1455
|
-
const h = await fetch(`${
|
|
1464
|
+
const h = await fetch(`${O}/mcp`, {
|
|
1456
1465
|
method: "POST",
|
|
1457
1466
|
headers: {
|
|
1458
1467
|
"Content-Type": "application/json",
|
|
@@ -1474,50 +1483,50 @@ d.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1474
1483
|
});
|
|
1475
1484
|
if (!h.ok)
|
|
1476
1485
|
throw new Error(`Server returned ${h.status}`);
|
|
1477
|
-
const
|
|
1478
|
-
if (
|
|
1479
|
-
throw new Error(
|
|
1480
|
-
const
|
|
1481
|
-
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)
|
|
1482
1491
|
throw new Error(y.error);
|
|
1483
|
-
|
|
1492
|
+
m.succeed("Upload URL obtained");
|
|
1484
1493
|
} catch (h) {
|
|
1485
|
-
|
|
1494
|
+
m.fail("Failed to get upload URL"), console.error(" ", h.message), process.exit(1);
|
|
1486
1495
|
}
|
|
1487
|
-
|
|
1496
|
+
m = P("Uploading component...").start();
|
|
1488
1497
|
try {
|
|
1489
|
-
const h = s.readFileSync(
|
|
1490
|
-
let
|
|
1491
|
-
const
|
|
1492
|
-
if (
|
|
1493
|
-
|
|
1498
|
+
const h = s.readFileSync(u, "utf-8");
|
|
1499
|
+
let C;
|
|
1500
|
+
const A = y.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
|
|
1501
|
+
if (A)
|
|
1502
|
+
C = A[1];
|
|
1494
1503
|
else {
|
|
1495
|
-
const
|
|
1496
|
-
if (
|
|
1497
|
-
|
|
1504
|
+
const V = y.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
|
|
1505
|
+
if (V)
|
|
1506
|
+
C = V[1];
|
|
1498
1507
|
else
|
|
1499
1508
|
throw new Error("Could not parse presigned URL from: " + y.curlCommand);
|
|
1500
1509
|
}
|
|
1501
|
-
console.info("Uploading to:",
|
|
1502
|
-
const
|
|
1510
|
+
console.info("Uploading to:", C.substring(0, 100) + "...");
|
|
1511
|
+
const D = await fetch(C, {
|
|
1503
1512
|
method: "PUT",
|
|
1504
1513
|
headers: {
|
|
1505
1514
|
"Content-Type": "text/html"
|
|
1506
1515
|
},
|
|
1507
1516
|
body: h
|
|
1508
1517
|
});
|
|
1509
|
-
if (!
|
|
1510
|
-
const
|
|
1511
|
-
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}`);
|
|
1512
1521
|
}
|
|
1513
|
-
|
|
1522
|
+
m.succeed("Component uploaded");
|
|
1514
1523
|
} catch (h) {
|
|
1515
|
-
|
|
1524
|
+
m.fail("Upload failed"), console.error(" ", h.message), h.cause && console.error(" Cause:", h.cause), process.exit(1);
|
|
1516
1525
|
}
|
|
1517
|
-
|
|
1526
|
+
m = P("Confirming upload...").start();
|
|
1518
1527
|
let b;
|
|
1519
1528
|
try {
|
|
1520
|
-
const h = await fetch(`${
|
|
1529
|
+
const h = await fetch(`${O}/mcp`, {
|
|
1521
1530
|
method: "POST",
|
|
1522
1531
|
headers: {
|
|
1523
1532
|
"Content-Type": "application/json",
|
|
@@ -1537,43 +1546,43 @@ d.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1537
1546
|
});
|
|
1538
1547
|
if (!h.ok)
|
|
1539
1548
|
throw new Error(`Server returned ${h.status}`);
|
|
1540
|
-
const
|
|
1541
|
-
if (
|
|
1542
|
-
throw new Error(
|
|
1543
|
-
const
|
|
1544
|
-
if (b = JSON.parse(
|
|
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)
|
|
1545
1554
|
throw new Error(b.error);
|
|
1546
|
-
|
|
1555
|
+
m.succeed("Upload confirmed");
|
|
1547
1556
|
} catch (h) {
|
|
1548
|
-
|
|
1557
|
+
m.fail("Confirmation failed"), console.error(" ", h.message), process.exit(1);
|
|
1549
1558
|
}
|
|
1550
1559
|
if (b.isNewComponent || !c.componentId) {
|
|
1551
1560
|
c.componentId = b.componentId, c.organization = b.orgId, c.name || (c.name = b.componentName);
|
|
1552
1561
|
try {
|
|
1553
|
-
s.writeFileSync(
|
|
1554
|
-
π Updated ${
|
|
1562
|
+
s.writeFileSync(n, JSON.stringify(c, null, 2)), console.log(`
|
|
1563
|
+
π Updated ${n} with componentId`);
|
|
1555
1564
|
} catch (h) {
|
|
1556
1565
|
console.log(`
|
|
1557
|
-
β οΈ Could not update ${
|
|
1566
|
+
β οΈ Could not update ${n}: ${h.message}`), console.log(` Please add componentId: "${b.componentId}" manually`);
|
|
1558
1567
|
}
|
|
1559
1568
|
}
|
|
1560
1569
|
console.log(`
|
|
1561
1570
|
β
Sync completed successfully!`), console.log(` Component: ${b.componentName}`), console.log(` Dashboard: ${b.dashboardUrl}`), process.exit(0);
|
|
1562
1571
|
});
|
|
1563
|
-
d.program.command("dev").description("Start development server with file watching").action(
|
|
1564
|
-
const
|
|
1572
|
+
d.program.command("dev").description("Start development server with file watching").action(Fe);
|
|
1573
|
+
const Ot = () => {
|
|
1565
1574
|
try {
|
|
1566
|
-
|
|
1575
|
+
ie("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
1567
1576
|
} catch {
|
|
1568
1577
|
return { gitNotInstalled: !0 };
|
|
1569
1578
|
}
|
|
1570
1579
|
try {
|
|
1571
|
-
|
|
1580
|
+
ie("git rev-parse --git-dir", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
1572
1581
|
} catch {
|
|
1573
1582
|
return { notARepo: !0 };
|
|
1574
1583
|
}
|
|
1575
1584
|
try {
|
|
1576
|
-
const e =
|
|
1585
|
+
const e = ie("git diff --stat HEAD -- . 2>/dev/null || git diff --stat -- . 2>/dev/null", {
|
|
1577
1586
|
encoding: "utf-8",
|
|
1578
1587
|
stdio: ["pipe", "pipe", "pipe"]
|
|
1579
1588
|
}).trim();
|
|
@@ -1583,23 +1592,23 @@ const Mt = () => {
|
|
|
1583
1592
|
insertions: 0,
|
|
1584
1593
|
deletions: 0
|
|
1585
1594
|
};
|
|
1586
|
-
const
|
|
1587
|
-
`), s =
|
|
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/);
|
|
1588
1597
|
return {
|
|
1589
1598
|
files: c ? parseInt(c[1]) : 0,
|
|
1590
|
-
insertions:
|
|
1599
|
+
insertions: a ? parseInt(a[1]) : 0,
|
|
1591
1600
|
deletions: f ? parseInt(f[1]) : 0
|
|
1592
1601
|
};
|
|
1593
1602
|
} catch {
|
|
1594
1603
|
return null;
|
|
1595
1604
|
}
|
|
1596
|
-
},
|
|
1597
|
-
var y, b,
|
|
1598
|
-
const s =
|
|
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();
|
|
1599
1608
|
console.log(`
|
|
1600
1609
|
βββββββββββββββββββββββββββββββββββββββββββββββββββ`), console.log("β β"), console.log("β Welcome to Myop CLI - Remote UI Made Easy β"), console.log("β β"), console.log(`βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
1601
|
-
`), 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: ${
|
|
1602
|
-
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 = [
|
|
1603
1612
|
{
|
|
1604
1613
|
emoji: "π",
|
|
1605
1614
|
label: "Initialize new component",
|
|
@@ -1607,49 +1616,49 @@ const Mt = () => {
|
|
|
1607
1616
|
help: "Creates myop.config.json in current directory",
|
|
1608
1617
|
disabled: e ? "(config already exists)" : !1
|
|
1609
1618
|
},
|
|
1610
|
-
{
|
|
1611
|
-
emoji: "π¦",
|
|
1612
|
-
label: f ? `Push "${f}"` : "Push component",
|
|
1613
|
-
value: "sync",
|
|
1614
|
-
help: "Builds project & uploads dist/index.html to Myop",
|
|
1615
|
-
disabled: e ? r ? !1 : "(login required)" : "(no config file)"
|
|
1616
|
-
},
|
|
1617
1619
|
{
|
|
1618
1620
|
emoji: "π οΈ ",
|
|
1619
1621
|
label: f ? `Start dev mode for "${f}"` : "Start dev mode",
|
|
1620
1622
|
value: "dev",
|
|
1621
1623
|
help: "Starts dev server with HMR for instant preview of changes",
|
|
1622
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)"
|
|
1623
1632
|
}
|
|
1624
1633
|
].map((v) => ({
|
|
1625
|
-
name:
|
|
1634
|
+
name: n && !v.disabled ? `${v.emoji} ${v.label}
|
|
1626
1635
|
${v.help}` : `${v.emoji} ${v.label}`,
|
|
1627
1636
|
value: v.value,
|
|
1628
1637
|
disabled: v.disabled
|
|
1629
1638
|
}));
|
|
1630
|
-
|
|
1631
|
-
new
|
|
1639
|
+
O.push(
|
|
1640
|
+
new fe(),
|
|
1632
1641
|
{
|
|
1633
|
-
name:
|
|
1634
|
-
Clears stored credentials from this machine` :
|
|
1635
|
-
Opens browser to authenticate with Myop` :
|
|
1636
|
-
value:
|
|
1642
|
+
name: n && a ? `π Logout (${s.email})
|
|
1643
|
+
Clears stored credentials from this machine` : n && !a ? `π Login to Myop
|
|
1644
|
+
Opens browser to authenticate with Myop` : a ? `π Logout (${s.email})` : "π Login to Myop",
|
|
1645
|
+
value: a ? "logout" : "login"
|
|
1637
1646
|
},
|
|
1638
1647
|
{
|
|
1639
|
-
name:
|
|
1648
|
+
name: n ? "π Hide help" : "π Show help",
|
|
1640
1649
|
value: "help"
|
|
1641
1650
|
},
|
|
1642
|
-
new
|
|
1651
|
+
new fe(),
|
|
1643
1652
|
{
|
|
1644
1653
|
name: "π Exit",
|
|
1645
1654
|
value: "exit"
|
|
1646
1655
|
}
|
|
1647
1656
|
);
|
|
1648
|
-
let
|
|
1657
|
+
let m;
|
|
1649
1658
|
try {
|
|
1650
|
-
|
|
1659
|
+
m = await Ne({
|
|
1651
1660
|
message: "What would you like to do?",
|
|
1652
|
-
choices:
|
|
1661
|
+
choices: O
|
|
1653
1662
|
});
|
|
1654
1663
|
} catch (v) {
|
|
1655
1664
|
throw v.name === "ExitPromptError" && (console.log(`
|
|
@@ -1657,9 +1666,9 @@ const Mt = () => {
|
|
|
1657
1666
|
π Goodbye!
|
|
1658
1667
|
`), process.exit(0)), v;
|
|
1659
1668
|
}
|
|
1660
|
-
switch (
|
|
1669
|
+
switch (m) {
|
|
1661
1670
|
case "init":
|
|
1662
|
-
await
|
|
1671
|
+
await It();
|
|
1663
1672
|
break;
|
|
1664
1673
|
case "sync":
|
|
1665
1674
|
console.log(`
|
|
@@ -1670,37 +1679,37 @@ Running sync...
|
|
|
1670
1679
|
v("node " + process.argv[1] + " sync", { stdio: "inherit" });
|
|
1671
1680
|
} catch {
|
|
1672
1681
|
}
|
|
1673
|
-
await
|
|
1682
|
+
await z(!0, n);
|
|
1674
1683
|
break;
|
|
1675
1684
|
case "dev":
|
|
1676
|
-
await
|
|
1685
|
+
await Fe();
|
|
1677
1686
|
break;
|
|
1678
1687
|
case "login":
|
|
1679
1688
|
try {
|
|
1680
|
-
await
|
|
1681
|
-
`), await
|
|
1682
|
-
} catch (
|
|
1683
|
-
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);
|
|
1684
1693
|
}
|
|
1685
1694
|
break;
|
|
1686
1695
|
case "logout":
|
|
1687
|
-
await
|
|
1688
|
-
`), await
|
|
1696
|
+
await He(), console.log(`
|
|
1697
|
+
`), await z(e, n);
|
|
1689
1698
|
break;
|
|
1690
1699
|
case "help":
|
|
1691
|
-
await
|
|
1700
|
+
await z(e, !n);
|
|
1692
1701
|
break;
|
|
1693
1702
|
case "exit":
|
|
1694
1703
|
process.exit(0);
|
|
1695
1704
|
}
|
|
1696
|
-
},
|
|
1697
|
-
const { input: e, select:
|
|
1698
|
-
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;
|
|
1699
1708
|
try {
|
|
1700
1709
|
c = await e({
|
|
1701
1710
|
message: "Component name:",
|
|
1702
1711
|
default: f
|
|
1703
|
-
}),
|
|
1712
|
+
}), u = await n({
|
|
1704
1713
|
message: "Component type:",
|
|
1705
1714
|
choices: [
|
|
1706
1715
|
{ name: "π HTML", value: "html", description: "Plain HTML/JS/CSS component" },
|
|
@@ -1709,21 +1718,22 @@ Running sync...
|
|
|
1709
1718
|
{ name: "π
°οΈ Angular", value: "angular", disabled: "(coming soon)" }
|
|
1710
1719
|
]
|
|
1711
1720
|
});
|
|
1712
|
-
} catch (
|
|
1713
|
-
throw
|
|
1721
|
+
} catch (m) {
|
|
1722
|
+
throw m.name === "ExitPromptError" && (console.log(`
|
|
1714
1723
|
|
|
1715
1724
|
π Goodbye!
|
|
1716
|
-
`), process.exit(0)),
|
|
1725
|
+
`), process.exit(0)), m;
|
|
1717
1726
|
}
|
|
1718
1727
|
const w = {
|
|
1719
1728
|
name: c,
|
|
1720
|
-
type:
|
|
1721
|
-
author: "@myop-cli"
|
|
1722
|
-
|
|
1729
|
+
type: u,
|
|
1730
|
+
author: "@myop-cli",
|
|
1731
|
+
HMR: !0
|
|
1732
|
+
}, O = d.program.getOptionValue("config") || "./myop.config.json";
|
|
1723
1733
|
try {
|
|
1724
|
-
s.writeFileSync(
|
|
1725
|
-
β
Created ${
|
|
1726
|
-
const
|
|
1734
|
+
s.writeFileSync(O, JSON.stringify(w, null, 2)), console.log(`
|
|
1735
|
+
β
Created ${O}`);
|
|
1736
|
+
const m = {
|
|
1727
1737
|
name: c.toLowerCase().replace(/\s+/g, "-"),
|
|
1728
1738
|
version: "1.0.0",
|
|
1729
1739
|
type: "module",
|
|
@@ -1735,7 +1745,7 @@ Running sync...
|
|
|
1735
1745
|
esbuild: "^0.24.0"
|
|
1736
1746
|
}
|
|
1737
1747
|
};
|
|
1738
|
-
s.writeFileSync("package.json", JSON.stringify(
|
|
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';
|
|
1739
1749
|
import fs from 'fs';
|
|
1740
1750
|
import path from 'path';
|
|
1741
1751
|
|
|
@@ -1833,7 +1843,7 @@ console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS
|
|
|
1833
1843
|
</html>
|
|
1834
1844
|
`;
|
|
1835
1845
|
s.writeFileSync("index.html", b), console.log("β
Created index.html");
|
|
1836
|
-
const
|
|
1846
|
+
const I = `// ${c} - Entry Point
|
|
1837
1847
|
import { init } from './modules/app.js';
|
|
1838
1848
|
import { setupMyopInterface } from './modules/myop.js';
|
|
1839
1849
|
|
|
@@ -1842,7 +1852,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
1842
1852
|
setupMyopInterface();
|
|
1843
1853
|
});
|
|
1844
1854
|
`;
|
|
1845
|
-
s.writeFileSync("src/index.js",
|
|
1855
|
+
s.writeFileSync("src/index.js", I), console.log("β
Created src/index.js");
|
|
1846
1856
|
const v = `// ${c} - Main Application Logic
|
|
1847
1857
|
|
|
1848
1858
|
export function init() {
|
|
@@ -1867,12 +1877,12 @@ export function setupMyopInterface() {
|
|
|
1867
1877
|
};
|
|
1868
1878
|
}
|
|
1869
1879
|
`), console.log("β
Created src/modules/myop.js");
|
|
1870
|
-
const
|
|
1880
|
+
const F = `/* ${c} - Styles Entry Point */
|
|
1871
1881
|
/* Add your CSS imports here - they will be auto-bundled */
|
|
1872
1882
|
@import './main.css';
|
|
1873
1883
|
`;
|
|
1874
|
-
s.writeFileSync("src/styles/index.css",
|
|
1875
|
-
const
|
|
1884
|
+
s.writeFileSync("src/styles/index.css", F), console.log("β
Created src/styles/index.css");
|
|
1885
|
+
const W = `/* ${c} - Main Styles */
|
|
1876
1886
|
|
|
1877
1887
|
* {
|
|
1878
1888
|
box-sizing: border-box;
|
|
@@ -1901,20 +1911,20 @@ p {
|
|
|
1901
1911
|
line-height: 1.5;
|
|
1902
1912
|
}
|
|
1903
1913
|
`;
|
|
1904
|
-
s.writeFileSync("src/styles/main.css",
|
|
1914
|
+
s.writeFileSync("src/styles/main.css", W), console.log("β
Created src/styles/main.css"), console.log(`
|
|
1905
1915
|
π¦ Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
|
|
1906
|
-
`), d.myopConfig = w, await
|
|
1907
|
-
} catch (
|
|
1908
|
-
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);
|
|
1909
1919
|
}
|
|
1910
1920
|
};
|
|
1911
1921
|
d.program.command("default", { isDefault: !0 }).action(async () => {
|
|
1912
|
-
if (d.program.getOptionValue("help") && (console.log(
|
|
1913
|
-
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();
|
|
1914
1924
|
let y = { found: !1 };
|
|
1915
1925
|
try {
|
|
1916
|
-
if (
|
|
1917
|
-
const
|
|
1926
|
+
if (u.existsSync(w)) {
|
|
1927
|
+
const I = u.readFileSync(w, "utf-8"), v = JSON.parse(I);
|
|
1918
1928
|
y = {
|
|
1919
1929
|
found: !0,
|
|
1920
1930
|
path: w,
|
|
@@ -1923,27 +1933,27 @@ d.program.command("default", { isDefault: !0 }).action(async () => {
|
|
|
1923
1933
|
organization: v.organization || null
|
|
1924
1934
|
};
|
|
1925
1935
|
}
|
|
1926
|
-
} catch (
|
|
1927
|
-
y = { found: !1, error:
|
|
1936
|
+
} catch (I) {
|
|
1937
|
+
y = { found: !1, error: I.message };
|
|
1928
1938
|
}
|
|
1929
1939
|
const b = {
|
|
1930
|
-
version:
|
|
1940
|
+
version: O,
|
|
1931
1941
|
config: y,
|
|
1932
1942
|
auth: {
|
|
1933
|
-
loggedIn: !!(
|
|
1934
|
-
email: (
|
|
1943
|
+
loggedIn: !!(m != null && m.email),
|
|
1944
|
+
email: (m == null ? void 0 : m.email) || null
|
|
1935
1945
|
}
|
|
1936
1946
|
};
|
|
1937
1947
|
console.log(JSON.stringify(b, null, 2)), process.exit(0);
|
|
1938
1948
|
}
|
|
1939
|
-
let s =
|
|
1949
|
+
let s = P({
|
|
1940
1950
|
text: "Loading Myop CLI...",
|
|
1941
1951
|
color: "green"
|
|
1942
1952
|
}).start();
|
|
1943
|
-
const
|
|
1944
|
-
await
|
|
1953
|
+
const a = de();
|
|
1954
|
+
await $t(500), s.stop();
|
|
1945
1955
|
const f = d.program.version();
|
|
1946
|
-
await
|
|
1956
|
+
await Ct(f) || await z(a.configFound);
|
|
1947
1957
|
});
|
|
1948
1958
|
d.program.parse(process.argv);
|
|
1949
1959
|
d.program.opts();
|