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