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