@myop/cli 0.1.38 β 0.1.41
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 +1261 -865
- package/dist/skills/myop-component/SKILL.md +233 -0
- package/dist/skills/myop-component/references/best-practices.md +406 -0
- package/dist/skills/myop-component/references/component-api.md +357 -0
- package/dist/skills/myop-component/references/dev-workflow.md +218 -0
- package/dist/skills/myop-component/references/sizing-and-layout.md +270 -0
- package/dist/skills/myop-component/references/type-definitions.md +270 -0
- package/package.json +2 -2
package/dist/myop-cli.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
import
|
|
6
|
-
import { select as
|
|
7
|
-
import { Command as
|
|
8
|
-
import { execSync as
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { URL as
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
const
|
|
2
|
+
var ut = Object.defineProperty;
|
|
3
|
+
var gt = (o, e, t) => e in o ? ut(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
4
|
+
var ye = (o, e, t) => gt(o, typeof e != "symbol" ? e + "" : e, t);
|
|
5
|
+
import G from "ora";
|
|
6
|
+
import { select as Ye, Separator as Fe } from "@inquirer/prompts";
|
|
7
|
+
import { Command as ft, Option as me } from "commander";
|
|
8
|
+
import { execSync as q, spawn as ht } from "child_process";
|
|
9
|
+
import H, { join as Oe } from "path";
|
|
10
|
+
import R, { readFileSync as yt } from "fs";
|
|
11
|
+
import Le from "crypto";
|
|
12
|
+
import wt from "http";
|
|
13
|
+
import { URL as Ke, URLSearchParams as Qe } from "url";
|
|
14
|
+
import St from "open";
|
|
15
|
+
import vt from "os";
|
|
16
|
+
const bt = `
|
|
17
17
|
Usage: myop [OPTIONS] COMMAND [ARGS]...
|
|
18
18
|
|
|
19
19
|
A powerful command-line interface for managing your Myop projects.
|
|
@@ -55,81 +55,81 @@ Examples:
|
|
|
55
55
|
verbose: !1
|
|
56
56
|
},
|
|
57
57
|
myopConfig: null
|
|
58
|
-
},
|
|
58
|
+
}, Ze = {
|
|
59
59
|
name: "π₯ Install Myop generated dependencies",
|
|
60
60
|
value: "myopInstall",
|
|
61
61
|
description: "Fetch and generates Myop dependencies. flows including components, refs and props.",
|
|
62
62
|
action: async () => {
|
|
63
63
|
console.info("installing... ");
|
|
64
64
|
for (const o of y.myopConfig.flows) {
|
|
65
|
-
const e =
|
|
65
|
+
const e = H.join(y.executionPath, "/node_modules/@myop/flow-types/");
|
|
66
66
|
console.info(`Generate flow at ${e}`), console.info(`Generated flow at ${e}`);
|
|
67
67
|
}
|
|
68
68
|
process.exit();
|
|
69
69
|
}
|
|
70
|
-
},
|
|
71
|
-
const e =
|
|
70
|
+
}, xt = (o) => {
|
|
71
|
+
const e = H.join(y.executionPath, o);
|
|
72
72
|
console.info(`reading config file from: ${e}`);
|
|
73
|
-
const t =
|
|
73
|
+
const t = R.readFileSync(e, "utf8"), n = JSON.parse(t);
|
|
74
74
|
return console.info("config file loaded, ", n), n;
|
|
75
|
-
},
|
|
76
|
-
const t =
|
|
75
|
+
}, Ae = (o, e) => {
|
|
76
|
+
const t = H.join(y.executionPath, o);
|
|
77
77
|
console.info(`writing config file to: ${t}`);
|
|
78
78
|
try {
|
|
79
79
|
const n = JSON.stringify(e, null, 2);
|
|
80
|
-
|
|
80
|
+
R.writeFileSync(t, n), console.info(`config file updated ${n}`);
|
|
81
81
|
} catch (n) {
|
|
82
82
|
throw console.info(`error ${n} while writing to ${t}, JSON: ${e}`), console.log(`
|
|
83
83
|
β οΈ Failed write config file to ${t}, for more info use verbose flag`), n;
|
|
84
84
|
}
|
|
85
|
-
},
|
|
85
|
+
}, Xe = {
|
|
86
86
|
name: "π Add flow definition to your project",
|
|
87
87
|
value: "addFlow",
|
|
88
88
|
description: "Adds flow to yours myop.config.json",
|
|
89
89
|
_action: (o) => {
|
|
90
|
-
y.myopConfig.flows.includes(o) || y.myopConfig.flows.push(o),
|
|
90
|
+
y.myopConfig.flows.includes(o) || y.myopConfig.flows.push(o), Ae(y.options.configPath, y.myopConfig);
|
|
91
91
|
},
|
|
92
92
|
action: async () => {
|
|
93
93
|
}
|
|
94
|
-
},
|
|
94
|
+
}, qe = {
|
|
95
95
|
name: "π« Remove flow definition from your project",
|
|
96
96
|
value: "removeFlow",
|
|
97
97
|
description: "Removes flow to yours myop.config.json",
|
|
98
98
|
_action: (o) => {
|
|
99
|
-
y.myopConfig.flows = y.myopConfig.flows.filter((e) => e !== o),
|
|
99
|
+
y.myopConfig.flows = y.myopConfig.flows.filter((e) => e !== o), Ae(y.options.configPath, y.myopConfig);
|
|
100
100
|
},
|
|
101
101
|
action: () => {
|
|
102
102
|
}
|
|
103
|
-
},
|
|
103
|
+
}, $t = {
|
|
104
104
|
name: "π Quit",
|
|
105
105
|
value: "quit",
|
|
106
106
|
description: "Quit and continue coding.",
|
|
107
107
|
action: () => {
|
|
108
108
|
process.exit();
|
|
109
109
|
}
|
|
110
|
-
},
|
|
110
|
+
}, Ct = {
|
|
111
111
|
name: "π’ Create new component",
|
|
112
112
|
value: "-",
|
|
113
113
|
disabled: "(not available yet)"
|
|
114
|
-
},
|
|
114
|
+
}, Mt = {
|
|
115
115
|
name: "π΅ Create new experience",
|
|
116
116
|
value: "-",
|
|
117
117
|
disabled: "(not available yet)"
|
|
118
|
-
},
|
|
118
|
+
}, Pt = {
|
|
119
119
|
name: "π‘ Create new skin",
|
|
120
120
|
value: "-",
|
|
121
121
|
disabled: "(not available yet)"
|
|
122
|
-
},
|
|
122
|
+
}, Tt = {
|
|
123
123
|
name: "π΄ Create new flow",
|
|
124
124
|
value: "-",
|
|
125
125
|
disabled: "(not available yet)"
|
|
126
|
-
},
|
|
126
|
+
}, Rt = {
|
|
127
127
|
name: "π Define new custom Myop message",
|
|
128
128
|
value: "generateMyopMessage",
|
|
129
129
|
description: "οΈHelp you creates the right structure for a new Myop message, including types and handlers.",
|
|
130
130
|
disabled: "(not available yet)"
|
|
131
|
-
},
|
|
132
|
-
function
|
|
131
|
+
}, Et = [Rt, Ct, Mt, Pt, Tt];
|
|
132
|
+
function It(o, e, t, n) {
|
|
133
133
|
return `<!DOCTYPE html>
|
|
134
134
|
<html lang="en">
|
|
135
135
|
<head>
|
|
@@ -219,34 +219,34 @@ ${n}
|
|
|
219
219
|
</body>
|
|
220
220
|
</html>`;
|
|
221
221
|
}
|
|
222
|
-
function
|
|
222
|
+
function Ot(o) {
|
|
223
223
|
return o.includes("esbuild") && o.includes("another platform");
|
|
224
224
|
}
|
|
225
|
-
function
|
|
225
|
+
function kt(o) {
|
|
226
226
|
return o.includes("ERR_MODULE_NOT_FOUND") && o.includes("esbuild");
|
|
227
227
|
}
|
|
228
|
-
function
|
|
228
|
+
function Ft() {
|
|
229
229
|
console.error(`
|
|
230
230
|
β esbuild platform mismatch detected!`), console.error(" Your node_modules contains esbuild binaries for a different OS."), console.error(`
|
|
231
231
|
This usually happens when node_modules is copied between different`), console.error(` operating systems (e.g., Windows β Mac, or Mac β Linux).
|
|
232
232
|
`);
|
|
233
233
|
}
|
|
234
|
-
function
|
|
234
|
+
function jt(o) {
|
|
235
235
|
return new Promise((e) => {
|
|
236
236
|
console.log(`π§ Attempting to fix: removing node_modules and reinstalling...
|
|
237
237
|
`);
|
|
238
238
|
const n = process.platform === "win32" ? "rmdir /s /q node_modules" : "rm -rf node_modules";
|
|
239
|
-
o(n, (
|
|
240
|
-
if (
|
|
241
|
-
console.error("β Failed to remove node_modules:",
|
|
239
|
+
o(n, (i) => {
|
|
240
|
+
if (i) {
|
|
241
|
+
console.error("β Failed to remove node_modules:", i.message), console.error(`
|
|
242
242
|
Please run manually:`), console.error(` \x1B[36m${n} && npm install\x1B[0m
|
|
243
243
|
`), e(!1);
|
|
244
244
|
return;
|
|
245
245
|
}
|
|
246
246
|
console.log(" β Removed node_modules"), console.log(` β³ Running npm install...
|
|
247
|
-
`), o("npm install", { maxBuffer: 10 * 1024 * 1024 }, (s,
|
|
247
|
+
`), o("npm install", { maxBuffer: 10 * 1024 * 1024 }, (s, l, w) => {
|
|
248
248
|
if (s) {
|
|
249
|
-
console.error("β npm install failed:", s.message),
|
|
249
|
+
console.error("β npm install failed:", s.message), w && console.error(w), e(!1);
|
|
250
250
|
return;
|
|
251
251
|
}
|
|
252
252
|
console.log(` β Dependencies reinstalled successfully!
|
|
@@ -255,101 +255,101 @@ function Rt(o) {
|
|
|
255
255
|
});
|
|
256
256
|
});
|
|
257
257
|
}
|
|
258
|
-
async function
|
|
258
|
+
async function et(o, e, t, n, i = {}) {
|
|
259
259
|
const {
|
|
260
260
|
hasTriedPlatformFix: s = !1,
|
|
261
|
-
hasTriedInstall:
|
|
262
|
-
onRetry:
|
|
263
|
-
} =
|
|
264
|
-
return !s &&
|
|
265
|
-
`),
|
|
266
|
-
n("npm install", (
|
|
267
|
-
if (
|
|
268
|
-
console.error("β Failed to install dependencies:",
|
|
261
|
+
hasTriedInstall: l = !1,
|
|
262
|
+
onRetry: w
|
|
263
|
+
} = i, v = ((o == null ? void 0 : o.message) || "") + (e || "") + (t || "");
|
|
264
|
+
return !s && Ot(v) ? (Ft(), await jt(n) && w ? (console.log(`π Retrying build...
|
|
265
|
+
`), w(), { handled: !0, hasTriedPlatformFix: !0, hasTriedInstall: l }) : { handled: !0, hasTriedPlatformFix: !0, hasTriedInstall: l }) : !l && kt(v) ? (console.log("π¦ Missing dependencies detected, running npm install..."), new Promise((m) => {
|
|
266
|
+
n("npm install", (d, C, u) => {
|
|
267
|
+
if (d) {
|
|
268
|
+
console.error("β Failed to install dependencies:", d.message), u && console.error(u), m({ handled: !0, hasTriedPlatformFix: s, hasTriedInstall: !0 });
|
|
269
269
|
return;
|
|
270
270
|
}
|
|
271
|
-
console.log("β
Dependencies installed"),
|
|
271
|
+
console.log("β
Dependencies installed"), w && w(), m({ handled: !0, hasTriedPlatformFix: s, hasTriedInstall: !0 });
|
|
272
272
|
});
|
|
273
|
-
})) : { handled: !1, hasTriedPlatformFix: s, hasTriedInstall:
|
|
273
|
+
})) : { handled: !1, hasTriedPlatformFix: s, hasTriedInstall: l };
|
|
274
274
|
}
|
|
275
|
-
async function
|
|
276
|
-
const o = await import("fs"), e = await import("path"), { exec: t } = await import("child_process"), n = await import("http"), { createHash:
|
|
275
|
+
async function be() {
|
|
276
|
+
const o = await import("fs"), e = await import("path"), { exec: t } = await import("child_process"), n = await import("http"), { createHash: i } = await import("node:crypto");
|
|
277
277
|
let s;
|
|
278
278
|
if (import.meta.url.startsWith("file://")) {
|
|
279
|
-
const
|
|
280
|
-
s = e.default.dirname(
|
|
279
|
+
const r = new URL(import.meta.url).pathname, c = process.platform === "win32" && r.startsWith("/") ? r.slice(1) : r;
|
|
280
|
+
s = e.default.dirname(c);
|
|
281
281
|
} else
|
|
282
282
|
s = e.default.dirname(import.meta.url);
|
|
283
|
-
const
|
|
284
|
-
let
|
|
285
|
-
const
|
|
283
|
+
const l = e.default.join(s, "commands", "dev", "management-website"), w = o.default.readFileSync(e.default.join(l, "styles.css"), "utf-8"), v = o.default.readFileSync(e.default.join(l, "app.js"), "utf-8"), m = 9292, d = 9293;
|
|
284
|
+
let C = "./dist", u = !1, S = !1, M = !1, T = null;
|
|
285
|
+
const D = () => {
|
|
286
286
|
try {
|
|
287
|
-
const a = o.default.readdirSync(".").filter((
|
|
287
|
+
const a = o.default.readdirSync(".").filter((r) => !r.endsWith(".html") || r.startsWith(".") ? !1 : o.default.statSync(r).isFile());
|
|
288
288
|
if (a.length === 1)
|
|
289
289
|
return a[0];
|
|
290
290
|
} catch {
|
|
291
291
|
}
|
|
292
292
|
return null;
|
|
293
|
-
},
|
|
293
|
+
}, P = () => {
|
|
294
294
|
try {
|
|
295
295
|
const a = JSON.parse(o.default.readFileSync("package.json", "utf-8"));
|
|
296
296
|
return !!(a.scripts && a.scripts.build);
|
|
297
297
|
} catch {
|
|
298
298
|
return !1;
|
|
299
299
|
}
|
|
300
|
-
},
|
|
301
|
-
const
|
|
302
|
-
let
|
|
303
|
-
|
|
300
|
+
}, x = (a) => {
|
|
301
|
+
const r = process.platform;
|
|
302
|
+
let c;
|
|
303
|
+
r === "darwin" ? c = `open "${a}"` : r === "win32" ? c = `start "" "${a}"` : c = `xdg-open "${a}"`, t(c, (p) => {
|
|
304
304
|
});
|
|
305
|
-
},
|
|
306
|
-
let
|
|
307
|
-
|
|
308
|
-
const
|
|
305
|
+
}, j = /* @__PURE__ */ new Map(), b = y.program.getOptionValue("config") || "./myop.config.json";
|
|
306
|
+
let f, E, _ = !1;
|
|
307
|
+
T = D();
|
|
308
|
+
const B = P();
|
|
309
309
|
try {
|
|
310
|
-
const a = o.default.readFileSync(
|
|
311
|
-
|
|
310
|
+
const a = o.default.readFileSync(b, "utf-8"), r = JSON.parse(a);
|
|
311
|
+
f = r.componentId || "DEV", E = r.componentName || r.name || null, _ = r.HMR === !0, T && !B && (M = !0, _ = !0, console.log(`π Single HTML file mode: ${T}`)), _ && console.log("π₯ HMR enabled");
|
|
312
312
|
} catch (a) {
|
|
313
|
-
|
|
313
|
+
T && !B ? (M = !0, f = "DEV", E = e.default.basename(T, ".html"), _ = !0, console.log(`π Single HTML file mode: ${T}`), console.log("π₯ HMR enabled")) : (console.error("β Error reading myop.config.json:", a.message), process.exit(1));
|
|
314
314
|
}
|
|
315
315
|
const U = async () => {
|
|
316
|
-
if (
|
|
317
|
-
return
|
|
316
|
+
if (f !== "DEV" && f !== "NEW")
|
|
317
|
+
return f;
|
|
318
318
|
try {
|
|
319
|
-
const
|
|
320
|
-
const
|
|
319
|
+
const r = ((await new Promise((g, h) => {
|
|
320
|
+
const $ = {
|
|
321
321
|
hostname: "localhost",
|
|
322
|
-
port:
|
|
322
|
+
port: d,
|
|
323
323
|
path: "/_list",
|
|
324
324
|
method: "GET",
|
|
325
325
|
timeout: 1e3
|
|
326
|
-
},
|
|
327
|
-
let
|
|
328
|
-
|
|
326
|
+
}, O = n.default.request($, (L) => {
|
|
327
|
+
let V = "";
|
|
328
|
+
L.on("data", (te) => V += te), L.on("end", () => {
|
|
329
329
|
try {
|
|
330
|
-
|
|
330
|
+
g(JSON.parse(V));
|
|
331
331
|
} catch {
|
|
332
|
-
|
|
332
|
+
g({ components: [] });
|
|
333
333
|
}
|
|
334
334
|
});
|
|
335
335
|
});
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}),
|
|
339
|
-
})).components || []).map(([
|
|
340
|
-
if (
|
|
336
|
+
O.on("error", () => g({ components: [] })), O.on("timeout", () => {
|
|
337
|
+
O.destroy(), g({ components: [] });
|
|
338
|
+
}), O.end();
|
|
339
|
+
})).components || []).map(([g]) => g).filter((g) => g === "DEV" || g === "NEW" || /^DEV\d+$/.test(g) || /^NEW\d+$/.test(g));
|
|
340
|
+
if (r.length === 0)
|
|
341
341
|
return "DEV1";
|
|
342
|
-
const
|
|
343
|
-
if (
|
|
344
|
-
const h =
|
|
345
|
-
return h ? parseInt(h[1], 10) :
|
|
346
|
-
}).filter((
|
|
347
|
-
return `DEV${Math.max(...
|
|
342
|
+
const c = r.map((g) => {
|
|
343
|
+
if (g === "DEV" || g === "NEW") return 1;
|
|
344
|
+
const h = g.match(/^DEV(\d+)$/), $ = g.match(/^NEW(\d+)$/);
|
|
345
|
+
return h ? parseInt(h[1], 10) : $ ? parseInt($[1], 10) : 0;
|
|
346
|
+
}).filter((g) => g > 0);
|
|
347
|
+
return `DEV${Math.max(...c, 0) + 1}`;
|
|
348
348
|
} catch {
|
|
349
349
|
return "DEV1";
|
|
350
350
|
}
|
|
351
|
-
},
|
|
352
|
-
const
|
|
351
|
+
}, k = process.cwd(), z = (a) => {
|
|
352
|
+
const r = e.default.extname(a).toLowerCase();
|
|
353
353
|
return {
|
|
354
354
|
".html": "text/html",
|
|
355
355
|
".js": "text/javascript",
|
|
@@ -360,336 +360,336 @@ async function _e() {
|
|
|
360
360
|
".gif": "image/gif",
|
|
361
361
|
".svg": "image/svg+xml",
|
|
362
362
|
".ico": "image/x-icon"
|
|
363
|
-
}[
|
|
364
|
-
},
|
|
363
|
+
}[r] || "application/octet-stream";
|
|
364
|
+
}, I = /* @__PURE__ */ new Map(), Z = [], se = 50, Y = [], ie = /* @__PURE__ */ new Map(), ee = /* @__PURE__ */ new Map(), lt = (a, r, c) => {
|
|
365
365
|
if (a.url.startsWith("/_hmr/")) {
|
|
366
|
-
const
|
|
367
|
-
|
|
366
|
+
const p = a.url.split("/_hmr/")[1], g = a.headers["sec-websocket-key"], h = i("sha1").update(g + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
|
|
367
|
+
r.write(
|
|
368
368
|
`HTTP/1.1 101 Switching Protocols\r
|
|
369
369
|
Upgrade: websocket\r
|
|
370
370
|
Connection: Upgrade\r
|
|
371
371
|
Sec-WebSocket-Accept: ${h}\r
|
|
372
372
|
\r
|
|
373
373
|
`
|
|
374
|
-
),
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
}),
|
|
378
|
-
const
|
|
379
|
-
|
|
374
|
+
), ee.has(p) || ee.set(p, /* @__PURE__ */ new Set()), ee.get(p).add(r), console.log(`π HMR client connected: ${p}`), r.on("close", () => {
|
|
375
|
+
const $ = ee.get(p);
|
|
376
|
+
$ && ($.delete(r), $.size === 0 && ee.delete(p)), console.log(`π HMR client disconnected: ${p}`);
|
|
377
|
+
}), r.on("error", () => {
|
|
378
|
+
const $ = ee.get(p);
|
|
379
|
+
$ && $.delete(r);
|
|
380
380
|
});
|
|
381
381
|
}
|
|
382
|
-
},
|
|
383
|
-
if (
|
|
384
|
-
let
|
|
385
|
-
a.on("data", (
|
|
382
|
+
}, Ce = n.default.createServer((a, r) => {
|
|
383
|
+
if (r.setHeader("Content-Type", "application/json"), a.method === "POST" && a.url === "/_register") {
|
|
384
|
+
let c = "";
|
|
385
|
+
a.on("data", (p) => c += p), a.on("end", () => {
|
|
386
386
|
try {
|
|
387
|
-
const { componentId:
|
|
388
|
-
|
|
389
|
-
const
|
|
390
|
-
console.log(`β
Registered: ${
|
|
391
|
-
const
|
|
392
|
-
id:
|
|
393
|
-
path:
|
|
394
|
-
name:
|
|
387
|
+
const { componentId: p, distPath: g, componentName: h, htmlFile: $ } = JSON.parse(c);
|
|
388
|
+
I.set(p, { path: g, name: h || null, htmlFile: $ || null });
|
|
389
|
+
const O = h ? ` (${h})` : "";
|
|
390
|
+
console.log(`β
Registered: ${p}${O} -> ${g}${$ ? "/" + $ : ""}`), r.writeHead(200), r.end(JSON.stringify({ success: !0, registered: Array.from(I.keys()) }));
|
|
391
|
+
const L = Array.from(I.entries()).map(([V, te]) => ({
|
|
392
|
+
id: V,
|
|
393
|
+
path: te.path,
|
|
394
|
+
name: te.name
|
|
395
395
|
}));
|
|
396
|
-
|
|
396
|
+
Y.forEach((V) => {
|
|
397
397
|
try {
|
|
398
|
-
|
|
398
|
+
V.write(`data: ${JSON.stringify({
|
|
399
399
|
type: "components",
|
|
400
|
-
components:
|
|
400
|
+
components: L
|
|
401
401
|
})}
|
|
402
402
|
|
|
403
403
|
`);
|
|
404
404
|
} catch {
|
|
405
405
|
}
|
|
406
406
|
});
|
|
407
|
-
} catch (
|
|
408
|
-
|
|
407
|
+
} catch (p) {
|
|
408
|
+
r.writeHead(400), r.end(JSON.stringify({ error: p.message }));
|
|
409
409
|
}
|
|
410
410
|
});
|
|
411
411
|
} else if (a.method === "POST" && a.url === "/_unregister") {
|
|
412
|
-
let
|
|
413
|
-
a.on("data", (
|
|
412
|
+
let c = "";
|
|
413
|
+
a.on("data", (p) => c += p), a.on("end", () => {
|
|
414
414
|
try {
|
|
415
|
-
const { componentId:
|
|
416
|
-
|
|
417
|
-
const
|
|
415
|
+
const { componentId: p } = JSON.parse(c);
|
|
416
|
+
I.delete(p), console.log(`β Unregistered: ${p}`), r.writeHead(200), r.end(JSON.stringify({ success: !0 }));
|
|
417
|
+
const g = Array.from(I.entries()).map(([h, $]) => ({
|
|
418
418
|
id: h,
|
|
419
|
-
path:
|
|
420
|
-
name:
|
|
419
|
+
path: $.path,
|
|
420
|
+
name: $.name
|
|
421
421
|
}));
|
|
422
|
-
|
|
422
|
+
Y.forEach((h) => {
|
|
423
423
|
try {
|
|
424
424
|
h.write(`data: ${JSON.stringify({
|
|
425
425
|
type: "components",
|
|
426
|
-
components:
|
|
426
|
+
components: g
|
|
427
427
|
})}
|
|
428
428
|
|
|
429
429
|
`);
|
|
430
430
|
} catch {
|
|
431
431
|
}
|
|
432
432
|
});
|
|
433
|
-
} catch (
|
|
434
|
-
|
|
433
|
+
} catch (p) {
|
|
434
|
+
r.writeHead(400), r.end(JSON.stringify({ error: p.message }));
|
|
435
435
|
}
|
|
436
436
|
});
|
|
437
437
|
} else if (a.method === "GET" && a.url === "/_list")
|
|
438
|
-
|
|
438
|
+
r.writeHead(200), r.end(JSON.stringify({ components: Array.from(I.entries()) }));
|
|
439
439
|
else if (a.method === "POST" && a.url === "/_hmr_notify") {
|
|
440
|
-
let
|
|
441
|
-
a.on("data", (
|
|
440
|
+
let c = "";
|
|
441
|
+
a.on("data", (p) => c += p), a.on("end", () => {
|
|
442
442
|
try {
|
|
443
|
-
const { componentId:
|
|
443
|
+
const { componentId: p, html: g } = JSON.parse(c), h = ee.get(p);
|
|
444
444
|
if (h && h.size > 0) {
|
|
445
|
-
console.log(`π₯ Notifying ${h.size} HMR client(s) for: ${
|
|
446
|
-
const
|
|
447
|
-
h.forEach((
|
|
445
|
+
console.log(`π₯ Notifying ${h.size} HMR client(s) for: ${p}`);
|
|
446
|
+
const $ = JSON.stringify({ type: "update", html: g }), O = Je($);
|
|
447
|
+
h.forEach((L) => {
|
|
448
448
|
try {
|
|
449
|
-
|
|
449
|
+
L.write(O);
|
|
450
450
|
} catch {
|
|
451
|
-
h.delete(
|
|
451
|
+
h.delete(L);
|
|
452
452
|
}
|
|
453
|
-
}),
|
|
453
|
+
}), r.writeHead(200), r.end(JSON.stringify({ success: !0, notified: h.size }));
|
|
454
454
|
} else
|
|
455
|
-
|
|
456
|
-
} catch (
|
|
457
|
-
|
|
455
|
+
r.writeHead(200), r.end(JSON.stringify({ success: !0, notified: 0 }));
|
|
456
|
+
} catch (p) {
|
|
457
|
+
r.writeHead(400), r.end(JSON.stringify({ error: p.message }));
|
|
458
458
|
}
|
|
459
459
|
});
|
|
460
460
|
} else
|
|
461
|
-
|
|
462
|
-
}),
|
|
461
|
+
r.writeHead(404), r.end(JSON.stringify({ error: "Not found" }));
|
|
462
|
+
}), ue = n.default.createServer((a, r) => {
|
|
463
463
|
if (a.url.includes("..")) {
|
|
464
|
-
|
|
464
|
+
r.writeHead(403, { "Content-Type": "text/plain" }), r.end("Forbidden");
|
|
465
465
|
return;
|
|
466
466
|
}
|
|
467
|
-
const
|
|
468
|
-
if (
|
|
469
|
-
const
|
|
470
|
-
if (!
|
|
471
|
-
|
|
467
|
+
const c = new URL(a.url, `http://localhost:${m}`), p = c.pathname, g = p.split("/").filter((J) => J);
|
|
468
|
+
if (p.startsWith("/consume")) {
|
|
469
|
+
const J = c.searchParams.get("id");
|
|
470
|
+
if (!J) {
|
|
471
|
+
r.writeHead(400, { "Content-Type": "application/json" }), r.end(JSON.stringify({ error: "Component ID required. Use /consume?id=<componentId>" }));
|
|
472
472
|
return;
|
|
473
473
|
}
|
|
474
|
-
const
|
|
475
|
-
let
|
|
474
|
+
const W = I.get(J), K = W ? W.path : null, ce = (oe) => {
|
|
475
|
+
let N = "Unknown", Q = "Unknown";
|
|
476
476
|
if (a.headers.referer || a.headers.referrer) {
|
|
477
|
-
const
|
|
477
|
+
const A = a.headers.referer || a.headers.referrer;
|
|
478
478
|
try {
|
|
479
|
-
const
|
|
480
|
-
|
|
479
|
+
const re = new URL(A);
|
|
480
|
+
N = re.origin, Q = re.hostname || re.origin;
|
|
481
481
|
} catch {
|
|
482
|
-
|
|
482
|
+
N = A, Q = A;
|
|
483
483
|
}
|
|
484
484
|
} else if (a.headers.origin)
|
|
485
485
|
try {
|
|
486
|
-
const
|
|
487
|
-
|
|
486
|
+
const A = new URL(a.headers.origin);
|
|
487
|
+
N = A.origin, Q = A.hostname || A.origin;
|
|
488
488
|
} catch {
|
|
489
|
-
|
|
489
|
+
N = a.headers.origin, Q = a.headers.origin;
|
|
490
490
|
}
|
|
491
491
|
else if (a.socket.remoteAddress) {
|
|
492
|
-
const
|
|
493
|
-
|
|
492
|
+
const A = a.socket.remoteAddress;
|
|
493
|
+
A === "::1" || A === "::ffff:127.0.0.1" ? (N = "localhost", Q = "localhost (direct)") : (N = A, Q = A.replace("::ffff:", ""));
|
|
494
494
|
}
|
|
495
|
-
const
|
|
495
|
+
const Ee = a.headers.referer || a.headers.referrer || N, he = {
|
|
496
496
|
type: "request",
|
|
497
|
-
componentId:
|
|
497
|
+
componentId: J,
|
|
498
498
|
timestamp: Date.now(),
|
|
499
|
-
servedLocally:
|
|
500
|
-
referrer:
|
|
501
|
-
origin:
|
|
502
|
-
originLabel:
|
|
499
|
+
servedLocally: oe,
|
|
500
|
+
referrer: Ee,
|
|
501
|
+
origin: N,
|
|
502
|
+
originLabel: Q
|
|
503
503
|
};
|
|
504
|
-
|
|
505
|
-
url:
|
|
506
|
-
label:
|
|
504
|
+
ie.has(N) || (ie.set(N, {
|
|
505
|
+
url: N,
|
|
506
|
+
label: Q,
|
|
507
507
|
firstSeen: Date.now(),
|
|
508
508
|
requestCount: 0
|
|
509
|
-
}),
|
|
509
|
+
}), Y.forEach((A) => {
|
|
510
510
|
try {
|
|
511
|
-
|
|
511
|
+
A.write(`data: ${JSON.stringify({
|
|
512
512
|
type: "origins",
|
|
513
|
-
origins: Array.from(
|
|
513
|
+
origins: Array.from(ie.values())
|
|
514
514
|
})}
|
|
515
515
|
|
|
516
516
|
`);
|
|
517
517
|
} catch {
|
|
518
518
|
}
|
|
519
519
|
}));
|
|
520
|
-
const
|
|
521
|
-
|
|
520
|
+
const Ie = ie.get(N);
|
|
521
|
+
Ie.requestCount++, Y.forEach((A) => {
|
|
522
522
|
try {
|
|
523
|
-
|
|
523
|
+
A.write(`data: ${JSON.stringify({
|
|
524
524
|
type: "origins",
|
|
525
|
-
origins: Array.from(
|
|
525
|
+
origins: Array.from(ie.values())
|
|
526
526
|
})}
|
|
527
527
|
|
|
528
528
|
`);
|
|
529
529
|
} catch {
|
|
530
530
|
}
|
|
531
|
-
}),
|
|
531
|
+
}), Z.push(he), Z.length > se && Z.shift(), Y.forEach((A) => {
|
|
532
532
|
try {
|
|
533
|
-
|
|
533
|
+
A.write(`data: ${JSON.stringify(he)}
|
|
534
534
|
|
|
535
535
|
`);
|
|
536
536
|
} catch {
|
|
537
537
|
}
|
|
538
538
|
});
|
|
539
539
|
};
|
|
540
|
-
if (
|
|
541
|
-
const
|
|
542
|
-
o.default.readFile(
|
|
543
|
-
if (
|
|
544
|
-
console.log(`β File not found: ${
|
|
540
|
+
if (K) {
|
|
541
|
+
const oe = W.htmlFile ? e.default.join(K, W.htmlFile) : e.default.join(K, "index.html");
|
|
542
|
+
o.default.readFile(oe, "utf-8", (N, Q) => {
|
|
543
|
+
if (N) {
|
|
544
|
+
console.log(`β File not found: ${oe}`), r.writeHead(404, { "Content-Type": "application/json" }), r.end(JSON.stringify({ error: "index.html not found" }));
|
|
545
545
|
return;
|
|
546
546
|
}
|
|
547
|
-
const
|
|
547
|
+
const Ee = Me(Q, J), he = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, Ie = {
|
|
548
548
|
item: {
|
|
549
|
-
name:
|
|
550
|
-
id:
|
|
549
|
+
name: J,
|
|
550
|
+
id: J,
|
|
551
551
|
consume_variant: [
|
|
552
552
|
{
|
|
553
|
-
id:
|
|
553
|
+
id: he,
|
|
554
554
|
name: "dev version",
|
|
555
555
|
loader: {
|
|
556
556
|
type: "HTMLLoader",
|
|
557
557
|
shadowRootMode: "localFrame",
|
|
558
|
-
HTML:
|
|
558
|
+
HTML: Ee
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
561
|
]
|
|
562
562
|
}
|
|
563
563
|
};
|
|
564
|
-
console.log(`β
Serving consume JSON for: ${
|
|
564
|
+
console.log(`β
Serving consume JSON for: ${J}`), ce(!0), r.writeHead(200, {
|
|
565
565
|
"Content-Type": "application/json",
|
|
566
566
|
"Access-Control-Allow-Origin": "*"
|
|
567
|
-
}),
|
|
567
|
+
}), r.end(JSON.stringify(Ie, null, 2));
|
|
568
568
|
});
|
|
569
569
|
} else {
|
|
570
|
-
console.log(`π‘ Proxying consume request to cloud.myop.dev for: ${
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
|
|
570
|
+
console.log(`π‘ Proxying consume request to cloud.myop.dev for: ${J}`);
|
|
571
|
+
const oe = `https://cloud.myop.dev/consume${c.search}`;
|
|
572
|
+
ce(!1), fetch(oe).then((N) => N.text()).then((N) => {
|
|
573
|
+
r.writeHead(200, {
|
|
574
574
|
"Content-Type": "application/json",
|
|
575
575
|
"Access-Control-Allow-Origin": "*"
|
|
576
|
-
}),
|
|
577
|
-
}).catch((
|
|
578
|
-
console.error(`β Proxy error: ${
|
|
576
|
+
}), r.end(N);
|
|
577
|
+
}).catch((N) => {
|
|
578
|
+
console.error(`β Proxy error: ${N.message}`), r.writeHead(502, { "Content-Type": "application/json" }), r.end(JSON.stringify({ error: "Failed to fetch from cloud.myop.dev" }));
|
|
579
579
|
});
|
|
580
580
|
}
|
|
581
581
|
return;
|
|
582
582
|
}
|
|
583
|
-
if (
|
|
584
|
-
|
|
583
|
+
if (p === "/events") {
|
|
584
|
+
r.writeHead(200, {
|
|
585
585
|
"Content-Type": "text/event-stream",
|
|
586
586
|
"Cache-Control": "no-cache",
|
|
587
587
|
Connection: "keep-alive",
|
|
588
588
|
"Access-Control-Allow-Origin": "*"
|
|
589
|
-
}),
|
|
590
|
-
const
|
|
591
|
-
id:
|
|
592
|
-
path:
|
|
593
|
-
name:
|
|
589
|
+
}), Y.push(r);
|
|
590
|
+
const J = Array.from(I.entries()).map(([W, K]) => ({
|
|
591
|
+
id: W,
|
|
592
|
+
path: K.path,
|
|
593
|
+
name: K.name
|
|
594
594
|
}));
|
|
595
|
-
|
|
595
|
+
r.write(`data: ${JSON.stringify({
|
|
596
596
|
type: "components",
|
|
597
|
-
components:
|
|
597
|
+
components: J
|
|
598
598
|
})}
|
|
599
599
|
|
|
600
|
-
`),
|
|
600
|
+
`), r.write(`data: ${JSON.stringify({
|
|
601
601
|
type: "origins",
|
|
602
|
-
origins: Array.from(
|
|
602
|
+
origins: Array.from(ie.values())
|
|
603
603
|
})}
|
|
604
604
|
|
|
605
|
-
`),
|
|
605
|
+
`), r.write(`data: ${JSON.stringify({
|
|
606
606
|
type: "requestLog",
|
|
607
|
-
log:
|
|
607
|
+
log: Z
|
|
608
608
|
})}
|
|
609
609
|
|
|
610
610
|
`), a.on("close", () => {
|
|
611
|
-
const
|
|
612
|
-
|
|
611
|
+
const W = Y.indexOf(r);
|
|
612
|
+
W !== -1 && Y.splice(W, 1);
|
|
613
613
|
});
|
|
614
614
|
return;
|
|
615
615
|
}
|
|
616
|
-
if (
|
|
617
|
-
|
|
616
|
+
if (g.length === 0) {
|
|
617
|
+
r.writeHead(200, { "Content-Type": "text/html" }), r.end(It(m, d, w, v));
|
|
618
618
|
return;
|
|
619
619
|
}
|
|
620
|
-
if (
|
|
621
|
-
|
|
620
|
+
if (g[0] !== "view") {
|
|
621
|
+
r.writeHead(404, { "Content-Type": "text/plain" }), r.end("Not found. Use /view/<componentId>/ to access components.");
|
|
622
622
|
return;
|
|
623
623
|
}
|
|
624
|
-
if (
|
|
625
|
-
|
|
624
|
+
if (g.length < 2) {
|
|
625
|
+
r.writeHead(400, { "Content-Type": "text/plain" }), r.end("Component ID required. Use /view/<componentId>/");
|
|
626
626
|
return;
|
|
627
627
|
}
|
|
628
|
-
const h =
|
|
629
|
-
if (
|
|
630
|
-
|
|
628
|
+
const h = g[1], $ = I.get(h);
|
|
629
|
+
if (!$) {
|
|
630
|
+
r.writeHead(404, { "Content-Type": "text/plain" }), r.end(`Component not found: ${h}`);
|
|
631
631
|
return;
|
|
632
632
|
}
|
|
633
|
-
const
|
|
634
|
-
console.log(`π₯ Request: ${a.url} -> ${
|
|
635
|
-
if (
|
|
636
|
-
console.log(`β File not found: ${
|
|
633
|
+
const O = $.path, L = g.slice(2), V = $.htmlFile || "index.html", te = L.length === 0 ? V : L.join("/"), le = e.default.join(O, te);
|
|
634
|
+
console.log(`π₯ Request: ${a.url} -> ${le}`), o.default.readFile(le, (J, W) => {
|
|
635
|
+
if (J) {
|
|
636
|
+
console.log(`β File not found: ${le}`), r.writeHead(404, { "Content-Type": "text/plain" }), r.end("Not Found");
|
|
637
637
|
return;
|
|
638
638
|
}
|
|
639
|
-
const
|
|
640
|
-
console.log(`β
Serving: ${
|
|
641
|
-
let
|
|
642
|
-
if (
|
|
643
|
-
const
|
|
644
|
-
|
|
639
|
+
const K = z(le);
|
|
640
|
+
console.log(`β
Serving: ${le} (${K})`);
|
|
641
|
+
let ce = W;
|
|
642
|
+
if (K === "text/html" && _) {
|
|
643
|
+
const oe = W.toString("utf-8");
|
|
644
|
+
ce = Me(oe, h);
|
|
645
645
|
}
|
|
646
|
-
|
|
647
|
-
"Content-Type":
|
|
646
|
+
r.writeHead(200, {
|
|
647
|
+
"Content-Type": K,
|
|
648
648
|
"Access-Control-Allow-Origin": "*"
|
|
649
|
-
}),
|
|
649
|
+
}), r.end(ce);
|
|
650
650
|
});
|
|
651
|
-
}),
|
|
652
|
-
const
|
|
653
|
-
componentId:
|
|
654
|
-
distPath:
|
|
655
|
-
componentName:
|
|
656
|
-
htmlFile:
|
|
657
|
-
}),
|
|
651
|
+
}), Ue = () => new Promise((a, r) => {
|
|
652
|
+
const c = M ? e.default.resolve(k) : e.default.resolve(k, C), p = JSON.stringify({
|
|
653
|
+
componentId: f,
|
|
654
|
+
distPath: c,
|
|
655
|
+
componentName: E,
|
|
656
|
+
htmlFile: M ? T : null
|
|
657
|
+
}), g = {
|
|
658
658
|
hostname: "localhost",
|
|
659
|
-
port:
|
|
659
|
+
port: d,
|
|
660
660
|
path: "/_register",
|
|
661
661
|
method: "POST",
|
|
662
662
|
headers: {
|
|
663
663
|
"Content-Type": "application/json",
|
|
664
|
-
"Content-Length": Buffer.byteLength(
|
|
664
|
+
"Content-Length": Buffer.byteLength(p)
|
|
665
665
|
}
|
|
666
|
-
}, h = n.default.request(
|
|
667
|
-
let
|
|
668
|
-
|
|
669
|
-
|
|
666
|
+
}, h = n.default.request(g, ($) => {
|
|
667
|
+
let O = "";
|
|
668
|
+
$.on("data", (L) => O += L), $.on("end", () => {
|
|
669
|
+
$.statusCode === 200 ? a(JSON.parse(O)) : r(new Error(`Registration failed: ${$.statusCode}`));
|
|
670
670
|
});
|
|
671
671
|
});
|
|
672
|
-
h.on("error",
|
|
673
|
-
}),
|
|
674
|
-
const
|
|
672
|
+
h.on("error", r), h.write(p), h.end();
|
|
673
|
+
}), ct = () => new Promise((a, r) => {
|
|
674
|
+
const c = JSON.stringify({ componentId: f }), p = {
|
|
675
675
|
hostname: "localhost",
|
|
676
|
-
port:
|
|
676
|
+
port: d,
|
|
677
677
|
path: "/_unregister",
|
|
678
678
|
method: "POST",
|
|
679
679
|
headers: {
|
|
680
680
|
"Content-Type": "application/json",
|
|
681
|
-
"Content-Length": Buffer.byteLength(
|
|
681
|
+
"Content-Length": Buffer.byteLength(c)
|
|
682
682
|
}
|
|
683
|
-
},
|
|
683
|
+
}, g = n.default.request(p, (h) => {
|
|
684
684
|
a();
|
|
685
685
|
});
|
|
686
|
-
|
|
687
|
-
}),
|
|
686
|
+
g.on("error", () => a()), g.write(c), g.end();
|
|
687
|
+
}), dt = (a) => `
|
|
688
688
|
<!-- MYOP HMR -->
|
|
689
689
|
<script>
|
|
690
690
|
(function() {
|
|
691
691
|
const componentId = '${a}';
|
|
692
|
-
const wsUrl = 'ws://localhost:${
|
|
692
|
+
const wsUrl = 'ws://localhost:${d}/_hmr/' + componentId;
|
|
693
693
|
let ws;
|
|
694
694
|
let reconnectAttempts = 0;
|
|
695
695
|
const maxReconnectAttempts = 10;
|
|
@@ -789,251 +789,251 @@ Sec-WebSocket-Accept: ${h}\r
|
|
|
789
789
|
connect();
|
|
790
790
|
})();
|
|
791
791
|
<\/script>
|
|
792
|
-
`,
|
|
793
|
-
if (!
|
|
794
|
-
const
|
|
795
|
-
return a.includes("</body>") ? a.replace("</body>", `${
|
|
796
|
-
},
|
|
797
|
-
const
|
|
798
|
-
let
|
|
799
|
-
return
|
|
800
|
-
Buffer.from([129,
|
|
792
|
+
`, Me = (a, r) => {
|
|
793
|
+
if (!_) return a;
|
|
794
|
+
const c = dt(r);
|
|
795
|
+
return a.includes("</body>") ? a.replace("</body>", `${c}</body>`) : a.includes("</html>") ? a.replace("</html>", `${c}</html>`) : a + c;
|
|
796
|
+
}, Je = (a) => {
|
|
797
|
+
const r = Buffer.from(a), c = r.length;
|
|
798
|
+
let p;
|
|
799
|
+
return c < 126 ? p = Buffer.concat([
|
|
800
|
+
Buffer.from([129, c]),
|
|
801
801
|
// FIN + text frame, length
|
|
802
|
-
|
|
803
|
-
]) :
|
|
802
|
+
r
|
|
803
|
+
]) : c < 65536 ? p = Buffer.concat([
|
|
804
804
|
Buffer.from([129, 126]),
|
|
805
805
|
// FIN + text frame, extended length
|
|
806
|
-
Buffer.from([
|
|
806
|
+
Buffer.from([c >> 8, c & 255]),
|
|
807
807
|
// 16-bit length
|
|
808
|
-
|
|
809
|
-
]) :
|
|
808
|
+
r
|
|
809
|
+
]) : p = Buffer.concat([
|
|
810
810
|
Buffer.from([129, 127]),
|
|
811
811
|
// FIN + text frame, extended length
|
|
812
|
-
Buffer.from([0, 0, 0, 0,
|
|
812
|
+
Buffer.from([0, 0, 0, 0, c >> 24, c >> 16 & 255, c >> 8 & 255, c & 255]),
|
|
813
813
|
// 64-bit length
|
|
814
|
-
|
|
815
|
-
]),
|
|
816
|
-
},
|
|
817
|
-
if (!
|
|
818
|
-
const a =
|
|
819
|
-
let
|
|
814
|
+
r
|
|
815
|
+
]), p;
|
|
816
|
+
}, Be = () => {
|
|
817
|
+
if (!_) return;
|
|
818
|
+
const a = M ? T : e.default.join(C, "index.html");
|
|
819
|
+
let r;
|
|
820
820
|
try {
|
|
821
|
-
const
|
|
822
|
-
|
|
823
|
-
} catch (
|
|
824
|
-
console.error("β Failed to read HTML for HMR:",
|
|
821
|
+
const c = o.default.readFileSync(a, "utf-8");
|
|
822
|
+
r = Me(c, f);
|
|
823
|
+
} catch (c) {
|
|
824
|
+
console.error("β Failed to read HTML for HMR:", c.message);
|
|
825
825
|
return;
|
|
826
826
|
}
|
|
827
827
|
if (Re) {
|
|
828
|
-
const
|
|
829
|
-
if (!
|
|
828
|
+
const c = ee.get(f);
|
|
829
|
+
if (!c || c.size === 0)
|
|
830
830
|
return;
|
|
831
|
-
console.log(`π₯ Notifying ${
|
|
832
|
-
const
|
|
831
|
+
console.log(`π₯ Notifying ${c.size} HMR client(s)`);
|
|
832
|
+
const p = JSON.stringify({
|
|
833
833
|
type: "update",
|
|
834
|
-
html:
|
|
835
|
-
}),
|
|
836
|
-
|
|
834
|
+
html: r
|
|
835
|
+
}), g = Je(p);
|
|
836
|
+
c.forEach((h) => {
|
|
837
837
|
try {
|
|
838
|
-
h.write(
|
|
838
|
+
h.write(g);
|
|
839
839
|
} catch {
|
|
840
|
-
|
|
840
|
+
c.delete(h);
|
|
841
841
|
}
|
|
842
842
|
});
|
|
843
843
|
} else {
|
|
844
|
-
const
|
|
845
|
-
componentId:
|
|
846
|
-
html:
|
|
847
|
-
}),
|
|
844
|
+
const c = JSON.stringify({
|
|
845
|
+
componentId: f,
|
|
846
|
+
html: r
|
|
847
|
+
}), p = {
|
|
848
848
|
hostname: "localhost",
|
|
849
|
-
port:
|
|
849
|
+
port: d,
|
|
850
850
|
path: "/_hmr_notify",
|
|
851
851
|
method: "POST",
|
|
852
852
|
headers: {
|
|
853
853
|
"Content-Type": "application/json",
|
|
854
|
-
"Content-Length": Buffer.byteLength(
|
|
854
|
+
"Content-Length": Buffer.byteLength(c)
|
|
855
855
|
},
|
|
856
856
|
timeout: 5e3
|
|
857
|
-
},
|
|
858
|
-
let
|
|
859
|
-
h.on("data", (
|
|
857
|
+
}, g = n.default.request(p, (h) => {
|
|
858
|
+
let $ = "";
|
|
859
|
+
h.on("data", (O) => $ += O), h.on("end", () => {
|
|
860
860
|
try {
|
|
861
|
-
const
|
|
862
|
-
|
|
861
|
+
const O = JSON.parse($);
|
|
862
|
+
O.notified > 0 && console.log(`π₯ Notified ${O.notified} HMR client(s) via server`);
|
|
863
863
|
} catch {
|
|
864
864
|
}
|
|
865
865
|
});
|
|
866
866
|
});
|
|
867
|
-
|
|
868
|
-
}),
|
|
869
|
-
|
|
870
|
-
}),
|
|
867
|
+
g.on("error", () => {
|
|
868
|
+
}), g.on("timeout", () => {
|
|
869
|
+
g.destroy();
|
|
870
|
+
}), g.write(c), g.end();
|
|
871
871
|
}
|
|
872
872
|
};
|
|
873
|
-
let
|
|
874
|
-
const
|
|
875
|
-
if (
|
|
876
|
-
|
|
873
|
+
let Pe = { hasTriedPlatformFix: !1, hasTriedInstall: !1 };
|
|
874
|
+
const ge = (a) => {
|
|
875
|
+
if (u) {
|
|
876
|
+
S = !0;
|
|
877
877
|
return;
|
|
878
878
|
}
|
|
879
|
-
|
|
880
|
-
π¨ Building...`), t("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (
|
|
881
|
-
if (
|
|
882
|
-
const
|
|
883
|
-
...
|
|
884
|
-
onRetry: () =>
|
|
879
|
+
u = !0, console.log(`
|
|
880
|
+
π¨ Building...`), t("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (r, c, p) => {
|
|
881
|
+
if (u = !1, r) {
|
|
882
|
+
const g = await et(r, c, p, t, {
|
|
883
|
+
...Pe,
|
|
884
|
+
onRetry: () => ge(a)
|
|
885
885
|
});
|
|
886
|
-
|
|
886
|
+
Pe = { ...Pe, ...g }, g.handled || (console.error("β Build failed:", r.message), p && console.error(p));
|
|
887
887
|
} else
|
|
888
|
-
console.log("β
Build completed"),
|
|
889
|
-
|
|
888
|
+
console.log("β
Build completed"), c && console.log(c), Be(), a && a();
|
|
889
|
+
S && (S = !1, ge());
|
|
890
890
|
});
|
|
891
|
-
},
|
|
892
|
-
o.default.readdir(a, { withFileTypes: !0 }, (
|
|
893
|
-
|
|
894
|
-
const
|
|
895
|
-
if (
|
|
896
|
-
|
|
897
|
-
else if (
|
|
898
|
-
const h = e.default.extname(
|
|
891
|
+
}, ze = /* @__PURE__ */ new Set(), Te = (a) => {
|
|
892
|
+
o.default.readdir(a, { withFileTypes: !0 }, (r, c) => {
|
|
893
|
+
r || (c.forEach((p) => {
|
|
894
|
+
const g = e.default.join(a, p.name);
|
|
895
|
+
if (p.isDirectory())
|
|
896
|
+
p.name !== "node_modules" && p.name !== "dist" && !p.name.startsWith(".") && Te(g);
|
|
897
|
+
else if (p.isFile()) {
|
|
898
|
+
const h = e.default.extname(p.name);
|
|
899
899
|
if (h === ".js" || h === ".css" || h === ".html")
|
|
900
900
|
try {
|
|
901
|
-
const
|
|
902
|
-
|
|
901
|
+
const $ = o.default.readFileSync(g, "utf-8");
|
|
902
|
+
j.set(g, $);
|
|
903
903
|
} catch {
|
|
904
904
|
}
|
|
905
905
|
}
|
|
906
|
-
}),
|
|
907
|
-
if (!
|
|
908
|
-
const h = e.default.extname(
|
|
906
|
+
}), ze.has(a) || (ze.add(a), o.default.watch(a, (p, g) => {
|
|
907
|
+
if (!g) return;
|
|
908
|
+
const h = e.default.extname(g);
|
|
909
909
|
if (h !== ".js" && h !== ".css" && h !== ".html") return;
|
|
910
|
-
const
|
|
910
|
+
const $ = e.default.join(a, g);
|
|
911
911
|
setTimeout(() => {
|
|
912
912
|
try {
|
|
913
|
-
const
|
|
914
|
-
|
|
913
|
+
const O = o.default.readFileSync($, "utf-8"), L = j.get($);
|
|
914
|
+
O !== L && (j.set($, O), console.log(`π File changed: ${$}`), M ? Be() : ge());
|
|
915
915
|
} catch {
|
|
916
916
|
}
|
|
917
917
|
}, 50);
|
|
918
918
|
})));
|
|
919
919
|
});
|
|
920
|
-
},
|
|
920
|
+
}, We = (a) => {
|
|
921
921
|
console.log(`
|
|
922
|
-
π¨ Component: ${
|
|
923
|
-
`), a && a()) : (
|
|
922
|
+
π¨ Component: ${f}`), M ? (console.log("π No build needed (single HTML file mode)"), Te(k), console.log(`π Watching ${T} for changes...`), console.log(`Press Ctrl+C to stop
|
|
923
|
+
`), a && a()) : (ge(a), Te(k), console.log("π Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
|
|
924
924
|
`));
|
|
925
|
-
},
|
|
926
|
-
const
|
|
925
|
+
}, pt = () => new Promise((a) => {
|
|
926
|
+
const r = {
|
|
927
927
|
hostname: "localhost",
|
|
928
|
-
port:
|
|
928
|
+
port: d,
|
|
929
929
|
path: "/_list",
|
|
930
930
|
method: "GET",
|
|
931
931
|
timeout: 1e3
|
|
932
|
-
},
|
|
932
|
+
}, c = n.default.request(r, (p) => {
|
|
933
933
|
a(!0);
|
|
934
934
|
});
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
}),
|
|
938
|
-
}),
|
|
939
|
-
const
|
|
940
|
-
if (
|
|
941
|
-
let
|
|
942
|
-
|
|
935
|
+
c.on("error", () => a(!1)), c.on("timeout", () => {
|
|
936
|
+
c.destroy(), a(!1);
|
|
937
|
+
}), c.end();
|
|
938
|
+
}), mt = () => new Promise((a) => {
|
|
939
|
+
const r = n.default.createServer((c, p) => {
|
|
940
|
+
if (p.setHeader("Content-Type", "application/json"), c.method === "POST" && c.url === "/_register") {
|
|
941
|
+
let g = "";
|
|
942
|
+
c.on("data", (h) => g += h), c.on("end", () => {
|
|
943
943
|
try {
|
|
944
|
-
const { componentId: h, distPath:
|
|
945
|
-
|
|
946
|
-
const
|
|
947
|
-
console.log(`β
Registered: ${h}${
|
|
944
|
+
const { componentId: h, distPath: $, componentName: O, htmlFile: L } = JSON.parse(g);
|
|
945
|
+
I.set(h, { path: $, name: O || null, htmlFile: L || null });
|
|
946
|
+
const V = O ? ` (${O})` : "";
|
|
947
|
+
console.log(`β
Registered: ${h}${V} -> ${$}${L ? "/" + L : ""}`), p.writeHead(200), p.end(JSON.stringify({ success: !0, registered: Array.from(I.keys()) }));
|
|
948
948
|
} catch (h) {
|
|
949
|
-
|
|
949
|
+
p.writeHead(400), p.end(JSON.stringify({ error: h.message }));
|
|
950
950
|
}
|
|
951
951
|
});
|
|
952
|
-
} else if (
|
|
953
|
-
let
|
|
954
|
-
|
|
952
|
+
} else if (c.method === "POST" && c.url === "/_unregister") {
|
|
953
|
+
let g = "";
|
|
954
|
+
c.on("data", (h) => g += h), c.on("end", () => {
|
|
955
955
|
try {
|
|
956
|
-
const { componentId: h } = JSON.parse(
|
|
957
|
-
|
|
956
|
+
const { componentId: h } = JSON.parse(g);
|
|
957
|
+
I.delete(h), console.log(`β Unregistered: ${h}`), p.writeHead(200), p.end(JSON.stringify({ success: !0 }));
|
|
958
958
|
} catch (h) {
|
|
959
|
-
|
|
959
|
+
p.writeHead(400), p.end(JSON.stringify({ error: h.message }));
|
|
960
960
|
}
|
|
961
961
|
});
|
|
962
|
-
} else
|
|
962
|
+
} else c.method === "GET" && c.url === "/_list" ? (p.writeHead(200), p.end(JSON.stringify({ components: Array.from(I.entries()) }))) : (p.writeHead(404), p.end(JSON.stringify({ error: "Not found" })));
|
|
963
963
|
});
|
|
964
|
-
|
|
964
|
+
r.on("error", () => {
|
|
965
965
|
a(!1);
|
|
966
|
-
}),
|
|
966
|
+
}), r.listen(d, () => {
|
|
967
967
|
console.log(`
|
|
968
|
-
π Taking over as server...`), console.log(`π‘ Management server on port ${
|
|
969
|
-
|
|
970
|
-
}),
|
|
971
|
-
console.log(`π‘ Main server running at http://localhost:${
|
|
972
|
-
const
|
|
973
|
-
|
|
974
|
-
path:
|
|
975
|
-
name:
|
|
976
|
-
htmlFile:
|
|
968
|
+
π Taking over as server...`), console.log(`π‘ Management server on port ${d}`), ue.on("error", () => {
|
|
969
|
+
r.close(), a(!1);
|
|
970
|
+
}), ue.listen(m, () => {
|
|
971
|
+
console.log(`π‘ Main server running at http://localhost:${m}`);
|
|
972
|
+
const c = M ? e.default.resolve(k) : e.default.resolve(k, C);
|
|
973
|
+
I.set(f, {
|
|
974
|
+
path: c,
|
|
975
|
+
name: E,
|
|
976
|
+
htmlFile: M ? T : null
|
|
977
977
|
});
|
|
978
|
-
const
|
|
979
|
-
console.log(`β
Registered component: ${
|
|
978
|
+
const p = E ? ` (${E})` : "";
|
|
979
|
+
console.log(`β
Registered component: ${f}${p}`), console.log(`π‘ Access at: http://localhost:${m}/view/${f}/`), a(!0);
|
|
980
980
|
});
|
|
981
981
|
});
|
|
982
982
|
});
|
|
983
|
-
let
|
|
984
|
-
const
|
|
985
|
-
|
|
986
|
-
await
|
|
987
|
-
β οΈ Server appears to be down, attempting to take over...`), await
|
|
983
|
+
let fe;
|
|
984
|
+
const Ve = () => {
|
|
985
|
+
fe = setInterval(async () => {
|
|
986
|
+
await pt() || (clearInterval(fe), console.log(`
|
|
987
|
+
β οΈ Server appears to be down, attempting to take over...`), await mt() ? (console.log("β
Successfully took over as server"), Re = !0) : (console.log("βΉοΈ Another instance took over, re-registering..."), setTimeout(async () => {
|
|
988
988
|
try {
|
|
989
|
-
await
|
|
990
|
-
} catch (
|
|
991
|
-
console.error("β Failed to re-register:",
|
|
989
|
+
await Ue(), console.log(`β
Re-registered component: ${f}`), Ve();
|
|
990
|
+
} catch (c) {
|
|
991
|
+
console.error("β Failed to re-register:", c.message);
|
|
992
992
|
}
|
|
993
993
|
}, 2e3)));
|
|
994
994
|
}, 3e3);
|
|
995
|
-
},
|
|
995
|
+
}, Ge = async () => {
|
|
996
996
|
console.log(`
|
|
997
997
|
|
|
998
|
-
π Shutting down...`),
|
|
998
|
+
π Shutting down...`), fe && clearInterval(fe), await ct(), process.exit(0);
|
|
999
999
|
};
|
|
1000
|
-
process.on("SIGINT",
|
|
1000
|
+
process.on("SIGINT", Ge), process.on("SIGTERM", Ge);
|
|
1001
1001
|
let Re = !1;
|
|
1002
|
-
|
|
1002
|
+
Ce.on("error", async (a) => {
|
|
1003
1003
|
if (a.code === "EADDRINUSE") {
|
|
1004
1004
|
console.log(`
|
|
1005
1005
|
π Connecting to existing dev server...`);
|
|
1006
1006
|
try {
|
|
1007
|
-
|
|
1008
|
-
const
|
|
1009
|
-
console.log(`β
Registered component: ${
|
|
1010
|
-
process.env.MYOP_NO_BROWSER ||
|
|
1011
|
-
}),
|
|
1012
|
-
} catch (
|
|
1013
|
-
console.error("β Failed to register component:",
|
|
1007
|
+
f = await U();
|
|
1008
|
+
const r = await Ue();
|
|
1009
|
+
console.log(`β
Registered component: ${f}`), console.log(`π‘ Access at: http://localhost:${m}/view/${f}/`), console.log(`π All registered components: ${r.registered.join(", ")}`), We(() => {
|
|
1010
|
+
process.env.MYOP_NO_BROWSER || x(`http://localhost:${m}/view/${f}/`);
|
|
1011
|
+
}), Ve();
|
|
1012
|
+
} catch (r) {
|
|
1013
|
+
console.error("β Failed to register component:", r.message), process.exit(1);
|
|
1014
1014
|
}
|
|
1015
1015
|
} else
|
|
1016
1016
|
console.error("β Management server error:", a.message), process.exit(1);
|
|
1017
|
-
}),
|
|
1017
|
+
}), Ce.on("upgrade", lt), Ce.listen(d, async () => {
|
|
1018
1018
|
Re = !0, console.log(`
|
|
1019
|
-
π Starting shared dev server...`), console.log(`π‘ Management server on port ${
|
|
1019
|
+
π Starting shared dev server...`), console.log(`π‘ Management server on port ${d}`), ue.on("error", (a) => {
|
|
1020
1020
|
console.error("β Main server error:", a.message), process.exit(1);
|
|
1021
|
-
}),
|
|
1022
|
-
console.log(`π‘ Main server running at http://localhost:${
|
|
1023
|
-
const a =
|
|
1024
|
-
|
|
1021
|
+
}), ue.listen(m, async () => {
|
|
1022
|
+
console.log(`π‘ Main server running at http://localhost:${m}`), (f === "DEV" || f === "NEW") && (f = "DEV1");
|
|
1023
|
+
const a = M ? e.default.resolve(k) : e.default.resolve(k, C);
|
|
1024
|
+
I.set(f, {
|
|
1025
1025
|
path: a,
|
|
1026
|
-
name:
|
|
1027
|
-
htmlFile:
|
|
1026
|
+
name: E,
|
|
1027
|
+
htmlFile: M ? T : null
|
|
1028
1028
|
});
|
|
1029
|
-
const
|
|
1030
|
-
console.log(`β
Registered component: ${
|
|
1031
|
-
process.env.MYOP_NO_BROWSER ||
|
|
1029
|
+
const r = E ? ` (${E})` : "";
|
|
1030
|
+
console.log(`β
Registered component: ${f}${r}`), console.log(`π‘ Access at: http://localhost:${m}/view/${f}/`), We(() => {
|
|
1031
|
+
process.env.MYOP_NO_BROWSER || x(`http://localhost:${m}/view/${f}/`);
|
|
1032
1032
|
});
|
|
1033
1033
|
});
|
|
1034
1034
|
});
|
|
1035
1035
|
}
|
|
1036
|
-
const
|
|
1036
|
+
const F = class F {
|
|
1037
1037
|
constructor(e) {
|
|
1038
1038
|
this.components = e.map(
|
|
1039
1039
|
(t) => typeof t == "string" ? { name: t, path: "", id: "" } : t
|
|
@@ -1042,7 +1042,7 @@ const O = class O {
|
|
|
1042
1042
|
this.logs.set(t.name, []), this.scrollPos.set(t.name, 0), this.statuses.set(t.name, "Initializing..."), this.statusKeys.set(t.name, "initializing");
|
|
1043
1043
|
this.cols = process.stdout.columns || 120, this.rows = process.stdout.rows || 30, process.stdout.on("resize", () => {
|
|
1044
1044
|
this.cols = process.stdout.columns || 120, this.rows = process.stdout.rows || 30, this.needsFullRedraw = !0, this.calculateLayout(), this.render();
|
|
1045
|
-
}), this.setupKeyboardInput(), process.stdout.write(
|
|
1045
|
+
}), this.setupKeyboardInput(), process.stdout.write(F.ESC.hideCursor), this.calculateLayout(), this.render(), this.uptimeInterval = setInterval(() => this.updateHeader(), 1e3);
|
|
1046
1046
|
}
|
|
1047
1047
|
setupKeyboardInput() {
|
|
1048
1048
|
process.stdin.isTTY && (process.stdin.setRawMode(!0), process.stdin.resume(), process.stdin.setEncoding("utf8"), process.stdin.on("data", (e) => {
|
|
@@ -1073,8 +1073,8 @@ const O = class O {
|
|
|
1073
1073
|
this.scrollPos.set(t, 0), this.queueUpdate(t);
|
|
1074
1074
|
break;
|
|
1075
1075
|
case "G":
|
|
1076
|
-
const
|
|
1077
|
-
this.scrollPos.set(t, Math.max(0,
|
|
1076
|
+
const i = this.logs.get(t) || [];
|
|
1077
|
+
this.scrollPos.set(t, Math.max(0, i.length - this.visibleLogLines)), this.queueUpdate(t);
|
|
1078
1078
|
break;
|
|
1079
1079
|
}
|
|
1080
1080
|
}));
|
|
@@ -1083,35 +1083,35 @@ const O = class O {
|
|
|
1083
1083
|
const e = this.components.length, t = 38;
|
|
1084
1084
|
let n;
|
|
1085
1085
|
this.cols >= t * 3 + 4 ? n = Math.min(e, 3) : this.cols >= t * 2 + 2 ? n = Math.min(e, 2) : n = 1;
|
|
1086
|
-
const
|
|
1087
|
-
this.visibleLogLines = Math.max(2,
|
|
1088
|
-
for (let
|
|
1089
|
-
const
|
|
1090
|
-
this.panelPositions.set(
|
|
1091
|
-
row:
|
|
1092
|
-
col:
|
|
1086
|
+
const i = Math.ceil(e / n), s = Math.floor(this.cols / n), l = 2, v = this.rows - l - 2, m = Math.floor(v / i);
|
|
1087
|
+
this.visibleLogLines = Math.max(2, m - 4), this.layout = { panelsPerRow: n, panelWidth: s, numRows: i, panelHeight: m }, this.panelPositions.clear();
|
|
1088
|
+
for (let d = 0; d < e; d++) {
|
|
1089
|
+
const C = this.components[d], u = Math.floor(d / n), S = d % n;
|
|
1090
|
+
this.panelPositions.set(C.name, {
|
|
1091
|
+
row: l + 1 + u * m,
|
|
1092
|
+
col: S * s + 1,
|
|
1093
1093
|
width: s,
|
|
1094
|
-
height:
|
|
1094
|
+
height: m
|
|
1095
1095
|
});
|
|
1096
1096
|
}
|
|
1097
1097
|
}
|
|
1098
1098
|
log(e, t, n = "info") {
|
|
1099
|
-
const
|
|
1099
|
+
const i = this.logs.get(e) || [], s = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
|
|
1100
1100
|
hour12: !1,
|
|
1101
1101
|
hour: "2-digit",
|
|
1102
1102
|
minute: "2-digit",
|
|
1103
1103
|
second: "2-digit"
|
|
1104
1104
|
});
|
|
1105
|
-
t.includes("β
") || t.includes("completed") ? n = "success" : t.includes("β") || t.includes("failed") ? n = "error" : t.includes("β ") ? n = "warning" : t.includes("π₯") || t.includes("HMR") ? n = "hmr" : (t.includes("π") || t.includes("changed")) && (n = "change"),
|
|
1105
|
+
t.includes("β
") || t.includes("completed") ? n = "success" : t.includes("β") || t.includes("failed") ? n = "error" : t.includes("β ") ? n = "warning" : t.includes("π₯") || t.includes("HMR") ? n = "hmr" : (t.includes("π") || t.includes("changed")) && (n = "change"), i.push({ timestamp: s, message: t.replace(/[β
ββ π₯ππ¨]/g, "").trim(), type: n }), this.logs.set(e, i), i.length > this.visibleLogLines && this.scrollPos.set(e, i.length - this.visibleLogLines), this.queueUpdate(e);
|
|
1106
1106
|
}
|
|
1107
1107
|
setStatus(e, t) {
|
|
1108
1108
|
let n = "ready";
|
|
1109
|
-
const
|
|
1110
|
-
|
|
1109
|
+
const i = t.toLowerCase();
|
|
1110
|
+
i.includes("initializing") || i.includes("β³") ? n = "initializing" : i.includes("starting") ? n = "starting" : i.includes("building") || i.includes("π¨") ? n = "building" : i.includes("ready") || i.includes("β
") ? n = "ready" : i.includes("changed") || i.includes("π") ? n = "changed" : i.includes("hmr") ? n = "hmr_update" : i.includes("π₯") ? n = "hmr" : i.includes("error") || i.includes("β") ? n = "error" : i.includes("warning") || i.includes("β ") ? n = "warning" : (i.includes("stopped") || i.includes("exited")) && (n = "stopped"), this.statuses.set(e, t), this.statusKeys.set(e, n), this.queueUpdate(e);
|
|
1111
1111
|
}
|
|
1112
1112
|
scroll(e, t) {
|
|
1113
|
-
const n = this.logs.get(e) || [],
|
|
1114
|
-
|
|
1113
|
+
const n = this.logs.get(e) || [], i = this.scrollPos.get(e) || 0, s = Math.max(0, n.length - this.visibleLogLines), l = Math.max(0, Math.min(s, i + t));
|
|
1114
|
+
l !== i && (this.scrollPos.set(e, l), this.queueUpdate(e));
|
|
1115
1115
|
}
|
|
1116
1116
|
queueUpdate(e) {
|
|
1117
1117
|
this.pendingUpdates.add(e), this.renderQueued || (this.renderQueued = !0, setImmediate(() => {
|
|
@@ -1132,71 +1132,71 @@ const O = class O {
|
|
|
1132
1132
|
return `${t}:${n.toString().padStart(2, "0")}`;
|
|
1133
1133
|
}
|
|
1134
1134
|
updateHeader() {
|
|
1135
|
-
const e =
|
|
1136
|
-
let
|
|
1137
|
-
|
|
1135
|
+
const e = F.C, t = Array.from(this.statusKeys.values()).filter((s) => s === "ready").length, n = this.components.length;
|
|
1136
|
+
let i = `${e.dim}π‘${e.reset} http://localhost:9292 ${e.gray}|${e.reset} `;
|
|
1137
|
+
i += `${e.green}${t}${e.reset}/${n} ready ${e.gray}|${e.reset} `, i += `β± ${this.getUptime()} ${e.gray}|${e.reset} `, i += `Press ${e.yellow}Ctrl+C${e.reset} to stop`, i += F.ESC.clearLine.slice(0, -1), process.stdout.write(F.ESC.moveTo(2, 1) + i);
|
|
1138
1138
|
}
|
|
1139
1139
|
renderPanel(e) {
|
|
1140
|
-
const t =
|
|
1141
|
-
if (!
|
|
1142
|
-
const s = this.components.findIndex((U) => U.name === e),
|
|
1143
|
-
let
|
|
1144
|
-
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1147
|
-
const
|
|
1148
|
-
let
|
|
1149
|
-
|
|
1150
|
-
const
|
|
1151
|
-
let
|
|
1152
|
-
|
|
1153
|
-
const
|
|
1140
|
+
const t = F.C, n = F.STATUS, i = this.panelPositions.get(e);
|
|
1141
|
+
if (!i) return;
|
|
1142
|
+
const s = this.components.findIndex((U) => U.name === e), l = this.components[s], w = s === this.selectedPanel, v = this.statusKeys.get(e) || "initializing", m = n[v], d = t[m.color], C = this.logs.get(e) || [], u = this.scrollPos.get(e) || 0, S = i.width - 1, M = w ? t.cyan : t.gray, T = [], D = l.name.substring(0, S - 20);
|
|
1143
|
+
let P = `${M}ββ${t.reset} ${d}${m.icon}${t.reset} `;
|
|
1144
|
+
P += `${t.bold}${D}${t.reset} ${t.gray}β${t.reset} ${d}${m.label}${t.reset} `;
|
|
1145
|
+
const x = 5 + D.length + m.label.length + 3;
|
|
1146
|
+
P += `${M}${"β".repeat(Math.max(0, S - x))}β${t.reset}`, T.push(F.ESC.moveTo(i.row, i.col) + P);
|
|
1147
|
+
const j = (l.path || "").substring(0, S - 6);
|
|
1148
|
+
let b = `${M}β${t.reset} ${t.dim}${j}${t.reset}`;
|
|
1149
|
+
b += " ".repeat(Math.max(0, S - j.length - 3)), b += `${M}β${t.reset}`, T.push(F.ESC.moveTo(i.row + 1, i.col) + b);
|
|
1150
|
+
const f = C.length, E = f > this.visibleLogLines ? `${u + 1}-${Math.min(u + this.visibleLogLines, f)}/${f}` : "";
|
|
1151
|
+
let _ = `${M}β${"β".repeat(S - E.length - 4)}${t.reset}`;
|
|
1152
|
+
E && (_ += `${t.dim}${E}${t.reset}`), _ += `${M}${"β".repeat(2)}β€${t.reset}`, T.push(F.ESC.moveTo(i.row + 2, i.col) + _);
|
|
1153
|
+
const B = C.slice(u, u + this.visibleLogLines);
|
|
1154
1154
|
for (let U = 0; U < this.visibleLogLines; U++) {
|
|
1155
|
-
const
|
|
1156
|
-
let
|
|
1157
|
-
if (
|
|
1158
|
-
let
|
|
1159
|
-
|
|
1160
|
-
const
|
|
1161
|
-
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1155
|
+
const k = B[U];
|
|
1156
|
+
let z = `${M}β${t.reset}`;
|
|
1157
|
+
if (k) {
|
|
1158
|
+
let I = t.white;
|
|
1159
|
+
k.type === "success" ? I = t.green : k.type === "error" ? I = t.red : k.type === "warning" ? I = t.yellow : k.type === "hmr" ? I = t.magenta : k.type === "change" && (I = t.blue);
|
|
1160
|
+
const Z = k.message.substring(0, S - 12);
|
|
1161
|
+
z += `${t.dim}${k.timestamp}${t.reset} ${I}${Z}${t.reset}`;
|
|
1162
|
+
const se = S - k.timestamp.length - Z.length - 2;
|
|
1163
|
+
z += " ".repeat(Math.max(0, se));
|
|
1164
1164
|
} else
|
|
1165
|
-
|
|
1166
|
-
|
|
1165
|
+
z += " ".repeat(S - 2);
|
|
1166
|
+
z += `${M}β${t.reset}`, T.push(F.ESC.moveTo(i.row + 3 + U, i.col) + z);
|
|
1167
1167
|
}
|
|
1168
|
-
|
|
1168
|
+
T.push(F.ESC.moveTo(i.row + 3 + this.visibleLogLines, i.col) + `${M}β${"β".repeat(S - 2)}β${t.reset}`), process.stdout.write(T.join(""));
|
|
1169
1169
|
}
|
|
1170
1170
|
fullRender() {
|
|
1171
|
-
const e =
|
|
1172
|
-
process.stdout.write(
|
|
1171
|
+
const e = F.C;
|
|
1172
|
+
process.stdout.write(F.ESC.clearScreen + F.ESC.moveTo(1, 1));
|
|
1173
1173
|
const t = " MYOP MONOREPO DEV ", n = Math.floor((this.cols - t.length) / 2);
|
|
1174
1174
|
process.stdout.write(`${e.cyan}${"β".repeat(n)}${e.bold}${e.bgCyan}${e.black}${t}${e.reset}${e.cyan}${"β".repeat(this.cols - n - t.length)}${e.reset}`), this.updateHeader();
|
|
1175
|
-
for (const
|
|
1176
|
-
this.renderPanel(
|
|
1175
|
+
for (const i of this.components)
|
|
1176
|
+
this.renderPanel(i.name);
|
|
1177
1177
|
this.renderFooter();
|
|
1178
1178
|
}
|
|
1179
1179
|
renderFooter() {
|
|
1180
|
-
const e =
|
|
1180
|
+
const e = F.C, t = this.rows - 1;
|
|
1181
1181
|
let n = `${e.gray}`;
|
|
1182
|
-
n += `${e.green}β${e.gray} Ready `, n += `${e.yellow}β³${e.gray} Building `, n += `${e.magenta}β‘${e.gray} HMR `, n += `${e.red}β${e.gray} Error `, n += `${e.dim}| ββ: select panel ββ: scroll PgUp/PgDn: page g/G: top/bottom${e.reset}`, process.stdout.write(
|
|
1182
|
+
n += `${e.green}β${e.gray} Ready `, n += `${e.yellow}β³${e.gray} Building `, n += `${e.magenta}β‘${e.gray} HMR `, n += `${e.red}β${e.gray} Error `, n += `${e.dim}| ββ: select panel ββ: scroll PgUp/PgDn: page g/G: top/bottom${e.reset}`, process.stdout.write(F.ESC.moveTo(t, 1) + n);
|
|
1183
1183
|
}
|
|
1184
1184
|
render() {
|
|
1185
1185
|
this.needsFullRedraw = !0, this.queueUpdate("__full__");
|
|
1186
1186
|
}
|
|
1187
1187
|
clear() {
|
|
1188
|
-
this.uptimeInterval && clearInterval(this.uptimeInterval), process.stdin.isTTY && process.stdin.setRawMode(!1), process.stdout.write(
|
|
1188
|
+
this.uptimeInterval && clearInterval(this.uptimeInterval), process.stdin.isTTY && process.stdin.setRawMode(!1), process.stdout.write(F.ESC.clearScreen + F.ESC.moveTo(1, 1) + F.ESC.showCursor);
|
|
1189
1189
|
}
|
|
1190
1190
|
};
|
|
1191
1191
|
// ANSI escape codes
|
|
1192
|
-
|
|
1192
|
+
ye(F, "ESC", {
|
|
1193
1193
|
moveTo: (e, t) => `\x1B[${e};${t}H`,
|
|
1194
1194
|
hideCursor: "\x1B[?25l",
|
|
1195
1195
|
showCursor: "\x1B[?25h",
|
|
1196
1196
|
clearScreen: "\x1B[2J",
|
|
1197
1197
|
clearLine: "\x1B[2K"
|
|
1198
1198
|
}), // Colors
|
|
1199
|
-
|
|
1199
|
+
ye(F, "C", {
|
|
1200
1200
|
reset: "\x1B[0m",
|
|
1201
1201
|
bold: "\x1B[1m",
|
|
1202
1202
|
dim: "\x1B[2m",
|
|
@@ -1211,7 +1211,7 @@ fe(O, "C", {
|
|
|
1211
1211
|
bgCyan: "\x1B[46m",
|
|
1212
1212
|
black: "\x1B[30m"
|
|
1213
1213
|
}), // Status configs
|
|
1214
|
-
|
|
1214
|
+
ye(F, "STATUS", {
|
|
1215
1215
|
initializing: { icon: "β", color: "yellow", label: "Initializing" },
|
|
1216
1216
|
starting: { icon: "β", color: "yellow", label: "Starting" },
|
|
1217
1217
|
building: { icon: "β³", color: "yellow", label: "Building" },
|
|
@@ -1224,125 +1224,125 @@ fe(O, "STATUS", {
|
|
|
1224
1224
|
warning: { icon: "β ", color: "yellow", label: "Warning" },
|
|
1225
1225
|
stopped: { icon: "β ", color: "gray", label: "Stopped" }
|
|
1226
1226
|
});
|
|
1227
|
-
let
|
|
1228
|
-
async function
|
|
1229
|
-
const { spawn: e, exec: t } = await import("child_process"), n = await import("path"),
|
|
1230
|
-
name:
|
|
1231
|
-
path:
|
|
1232
|
-
id:
|
|
1233
|
-
})), s = new
|
|
1234
|
-
const
|
|
1235
|
-
let
|
|
1236
|
-
|
|
1227
|
+
let je = F;
|
|
1228
|
+
async function Nt(o) {
|
|
1229
|
+
const { spawn: e, exec: t } = await import("child_process"), n = await import("path"), i = o.map((d) => ({
|
|
1230
|
+
name: d.name,
|
|
1231
|
+
path: d.path,
|
|
1232
|
+
id: d.componentId || ""
|
|
1233
|
+
})), s = new je(i), l = [], w = (d) => {
|
|
1234
|
+
const C = process.platform;
|
|
1235
|
+
let u;
|
|
1236
|
+
C === "darwin" ? u = `open "${d}"` : C === "win32" ? u = `start "" "${d}"` : u = `xdg-open "${d}"`, t(u, () => {
|
|
1237
1237
|
});
|
|
1238
|
-
},
|
|
1238
|
+
}, v = () => {
|
|
1239
1239
|
s.clear(), console.log(`
|
|
1240
|
-
π Shutting down all components...`),
|
|
1240
|
+
π Shutting down all components...`), l.forEach((d) => {
|
|
1241
1241
|
try {
|
|
1242
|
-
|
|
1242
|
+
d.kill("SIGTERM");
|
|
1243
1243
|
} catch {
|
|
1244
1244
|
}
|
|
1245
1245
|
}), setTimeout(() => process.exit(0), 500);
|
|
1246
1246
|
};
|
|
1247
|
-
process.on("SIGINT",
|
|
1248
|
-
const
|
|
1249
|
-
for (let
|
|
1250
|
-
const
|
|
1251
|
-
s.setStatus(
|
|
1252
|
-
const
|
|
1253
|
-
cwd: n.default.resolve(
|
|
1247
|
+
process.on("SIGINT", v), process.on("SIGTERM", v);
|
|
1248
|
+
const m = process.argv[1];
|
|
1249
|
+
for (let d = 0; d < o.length; d++) {
|
|
1250
|
+
const C = o[d], u = C.name;
|
|
1251
|
+
s.setStatus(u, "β³ Starting..."), s.log(u, `Starting in ${C.path}`);
|
|
1252
|
+
const S = e("node", [m, "dev"], {
|
|
1253
|
+
cwd: n.default.resolve(C.path),
|
|
1254
1254
|
env: { ...process.env, FORCE_COLOR: "1", MYOP_NO_BROWSER: "1" },
|
|
1255
1255
|
stdio: ["ignore", "pipe", "pipe"]
|
|
1256
1256
|
});
|
|
1257
|
-
|
|
1258
|
-
let
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
const
|
|
1257
|
+
l.push(S);
|
|
1258
|
+
let M = "";
|
|
1259
|
+
S.stdout.on("data", (T) => {
|
|
1260
|
+
M += T.toString();
|
|
1261
|
+
const D = M.split(`
|
|
1262
1262
|
`);
|
|
1263
|
-
|
|
1264
|
-
for (const
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1263
|
+
M = D.pop() || "";
|
|
1264
|
+
for (const P of D) {
|
|
1265
|
+
const x = P.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "").trim();
|
|
1266
|
+
x && (x.includes("Registered component") || x.includes("Registered:") ? s.setStatus(u, "β
Ready") : x.includes("Building...") || x.includes("Running initial build") ? s.setStatus(u, "π¨ Building...") : x.includes("Build completed") || x.includes("Build succeeded") ? s.setStatus(u, "β
Ready") : x.includes("Build failed") ? s.setStatus(u, "β Build Error") : x.includes("File changed") ? (s.setStatus(u, "π Changed"), setTimeout(() => s.setStatus(u, "β
Ready"), 1500)) : x.includes("Notifying") && x.includes("HMR") ? (s.setStatus(u, "π₯ HMR Update"), setTimeout(() => s.setStatus(u, "β
Ready"), 1e3)) : x.includes("HMR client connected") && (s.setStatus(u, "π₯ HMR Connected"), setTimeout(() => s.setStatus(u, "β
Ready"), 1e3)), !x.includes("Watching") && !x.includes("Press Ctrl+C") && !x.includes("Starting shared") && !x.includes("Management server") && !x.includes("Main server") && !x.includes("Access at:") && !x.includes("No build needed") && s.log(u, x));
|
|
1267
1267
|
}
|
|
1268
|
-
}),
|
|
1269
|
-
const
|
|
1268
|
+
}), S.stderr.on("data", (T) => {
|
|
1269
|
+
const D = T.toString().split(`
|
|
1270
1270
|
`);
|
|
1271
|
-
for (const
|
|
1272
|
-
const
|
|
1273
|
-
|
|
1271
|
+
for (const P of D) {
|
|
1272
|
+
const x = P.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "").trim();
|
|
1273
|
+
x && (s.log(u, `β οΈ ${x}`), s.setStatus(u, "β οΈ Warning"));
|
|
1274
1274
|
}
|
|
1275
|
-
}),
|
|
1276
|
-
|
|
1277
|
-
}),
|
|
1275
|
+
}), S.on("exit", (T) => {
|
|
1276
|
+
T !== 0 && T !== null && (s.setStatus(u, `β Exited (${T})`), s.log(u, `Process exited with code ${T}`));
|
|
1277
|
+
}), d < o.length - 1 && await new Promise((T) => setTimeout(T, 500));
|
|
1278
1278
|
}
|
|
1279
1279
|
s.render(), setTimeout(() => {
|
|
1280
|
-
|
|
1280
|
+
w("http://localhost:9292");
|
|
1281
1281
|
}, 2e3);
|
|
1282
1282
|
}
|
|
1283
|
-
const
|
|
1283
|
+
const _t = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1284
1284
|
__proto__: null,
|
|
1285
|
-
devCommand:
|
|
1286
|
-
monorepoDevCommand:
|
|
1287
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
1288
|
-
function
|
|
1289
|
-
|
|
1285
|
+
devCommand: be,
|
|
1286
|
+
monorepoDevCommand: Nt
|
|
1287
|
+
}, Symbol.toStringTag, { value: "Module" })), Ne = H.join(vt.homedir(), ".myop"), pe = H.join(Ne, "credentials.json");
|
|
1288
|
+
function Lt() {
|
|
1289
|
+
R.existsSync(Ne) || R.mkdirSync(Ne, { recursive: !0, mode: 448 });
|
|
1290
1290
|
}
|
|
1291
|
-
function
|
|
1291
|
+
function De() {
|
|
1292
1292
|
try {
|
|
1293
|
-
if (!
|
|
1293
|
+
if (!R.existsSync(pe))
|
|
1294
1294
|
return null;
|
|
1295
|
-
const o =
|
|
1295
|
+
const o = R.readFileSync(pe, "utf8");
|
|
1296
1296
|
return JSON.parse(o);
|
|
1297
1297
|
} catch (o) {
|
|
1298
1298
|
return console.info("Failed to read credentials:", o.message), null;
|
|
1299
1299
|
}
|
|
1300
1300
|
}
|
|
1301
|
-
function
|
|
1302
|
-
|
|
1301
|
+
function tt(o) {
|
|
1302
|
+
Lt();
|
|
1303
1303
|
const e = {
|
|
1304
1304
|
...o,
|
|
1305
1305
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1306
1306
|
};
|
|
1307
|
-
|
|
1307
|
+
R.writeFileSync(pe, JSON.stringify(e, null, 2), {
|
|
1308
1308
|
mode: 384
|
|
1309
1309
|
// Read/write for owner only
|
|
1310
1310
|
});
|
|
1311
1311
|
}
|
|
1312
|
-
function
|
|
1312
|
+
function ot() {
|
|
1313
1313
|
try {
|
|
1314
|
-
return
|
|
1314
|
+
return R.existsSync(pe) && R.unlinkSync(pe), !0;
|
|
1315
1315
|
} catch (o) {
|
|
1316
1316
|
return console.error("Failed to clear credentials:", o.message), !1;
|
|
1317
1317
|
}
|
|
1318
1318
|
}
|
|
1319
|
-
function
|
|
1319
|
+
function At(o) {
|
|
1320
1320
|
if (!o || !o.expiresAt)
|
|
1321
1321
|
return !0;
|
|
1322
1322
|
const e = 5 * 60 * 1e3, t = new Date(o.expiresAt).getTime();
|
|
1323
1323
|
return Date.now() > t - e;
|
|
1324
1324
|
}
|
|
1325
|
-
function
|
|
1326
|
-
const o =
|
|
1325
|
+
function xe() {
|
|
1326
|
+
const o = De();
|
|
1327
1327
|
return o ? {
|
|
1328
1328
|
email: o.userEmail,
|
|
1329
1329
|
userId: o.userId
|
|
1330
1330
|
} : null;
|
|
1331
1331
|
}
|
|
1332
|
-
const
|
|
1333
|
-
function
|
|
1334
|
-
return
|
|
1332
|
+
const ae = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", Se = 19284, He = `http://localhost:${Se}/callback`, Dt = "myop-cli";
|
|
1333
|
+
function Ht() {
|
|
1334
|
+
return Le.randomBytes(32).toString("base64url");
|
|
1335
1335
|
}
|
|
1336
|
-
function
|
|
1337
|
-
return
|
|
1336
|
+
function Ut(o) {
|
|
1337
|
+
return Le.createHash("sha256").update(o).digest("base64url");
|
|
1338
1338
|
}
|
|
1339
|
-
async function
|
|
1340
|
-
const o = await fetch(`${
|
|
1339
|
+
async function Jt() {
|
|
1340
|
+
const o = await fetch(`${ae}/oauth/register`, {
|
|
1341
1341
|
method: "POST",
|
|
1342
1342
|
headers: { "Content-Type": "application/json" },
|
|
1343
1343
|
body: JSON.stringify({
|
|
1344
|
-
client_name:
|
|
1345
|
-
redirect_uris: [
|
|
1344
|
+
client_name: Dt,
|
|
1345
|
+
redirect_uris: [He],
|
|
1346
1346
|
grant_types: ["authorization_code", "refresh_token"],
|
|
1347
1347
|
response_types: ["code"]
|
|
1348
1348
|
})
|
|
@@ -1353,8 +1353,8 @@ async function _t() {
|
|
|
1353
1353
|
}
|
|
1354
1354
|
return o.json();
|
|
1355
1355
|
}
|
|
1356
|
-
function
|
|
1357
|
-
const
|
|
1356
|
+
function we(o, e, t, n = null) {
|
|
1357
|
+
const i = {
|
|
1358
1358
|
success: `<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#4ade80" stroke-width="2">
|
|
1359
1359
|
<circle cx="12" cy="12" r="10"/>
|
|
1360
1360
|
<path d="M8 12l2.5 2.5L16 9"/>
|
|
@@ -1371,7 +1371,7 @@ function ge(o, e, t, n = null) {
|
|
|
1371
1371
|
success: { accent: "#4ade80", glow: "rgba(74, 222, 128, 0.1)" },
|
|
1372
1372
|
error: { accent: "#f87171", glow: "rgba(248, 113, 113, 0.1)" },
|
|
1373
1373
|
warning: { accent: "#fbbf24", glow: "rgba(251, 191, 36, 0.1)" }
|
|
1374
|
-
}, { accent:
|
|
1374
|
+
}, { accent: l, glow: w } = s[o] || s.error;
|
|
1375
1375
|
return `<!DOCTYPE html>
|
|
1376
1376
|
<html lang="en">
|
|
1377
1377
|
<head>
|
|
@@ -1432,7 +1432,7 @@ function ge(o, e, t, n = null) {
|
|
|
1432
1432
|
h1 {
|
|
1433
1433
|
font-size: 20px;
|
|
1434
1434
|
font-weight: 500;
|
|
1435
|
-
color: ${
|
|
1435
|
+
color: ${l};
|
|
1436
1436
|
margin-bottom: 12px;
|
|
1437
1437
|
letter-spacing: -0.5px;
|
|
1438
1438
|
}
|
|
@@ -1464,8 +1464,8 @@ function ge(o, e, t, n = null) {
|
|
|
1464
1464
|
display: inline-flex;
|
|
1465
1465
|
align-items: center;
|
|
1466
1466
|
gap: 8px;
|
|
1467
|
-
background: ${
|
|
1468
|
-
border: 1px solid ${
|
|
1467
|
+
background: ${w};
|
|
1468
|
+
border: 1px solid ${l}33;
|
|
1469
1469
|
border-radius: 4px;
|
|
1470
1470
|
padding: 10px 16px;
|
|
1471
1471
|
font-size: 12px;
|
|
@@ -1502,7 +1502,7 @@ function ge(o, e, t, n = null) {
|
|
|
1502
1502
|
<body>
|
|
1503
1503
|
<div class="container">
|
|
1504
1504
|
<div class="icon">
|
|
1505
|
-
${
|
|
1505
|
+
${i[o] || i.error}
|
|
1506
1506
|
</div>
|
|
1507
1507
|
<h1>${e}</h1>
|
|
1508
1508
|
<p class="message">${t}</p>
|
|
@@ -1519,23 +1519,23 @@ function ge(o, e, t, n = null) {
|
|
|
1519
1519
|
</body>
|
|
1520
1520
|
</html>`;
|
|
1521
1521
|
}
|
|
1522
|
-
function
|
|
1522
|
+
function Bt(o) {
|
|
1523
1523
|
return new Promise((e, t) => {
|
|
1524
|
-
const n =
|
|
1525
|
-
const
|
|
1526
|
-
if (
|
|
1527
|
-
const
|
|
1528
|
-
if (
|
|
1529
|
-
s.writeHead(200, { "Content-Type": "text/html" }), s.end(
|
|
1524
|
+
const n = wt.createServer((i, s) => {
|
|
1525
|
+
const l = new Ke(i.url, `http://localhost:${Se}`);
|
|
1526
|
+
if (l.pathname === "/callback") {
|
|
1527
|
+
const w = l.searchParams.get("code"), v = l.searchParams.get("state"), m = l.searchParams.get("error");
|
|
1528
|
+
if (m) {
|
|
1529
|
+
s.writeHead(200, { "Content-Type": "text/html" }), s.end(we(
|
|
1530
1530
|
"error",
|
|
1531
1531
|
"Authentication Failed",
|
|
1532
1532
|
"Unable to complete the authentication process.",
|
|
1533
|
-
|
|
1534
|
-
)), n.close(), t(new Error(`OAuth error: ${
|
|
1533
|
+
m
|
|
1534
|
+
)), n.close(), t(new Error(`OAuth error: ${m}`));
|
|
1535
1535
|
return;
|
|
1536
1536
|
}
|
|
1537
|
-
if (
|
|
1538
|
-
s.writeHead(400, { "Content-Type": "text/html" }), s.end(
|
|
1537
|
+
if (v !== o) {
|
|
1538
|
+
s.writeHead(400, { "Content-Type": "text/html" }), s.end(we(
|
|
1539
1539
|
"warning",
|
|
1540
1540
|
"Security Error",
|
|
1541
1541
|
"State mismatch detected. This could indicate a CSRF attack. Please try authenticating again.",
|
|
@@ -1543,8 +1543,8 @@ function kt(o) {
|
|
|
1543
1543
|
)), n.close(), t(new Error("State mismatch"));
|
|
1544
1544
|
return;
|
|
1545
1545
|
}
|
|
1546
|
-
if (!
|
|
1547
|
-
s.writeHead(400, { "Content-Type": "text/html" }), s.end(
|
|
1546
|
+
if (!w) {
|
|
1547
|
+
s.writeHead(400, { "Content-Type": "text/html" }), s.end(we(
|
|
1548
1548
|
"error",
|
|
1549
1549
|
"Missing Authorization Code",
|
|
1550
1550
|
"No authorization code was received from the server.",
|
|
@@ -1552,44 +1552,44 @@ function kt(o) {
|
|
|
1552
1552
|
)), n.close(), t(new Error("No authorization code"));
|
|
1553
1553
|
return;
|
|
1554
1554
|
}
|
|
1555
|
-
s.writeHead(200, { "Content-Type": "text/html" }), s.end(
|
|
1555
|
+
s.writeHead(200, { "Content-Type": "text/html" }), s.end(we(
|
|
1556
1556
|
"success",
|
|
1557
1557
|
"Authentication Successful",
|
|
1558
1558
|
"You have been authenticated successfully. Return to the terminal to continue."
|
|
1559
|
-
)), n.close(), e(
|
|
1559
|
+
)), n.close(), e(w);
|
|
1560
1560
|
} else
|
|
1561
1561
|
s.writeHead(404), s.end("Not found");
|
|
1562
1562
|
});
|
|
1563
|
-
n.listen(
|
|
1564
|
-
console.info(`OAuth callback server listening on port ${
|
|
1563
|
+
n.listen(Se, () => {
|
|
1564
|
+
console.info(`OAuth callback server listening on port ${Se}`);
|
|
1565
1565
|
}), setTimeout(() => {
|
|
1566
1566
|
n.close(), t(new Error("Authentication timed out"));
|
|
1567
1567
|
}, 5 * 60 * 1e3);
|
|
1568
1568
|
});
|
|
1569
1569
|
}
|
|
1570
|
-
async function
|
|
1571
|
-
const n = await fetch(`${
|
|
1570
|
+
async function zt(o, e, t) {
|
|
1571
|
+
const n = await fetch(`${ae}/oauth/token`, {
|
|
1572
1572
|
method: "POST",
|
|
1573
1573
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1574
|
-
body: new
|
|
1574
|
+
body: new Qe({
|
|
1575
1575
|
grant_type: "authorization_code",
|
|
1576
1576
|
code: o,
|
|
1577
1577
|
client_id: e,
|
|
1578
|
-
redirect_uri:
|
|
1578
|
+
redirect_uri: He,
|
|
1579
1579
|
code_verifier: t
|
|
1580
1580
|
})
|
|
1581
1581
|
});
|
|
1582
1582
|
if (!n.ok) {
|
|
1583
|
-
const
|
|
1584
|
-
throw new Error(
|
|
1583
|
+
const i = await n.json();
|
|
1584
|
+
throw new Error(i.error_description || i.error || "Token exchange failed");
|
|
1585
1585
|
}
|
|
1586
1586
|
return n.json();
|
|
1587
1587
|
}
|
|
1588
|
-
async function
|
|
1589
|
-
const t = await fetch(`${
|
|
1588
|
+
async function Wt(o, e) {
|
|
1589
|
+
const t = await fetch(`${ae}/oauth/token`, {
|
|
1590
1590
|
method: "POST",
|
|
1591
1591
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1592
|
-
body: new
|
|
1592
|
+
body: new Qe({
|
|
1593
1593
|
grant_type: "refresh_token",
|
|
1594
1594
|
refresh_token: o,
|
|
1595
1595
|
client_id: e
|
|
@@ -1601,9 +1601,9 @@ async function At(o, e) {
|
|
|
1601
1601
|
}
|
|
1602
1602
|
return t.json();
|
|
1603
1603
|
}
|
|
1604
|
-
async function
|
|
1605
|
-
var
|
|
1606
|
-
const e = await fetch(`${
|
|
1604
|
+
async function Vt(o) {
|
|
1605
|
+
var i, s, l;
|
|
1606
|
+
const e = await fetch(`${ae}/mcp`, {
|
|
1607
1607
|
method: "POST",
|
|
1608
1608
|
headers: {
|
|
1609
1609
|
"Content-Type": "application/json",
|
|
@@ -1624,57 +1624,57 @@ async function Ht(o) {
|
|
|
1624
1624
|
const t = await e.json();
|
|
1625
1625
|
if (t.error)
|
|
1626
1626
|
throw new Error(t.error.message);
|
|
1627
|
-
const n = (
|
|
1627
|
+
const n = (l = (s = (i = t.result) == null ? void 0 : i.content) == null ? void 0 : s[0]) == null ? void 0 : l.text;
|
|
1628
1628
|
if (n)
|
|
1629
1629
|
return JSON.parse(n);
|
|
1630
1630
|
throw new Error("Invalid response from whoami");
|
|
1631
1631
|
}
|
|
1632
|
-
async function
|
|
1633
|
-
const o =
|
|
1632
|
+
async function de() {
|
|
1633
|
+
const o = G("Starting authentication...").start();
|
|
1634
1634
|
try {
|
|
1635
1635
|
o.text = "Registering OAuth client...";
|
|
1636
|
-
const t = (await
|
|
1636
|
+
const t = (await Jt()).client_id, n = Ht(), i = Ut(n), s = Le.randomBytes(16).toString("hex");
|
|
1637
1637
|
o.text = "Waiting for authorization...";
|
|
1638
|
-
const
|
|
1639
|
-
|
|
1640
|
-
π Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${
|
|
1641
|
-
`), await
|
|
1642
|
-
const
|
|
1638
|
+
const l = Bt(s), w = new Ke(`${ae}/oauth/authorize`);
|
|
1639
|
+
w.searchParams.set("response_type", "code"), w.searchParams.set("client_id", t), w.searchParams.set("redirect_uri", He), w.searchParams.set("code_challenge", i), w.searchParams.set("code_challenge_method", "S256"), w.searchParams.set("state", s), o.stop(), console.log(`
|
|
1640
|
+
π Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${w.toString()}
|
|
1641
|
+
`), await St(w.toString());
|
|
1642
|
+
const v = await l;
|
|
1643
1643
|
o.start("Exchanging authorization code...");
|
|
1644
|
-
const
|
|
1644
|
+
const m = await zt(v, t, n);
|
|
1645
1645
|
o.text = "Getting user info...";
|
|
1646
|
-
const
|
|
1647
|
-
accessToken:
|
|
1648
|
-
refreshToken:
|
|
1649
|
-
expiresAt: new Date(Date.now() +
|
|
1646
|
+
const d = await Vt(m.access_token), C = {
|
|
1647
|
+
accessToken: m.access_token,
|
|
1648
|
+
refreshToken: m.refresh_token,
|
|
1649
|
+
expiresAt: new Date(Date.now() + m.expires_in * 1e3).toISOString(),
|
|
1650
1650
|
clientId: t,
|
|
1651
|
-
userId:
|
|
1652
|
-
userEmail:
|
|
1651
|
+
userId: d.userId,
|
|
1652
|
+
userEmail: d.email
|
|
1653
1653
|
};
|
|
1654
|
-
return
|
|
1654
|
+
return tt(C), o.succeed(`Authenticated as ${d.email}`), C;
|
|
1655
1655
|
} catch (e) {
|
|
1656
1656
|
throw o.fail(`Authentication failed: ${e.message}`), e;
|
|
1657
1657
|
}
|
|
1658
1658
|
}
|
|
1659
|
-
async function
|
|
1660
|
-
const o =
|
|
1659
|
+
async function nt() {
|
|
1660
|
+
const o = De();
|
|
1661
1661
|
if (!o) {
|
|
1662
1662
|
console.log("Not currently logged in.");
|
|
1663
1663
|
return;
|
|
1664
1664
|
}
|
|
1665
|
-
|
|
1665
|
+
ot(), console.log(`β
Logged out (was: ${o.userEmail})`);
|
|
1666
1666
|
}
|
|
1667
|
-
async function
|
|
1668
|
-
let o =
|
|
1667
|
+
async function st() {
|
|
1668
|
+
let o = De();
|
|
1669
1669
|
if (!o)
|
|
1670
1670
|
return console.log(`Not logged in. Starting authentication...
|
|
1671
|
-
`), await
|
|
1672
|
-
if (!
|
|
1671
|
+
`), await de();
|
|
1672
|
+
if (!At(o))
|
|
1673
1673
|
return o;
|
|
1674
1674
|
if (o.refreshToken) {
|
|
1675
|
-
const e =
|
|
1675
|
+
const e = G("Refreshing access token...").start();
|
|
1676
1676
|
try {
|
|
1677
|
-
const t = await
|
|
1677
|
+
const t = await Wt(
|
|
1678
1678
|
o.refreshToken,
|
|
1679
1679
|
o.clientId
|
|
1680
1680
|
);
|
|
@@ -1683,102 +1683,190 @@ async function Dt() {
|
|
|
1683
1683
|
accessToken: t.access_token,
|
|
1684
1684
|
refreshToken: t.refresh_token,
|
|
1685
1685
|
expiresAt: new Date(Date.now() + t.expires_in * 1e3).toISOString()
|
|
1686
|
-
},
|
|
1686
|
+
}, tt(o), e.succeed("Token refreshed"), o;
|
|
1687
1687
|
} catch {
|
|
1688
|
-
return e.warn("Token refresh failed, please log in again"),
|
|
1688
|
+
return e.warn("Token refresh failed, please log in again"), ot(), await de();
|
|
1689
1689
|
}
|
|
1690
1690
|
}
|
|
1691
1691
|
return console.log(`Session expired. Please log in again.
|
|
1692
|
-
`), await
|
|
1692
|
+
`), await de();
|
|
1693
|
+
}
|
|
1694
|
+
function it() {
|
|
1695
|
+
return ae;
|
|
1696
|
+
}
|
|
1697
|
+
const X = "@myop/cli", ke = process.platform === "win32";
|
|
1698
|
+
function Gt() {
|
|
1699
|
+
try {
|
|
1700
|
+
return q("npm config get registry", { encoding: "utf-8" }).trim() || "https://registry.npmjs.org/";
|
|
1701
|
+
} catch {
|
|
1702
|
+
return "https://registry.npmjs.org/";
|
|
1703
|
+
}
|
|
1693
1704
|
}
|
|
1694
|
-
function
|
|
1695
|
-
|
|
1705
|
+
function Yt() {
|
|
1706
|
+
try {
|
|
1707
|
+
return q("npm config get prefix", { encoding: "utf-8" }).trim();
|
|
1708
|
+
} catch {
|
|
1709
|
+
return null;
|
|
1710
|
+
}
|
|
1696
1711
|
}
|
|
1697
|
-
|
|
1698
|
-
async function Bt() {
|
|
1712
|
+
async function Kt() {
|
|
1699
1713
|
try {
|
|
1700
|
-
const o = await fetch(
|
|
1701
|
-
return
|
|
1714
|
+
const o = Gt().replace(/\/$/, ""), e = await fetch(`${o}/${X}/latest`);
|
|
1715
|
+
return e.ok ? (await e.json()).version : null;
|
|
1702
1716
|
} catch {
|
|
1703
1717
|
return null;
|
|
1704
1718
|
}
|
|
1705
1719
|
}
|
|
1706
|
-
function
|
|
1720
|
+
function Qt(o, e) {
|
|
1707
1721
|
const t = o.split(".").map(Number), n = e.split(".").map(Number);
|
|
1708
|
-
for (let
|
|
1709
|
-
const s = t[
|
|
1710
|
-
if (s >
|
|
1711
|
-
if (s <
|
|
1722
|
+
for (let i = 0; i < Math.max(t.length, n.length); i++) {
|
|
1723
|
+
const s = t[i] || 0, l = n[i] || 0;
|
|
1724
|
+
if (s > l) return 1;
|
|
1725
|
+
if (s < l) return -1;
|
|
1712
1726
|
}
|
|
1713
1727
|
return 0;
|
|
1714
1728
|
}
|
|
1715
|
-
async function
|
|
1716
|
-
const e =
|
|
1729
|
+
async function Zt(o) {
|
|
1730
|
+
const e = G({
|
|
1717
1731
|
text: "Checking for updates...",
|
|
1718
1732
|
color: "cyan"
|
|
1719
|
-
}).start(), t = await
|
|
1720
|
-
if (e.stop(), !t ||
|
|
1733
|
+
}).start(), t = await Kt();
|
|
1734
|
+
if (e.stop(), !t || Qt(t, o) <= 0)
|
|
1721
1735
|
return !1;
|
|
1722
1736
|
console.log(`
|
|
1723
1737
|
π¦ New version available: ${o} β ${t}
|
|
1724
1738
|
`);
|
|
1725
1739
|
let n;
|
|
1726
1740
|
try {
|
|
1727
|
-
n = await
|
|
1741
|
+
n = await Ye({
|
|
1728
1742
|
message: "Would you like to update now?",
|
|
1729
1743
|
choices: [
|
|
1730
1744
|
{ name: "Yes, update now", value: !0 },
|
|
1731
1745
|
{ name: "No, continue with current version", value: !1 }
|
|
1732
1746
|
]
|
|
1733
1747
|
});
|
|
1734
|
-
} catch (
|
|
1735
|
-
throw
|
|
1748
|
+
} catch (i) {
|
|
1749
|
+
throw i.name === "ExitPromptError" && (console.log(`
|
|
1736
1750
|
|
|
1737
1751
|
π Goodbye!
|
|
1738
|
-
`), process.exit(0)),
|
|
1752
|
+
`), process.exit(0)), i;
|
|
1739
1753
|
}
|
|
1740
1754
|
if (n) {
|
|
1741
|
-
const
|
|
1742
|
-
text: `Updating ${
|
|
1755
|
+
const i = G({
|
|
1756
|
+
text: `Updating ${X} to v${t}...`,
|
|
1743
1757
|
color: "green"
|
|
1744
|
-
}).start();
|
|
1758
|
+
}).start(), s = `npm install -g ${X}@latest`, l = Yt();
|
|
1759
|
+
try {
|
|
1760
|
+
q(s, { stdio: "pipe" }), i.succeed(`Updated to v${t}`);
|
|
1761
|
+
} catch {
|
|
1762
|
+
i.stop(), console.log(`
|
|
1763
|
+
π Elevated permissions required.
|
|
1764
|
+
`);
|
|
1765
|
+
try {
|
|
1766
|
+
if (ke) {
|
|
1767
|
+
const d = `Start-Process -FilePath 'cmd' -ArgumentList '/c npm ${l ? `install -g ${X}@latest --prefix \\"${l}\\"` : `install -g ${X}@latest`}' -Verb RunAs -Wait`;
|
|
1768
|
+
q(`powershell -Command "${d}"`, { stdio: "inherit" });
|
|
1769
|
+
} else {
|
|
1770
|
+
const m = l ? `sudo npm install -g ${X}@latest --prefix "${l}"` : `sudo ${s}`;
|
|
1771
|
+
q(m, { stdio: "inherit" });
|
|
1772
|
+
}
|
|
1773
|
+
console.log(`
|
|
1774
|
+
β
Updated to v${t}`);
|
|
1775
|
+
} catch {
|
|
1776
|
+
console.log(`
|
|
1777
|
+
β Update failed`);
|
|
1778
|
+
const d = ke ? `npm install -g ${X}@latest (run as Administrator)` : `sudo npm install -g ${X}@latest`;
|
|
1779
|
+
console.log(`
|
|
1780
|
+
Please run manually: ${d}
|
|
1781
|
+
`), process.exit(1);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
let w = null;
|
|
1745
1785
|
try {
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1786
|
+
let v;
|
|
1787
|
+
l ? v = ke ? Oe(l, "node_modules") : Oe(l, "lib", "node_modules") : v = q("npm root -g", { encoding: "utf-8" }).trim();
|
|
1788
|
+
const m = Oe(v, X, "package.json"), d = yt(m, "utf-8");
|
|
1789
|
+
w = JSON.parse(d).version;
|
|
1790
|
+
} catch {
|
|
1791
|
+
}
|
|
1792
|
+
if (w === t)
|
|
1793
|
+
return console.log(`
|
|
1794
|
+
π Restarting...
|
|
1795
|
+
`), ht(process.argv[0], process.argv.slice(1), {
|
|
1749
1796
|
stdio: "inherit",
|
|
1750
1797
|
shell: !0
|
|
1751
|
-
}).on("close", (
|
|
1752
|
-
process.exit(
|
|
1798
|
+
}).on("close", (m) => {
|
|
1799
|
+
process.exit(m || 0);
|
|
1753
1800
|
}), !0;
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
`), !1;
|
|
1758
|
-
}
|
|
1801
|
+
console.log(`
|
|
1802
|
+
Please run myop again to use the new version.
|
|
1803
|
+
`), process.exit(0);
|
|
1759
1804
|
}
|
|
1760
1805
|
return !1;
|
|
1761
1806
|
}
|
|
1762
|
-
const
|
|
1807
|
+
const Xt = (o) => new Promise((e) => setTimeout(e, o)), qt = () => {
|
|
1808
|
+
let o = new URL(import.meta.url).pathname;
|
|
1809
|
+
process.platform === "win32" && o.startsWith("/") && (o = o.slice(1));
|
|
1810
|
+
const e = H.dirname(o);
|
|
1811
|
+
return H.join(e, "skills");
|
|
1812
|
+
}, _e = (o, e) => {
|
|
1813
|
+
R.mkdirSync(e, { recursive: !0 });
|
|
1814
|
+
const t = R.readdirSync(o, { withFileTypes: !0 });
|
|
1815
|
+
for (const n of t) {
|
|
1816
|
+
const i = H.join(o, n.name), s = H.join(e, n.name);
|
|
1817
|
+
n.isDirectory() ? _e(i, s) : R.copyFileSync(i, s);
|
|
1818
|
+
}
|
|
1819
|
+
}, rt = (o) => {
|
|
1820
|
+
const e = qt();
|
|
1821
|
+
if (!R.existsSync(e))
|
|
1822
|
+
return console.info("Skills source directory not found, skipping skills installation"), !1;
|
|
1823
|
+
try {
|
|
1824
|
+
const t = H.join(o, ".agents", "skills");
|
|
1825
|
+
_e(e, t);
|
|
1826
|
+
const n = [".claude", ".cursor", ".gemini", ".junie", ".agent"], i = R.readdirSync(e, { withFileTypes: !0 }).filter((s) => s.isDirectory()).map((s) => s.name);
|
|
1827
|
+
for (const s of n) {
|
|
1828
|
+
const l = H.join(o, s, "skills");
|
|
1829
|
+
R.mkdirSync(l, { recursive: !0 });
|
|
1830
|
+
for (const w of i) {
|
|
1831
|
+
const v = H.join(l, w), m = H.join("..", "..", ".agents", "skills", w);
|
|
1832
|
+
try {
|
|
1833
|
+
R.rmSync(v, { recursive: !0, force: !0 });
|
|
1834
|
+
} catch {
|
|
1835
|
+
}
|
|
1836
|
+
try {
|
|
1837
|
+
R.symlinkSync(m, v, "dir");
|
|
1838
|
+
} catch {
|
|
1839
|
+
_e(
|
|
1840
|
+
H.join(t, w),
|
|
1841
|
+
v
|
|
1842
|
+
);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
return !0;
|
|
1847
|
+
} catch (t) {
|
|
1848
|
+
return console.info("Failed to install skills:", t.message), !1;
|
|
1849
|
+
}
|
|
1850
|
+
}, at = (o = ".", e = 3, t = 0) => {
|
|
1763
1851
|
const n = [];
|
|
1764
1852
|
if (t > e) return n;
|
|
1765
1853
|
try {
|
|
1766
|
-
const
|
|
1767
|
-
for (const s of
|
|
1768
|
-
const
|
|
1854
|
+
const i = R.readdirSync(o, { withFileTypes: !0 });
|
|
1855
|
+
for (const s of i) {
|
|
1856
|
+
const l = H.join(o, s.name);
|
|
1769
1857
|
if (s.isDirectory()) {
|
|
1770
1858
|
if (s.name === "node_modules" || s.name === ".git" || s.name === "dist" || s.name.startsWith("."))
|
|
1771
1859
|
continue;
|
|
1772
|
-
n.push(...
|
|
1860
|
+
n.push(...at(l, e, t + 1));
|
|
1773
1861
|
} else if (s.name === "myop.config.json")
|
|
1774
1862
|
try {
|
|
1775
|
-
const
|
|
1863
|
+
const w = R.readFileSync(l, "utf-8"), v = JSON.parse(w);
|
|
1776
1864
|
n.push({
|
|
1777
1865
|
path: o,
|
|
1778
|
-
configPath:
|
|
1779
|
-
name:
|
|
1780
|
-
componentId:
|
|
1781
|
-
config:
|
|
1866
|
+
configPath: l,
|
|
1867
|
+
name: v.name || v.componentName || H.basename(o),
|
|
1868
|
+
componentId: v.componentId || null,
|
|
1869
|
+
config: v
|
|
1782
1870
|
});
|
|
1783
1871
|
} catch {
|
|
1784
1872
|
}
|
|
@@ -1788,7 +1876,7 @@ const Wt = (o) => new Promise((e) => setTimeout(e, o)), tt = (o = ".", e = 3, t
|
|
|
1788
1876
|
return n;
|
|
1789
1877
|
};
|
|
1790
1878
|
y.executionPath = process.cwd();
|
|
1791
|
-
const
|
|
1879
|
+
const $e = (o = !1) => {
|
|
1792
1880
|
const e = y.program.getOptionValue("verbose");
|
|
1793
1881
|
e || (console.info = () => {
|
|
1794
1882
|
}), console.info("π verbose mode on"), y.options = {
|
|
@@ -1796,7 +1884,7 @@ const Se = (o = !1) => {
|
|
|
1796
1884
|
verbose: e
|
|
1797
1885
|
};
|
|
1798
1886
|
try {
|
|
1799
|
-
return y.myopConfig =
|
|
1887
|
+
return y.myopConfig = xt(y.options.configPath), { configFound: !0 };
|
|
1800
1888
|
} catch (t) {
|
|
1801
1889
|
if (o) {
|
|
1802
1890
|
console.info(`
|
|
@@ -1806,7 +1894,7 @@ const Se = (o = !1) => {
|
|
|
1806
1894
|
author: "@myop-cli",
|
|
1807
1895
|
flows: []
|
|
1808
1896
|
};
|
|
1809
|
-
return
|
|
1897
|
+
return Ae(y.options.configPath, n), y.myopConfig = n, { configFound: !0 };
|
|
1810
1898
|
} catch {
|
|
1811
1899
|
return console.info("Error details :", t), { configFound: !1, error: t };
|
|
1812
1900
|
}
|
|
@@ -1815,95 +1903,109 @@ const Se = (o = !1) => {
|
|
|
1815
1903
|
}
|
|
1816
1904
|
};
|
|
1817
1905
|
[
|
|
1818
|
-
new
|
|
1819
|
-
...
|
|
1906
|
+
new Fe(),
|
|
1907
|
+
...Et
|
|
1820
1908
|
];
|
|
1821
|
-
const
|
|
1822
|
-
y.program = new
|
|
1823
|
-
y.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(
|
|
1824
|
-
y.program.addOption(new
|
|
1825
|
-
y.program.addOption(new
|
|
1826
|
-
y.program.addOption(new
|
|
1827
|
-
y.program.addOption(new
|
|
1828
|
-
y.program.addOption(new
|
|
1909
|
+
const eo = "0.1.41";
|
|
1910
|
+
y.program = new ft();
|
|
1911
|
+
y.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(eo);
|
|
1912
|
+
y.program.addOption(new me("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
|
|
1913
|
+
y.program.addOption(new me("-h, --help", "Show helpful information"));
|
|
1914
|
+
y.program.addOption(new me("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
|
|
1915
|
+
y.program.addOption(new me("--ci", "CI mode: print status info (version, config, auth) as JSON and exit without prompts"));
|
|
1916
|
+
y.program.addOption(new me("-m, --monorepo", "Monorepo mode: scan for all myop.config.json files in nested directories"));
|
|
1829
1917
|
y.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((o, e) => {
|
|
1830
|
-
|
|
1918
|
+
$e(!0), console.info("adding ", o, e, y.options.configPath), o === "flow" && Xe._action(e), process.exit();
|
|
1831
1919
|
});
|
|
1832
1920
|
y.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((o, e) => {
|
|
1833
|
-
|
|
1921
|
+
$e(), console.info("removing ", o, e, y.options.configPath), o === "flow" && qe._action(e), process.exit();
|
|
1834
1922
|
});
|
|
1835
1923
|
y.program.command("install").description("Install Myop assets").action(async () => {
|
|
1836
|
-
|
|
1924
|
+
$e(), await Ze.action();
|
|
1837
1925
|
});
|
|
1838
1926
|
y.program.command("login").description("Authenticate with Myop platform").action(async () => {
|
|
1839
1927
|
try {
|
|
1840
|
-
await
|
|
1928
|
+
await de();
|
|
1841
1929
|
} catch (o) {
|
|
1842
1930
|
console.error("Login failed:", o.message), process.exit(1);
|
|
1843
1931
|
}
|
|
1844
1932
|
process.exit(0);
|
|
1845
1933
|
});
|
|
1846
1934
|
y.program.command("logout").description("Clear stored credentials").action(async () => {
|
|
1847
|
-
await
|
|
1935
|
+
await nt(), process.exit(0);
|
|
1848
1936
|
});
|
|
1849
1937
|
y.program.command("whoami").description("Show current authenticated user").action(async () => {
|
|
1850
|
-
const o =
|
|
1938
|
+
const o = xe();
|
|
1851
1939
|
o && o.email ? console.log(`Logged in as: ${o.email}`) : console.log("Not logged in. Run `myop login` to authenticate."), process.exit(0);
|
|
1852
1940
|
});
|
|
1853
1941
|
y.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (o) => {
|
|
1854
|
-
var
|
|
1855
|
-
const e = y.program.getOptionValue("config") || "./myop.config.json", t = await import("fs"), { execSync: n } = await import("child_process"),
|
|
1942
|
+
var M, T, D, P, x, j;
|
|
1943
|
+
const e = y.program.getOptionValue("config") || "./myop.config.json", t = await import("fs"), { execSync: n } = await import("child_process"), i = await import("path");
|
|
1856
1944
|
let s = {};
|
|
1857
1945
|
if (t.existsSync(e))
|
|
1858
1946
|
try {
|
|
1859
|
-
const
|
|
1860
|
-
s = JSON.parse(
|
|
1861
|
-
const
|
|
1862
|
-
console.log(`π Found config: ${
|
|
1863
|
-
} catch (
|
|
1864
|
-
console.error(`β οΈ Failed to parse ${e}:`,
|
|
1947
|
+
const b = t.readFileSync(e, "utf-8");
|
|
1948
|
+
s = JSON.parse(b);
|
|
1949
|
+
const f = s.name || s.componentName;
|
|
1950
|
+
console.log(`π Found config: ${f || "Unnamed component"}`), s.componentId && console.log(` Component ID: ${s.componentId}`);
|
|
1951
|
+
} catch (b) {
|
|
1952
|
+
console.error(`β οΈ Failed to parse ${e}:`, b.message);
|
|
1865
1953
|
}
|
|
1866
1954
|
else
|
|
1867
1955
|
console.log("β οΈ No myop.config.json found. A new component will be created.");
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1956
|
+
let l = null, w = !1;
|
|
1957
|
+
try {
|
|
1958
|
+
const b = JSON.parse(t.readFileSync("package.json", "utf-8"));
|
|
1959
|
+
w = !!(b.scripts && b.scripts.build);
|
|
1960
|
+
} catch {
|
|
1961
|
+
}
|
|
1962
|
+
if (!w) {
|
|
1963
|
+
const b = t.readdirSync(".").filter(
|
|
1964
|
+
(f) => f.endsWith(".html") && !f.startsWith(".") && t.statSync(f).isFile()
|
|
1965
|
+
);
|
|
1966
|
+
b.length === 1 && (l = b[0]);
|
|
1967
|
+
}
|
|
1968
|
+
if (l)
|
|
1969
|
+
console.log(`π Single HTML file mode: ${l} (skipping build)`);
|
|
1970
|
+
else if (!o.skipBuild) {
|
|
1971
|
+
const { exec: b } = await import("child_process");
|
|
1972
|
+
let f = { hasTriedPlatformFix: !1, hasTriedInstall: !1 };
|
|
1973
|
+
const E = (B = !1) => new Promise((U) => {
|
|
1974
|
+
const k = G(B ? "Retrying build..." : "Building project...").start();
|
|
1975
|
+
b("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (z, I, Z) => {
|
|
1976
|
+
if (!z) {
|
|
1977
|
+
k.succeed("Build completed"), U(!0);
|
|
1876
1978
|
return;
|
|
1877
1979
|
}
|
|
1878
|
-
if (
|
|
1879
|
-
const
|
|
1880
|
-
if (
|
|
1980
|
+
if (k.fail("Build failed"), !f.hasTriedPlatformFix && !f.hasTriedInstall) {
|
|
1981
|
+
const se = await et(z, I, Z, b, f);
|
|
1982
|
+
if (f = { ...f, ...se }, se.handled) {
|
|
1881
1983
|
const Y = await E(!0);
|
|
1882
|
-
|
|
1984
|
+
U(Y);
|
|
1883
1985
|
return;
|
|
1884
1986
|
}
|
|
1885
1987
|
}
|
|
1886
|
-
console.error(
|
|
1988
|
+
console.error(z.message), U(!1);
|
|
1887
1989
|
});
|
|
1888
1990
|
});
|
|
1889
1991
|
await E() || process.exit(1);
|
|
1890
1992
|
}
|
|
1891
|
-
const
|
|
1892
|
-
t.existsSync(
|
|
1893
|
-
let
|
|
1993
|
+
const v = l || "./dist/index.html";
|
|
1994
|
+
t.existsSync(v) || (console.error(`β Error: ${v} not found`), console.log(" Make sure your build outputs to ./dist/index.html"), process.exit(1));
|
|
1995
|
+
let m;
|
|
1894
1996
|
try {
|
|
1895
|
-
|
|
1896
|
-
} catch (
|
|
1897
|
-
console.error("β Authentication failed:",
|
|
1997
|
+
m = await st();
|
|
1998
|
+
} catch (b) {
|
|
1999
|
+
console.error("β Authentication failed:", b.message), process.exit(1);
|
|
1898
2000
|
}
|
|
1899
|
-
const
|
|
1900
|
-
let
|
|
2001
|
+
const d = it();
|
|
2002
|
+
let C = G("Requesting upload URL...").start(), u;
|
|
1901
2003
|
try {
|
|
1902
|
-
const
|
|
2004
|
+
const b = await fetch(`${d}/mcp`, {
|
|
1903
2005
|
method: "POST",
|
|
1904
2006
|
headers: {
|
|
1905
2007
|
"Content-Type": "application/json",
|
|
1906
|
-
Authorization: `Bearer ${
|
|
2008
|
+
Authorization: `Bearer ${m.accessToken}`
|
|
1907
2009
|
},
|
|
1908
2010
|
body: JSON.stringify({
|
|
1909
2011
|
jsonrpc: "2.0",
|
|
@@ -1912,63 +2014,63 @@ y.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1912
2014
|
params: {
|
|
1913
2015
|
name: "upload_component",
|
|
1914
2016
|
arguments: {
|
|
1915
|
-
name: s.name || s.componentName ||
|
|
2017
|
+
name: s.name || s.componentName || i.default.basename(process.cwd()),
|
|
1916
2018
|
componentId: s.componentId || void 0,
|
|
1917
2019
|
organization: s.organization || void 0
|
|
1918
2020
|
}
|
|
1919
2021
|
}
|
|
1920
2022
|
})
|
|
1921
2023
|
});
|
|
1922
|
-
if (!
|
|
1923
|
-
throw new Error(`Server returned ${
|
|
1924
|
-
const
|
|
1925
|
-
if (
|
|
1926
|
-
throw new Error(
|
|
1927
|
-
const E = (
|
|
1928
|
-
if (
|
|
1929
|
-
throw new Error(
|
|
1930
|
-
|
|
1931
|
-
} catch (
|
|
1932
|
-
|
|
1933
|
-
}
|
|
1934
|
-
|
|
2024
|
+
if (!b.ok)
|
|
2025
|
+
throw new Error(`Server returned ${b.status}`);
|
|
2026
|
+
const f = await b.json();
|
|
2027
|
+
if (f.error)
|
|
2028
|
+
throw new Error(f.error.message);
|
|
2029
|
+
const E = (D = (T = (M = f.result) == null ? void 0 : M.content) == null ? void 0 : T[0]) == null ? void 0 : D.text;
|
|
2030
|
+
if (u = JSON.parse(E), !u.success)
|
|
2031
|
+
throw new Error(u.error);
|
|
2032
|
+
C.succeed("Upload URL obtained");
|
|
2033
|
+
} catch (b) {
|
|
2034
|
+
C.fail("Failed to get upload URL"), console.error(" ", b.message), process.exit(1);
|
|
2035
|
+
}
|
|
2036
|
+
C = G("Uploading component...").start();
|
|
1935
2037
|
try {
|
|
1936
|
-
const
|
|
1937
|
-
let
|
|
1938
|
-
const E =
|
|
2038
|
+
const b = t.readFileSync(v, "utf-8");
|
|
2039
|
+
let f;
|
|
2040
|
+
const E = u.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
|
|
1939
2041
|
if (E)
|
|
1940
|
-
|
|
2042
|
+
f = E[1];
|
|
1941
2043
|
else {
|
|
1942
|
-
const
|
|
1943
|
-
if (
|
|
1944
|
-
|
|
2044
|
+
const B = u.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
|
|
2045
|
+
if (B)
|
|
2046
|
+
f = B[1];
|
|
1945
2047
|
else
|
|
1946
|
-
throw new Error("Could not parse presigned URL from: " +
|
|
2048
|
+
throw new Error("Could not parse presigned URL from: " + u.curlCommand);
|
|
1947
2049
|
}
|
|
1948
|
-
console.info("Uploading to:",
|
|
1949
|
-
const
|
|
2050
|
+
console.info("Uploading to:", f.substring(0, 100) + "...");
|
|
2051
|
+
const _ = await fetch(f, {
|
|
1950
2052
|
method: "PUT",
|
|
1951
2053
|
headers: {
|
|
1952
2054
|
"Content-Type": "text/html"
|
|
1953
2055
|
},
|
|
1954
|
-
body:
|
|
2056
|
+
body: b
|
|
1955
2057
|
});
|
|
1956
|
-
if (!
|
|
1957
|
-
const
|
|
1958
|
-
throw new Error(`Upload failed with status ${
|
|
2058
|
+
if (!_.ok) {
|
|
2059
|
+
const B = await _.text();
|
|
2060
|
+
throw new Error(`Upload failed with status ${_.status}: ${B}`);
|
|
1959
2061
|
}
|
|
1960
|
-
|
|
1961
|
-
} catch (
|
|
1962
|
-
|
|
2062
|
+
C.succeed("Component uploaded");
|
|
2063
|
+
} catch (b) {
|
|
2064
|
+
C.fail("Upload failed"), console.error(" ", b.message), b.cause && console.error(" Cause:", b.cause), process.exit(1);
|
|
1963
2065
|
}
|
|
1964
|
-
|
|
2066
|
+
C = G("Confirming upload...").start();
|
|
1965
2067
|
let S;
|
|
1966
2068
|
try {
|
|
1967
|
-
const
|
|
2069
|
+
const b = await fetch(`${d}/mcp`, {
|
|
1968
2070
|
method: "POST",
|
|
1969
2071
|
headers: {
|
|
1970
2072
|
"Content-Type": "application/json",
|
|
1971
|
-
Authorization: `Bearer ${
|
|
2073
|
+
Authorization: `Bearer ${m.accessToken}`
|
|
1972
2074
|
},
|
|
1973
2075
|
body: JSON.stringify({
|
|
1974
2076
|
jsonrpc: "2.0",
|
|
@@ -1977,50 +2079,329 @@ y.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1977
2079
|
params: {
|
|
1978
2080
|
name: "confirm_upload",
|
|
1979
2081
|
arguments: {
|
|
1980
|
-
uploadId:
|
|
2082
|
+
uploadId: u.uploadId
|
|
1981
2083
|
}
|
|
1982
2084
|
}
|
|
1983
2085
|
})
|
|
1984
2086
|
});
|
|
1985
|
-
if (!
|
|
1986
|
-
throw new Error(`Server returned ${
|
|
1987
|
-
const
|
|
1988
|
-
if (
|
|
1989
|
-
throw new Error(
|
|
1990
|
-
const E = (
|
|
2087
|
+
if (!b.ok)
|
|
2088
|
+
throw new Error(`Server returned ${b.status}`);
|
|
2089
|
+
const f = await b.json();
|
|
2090
|
+
if (f.error)
|
|
2091
|
+
throw new Error(f.error.message);
|
|
2092
|
+
const E = (j = (x = (P = f.result) == null ? void 0 : P.content) == null ? void 0 : x[0]) == null ? void 0 : j.text;
|
|
1991
2093
|
if (S = JSON.parse(E), !S.success)
|
|
1992
2094
|
throw new Error(S.error);
|
|
1993
|
-
|
|
1994
|
-
} catch (
|
|
1995
|
-
|
|
2095
|
+
C.succeed("Upload confirmed");
|
|
2096
|
+
} catch (b) {
|
|
2097
|
+
C.fail("Confirmation failed"), console.error(" ", b.message), process.exit(1);
|
|
1996
2098
|
}
|
|
1997
2099
|
if (S.isNewComponent || !s.componentId) {
|
|
1998
2100
|
s.componentId = S.componentId, s.organization = S.orgId, s.name || (s.name = S.componentName);
|
|
1999
2101
|
try {
|
|
2000
2102
|
t.writeFileSync(e, JSON.stringify(s, null, 2)), console.log(`
|
|
2001
2103
|
π Updated ${e} with componentId`);
|
|
2002
|
-
} catch (
|
|
2104
|
+
} catch (b) {
|
|
2003
2105
|
console.log(`
|
|
2004
|
-
β οΈ Could not update ${e}: ${
|
|
2106
|
+
β οΈ Could not update ${e}: ${b.message}`), console.log(` Please add componentId: "${S.componentId}" manually`);
|
|
2005
2107
|
}
|
|
2006
2108
|
}
|
|
2007
2109
|
console.log(`
|
|
2008
2110
|
β
Sync completed successfully!`), console.log(` Component: ${S.componentName}`), console.log(` Dashboard: ${S.dashboardUrl}`), process.exit(0);
|
|
2009
2111
|
});
|
|
2010
|
-
y.program.command("
|
|
2011
|
-
|
|
2112
|
+
y.program.command("push").description("Upload component to Myop platform").action(async () => {
|
|
2113
|
+
var C, u, S, M, T, D;
|
|
2114
|
+
const o = y.program.getOptionValue("config") || "./myop.config.json";
|
|
2115
|
+
let e = {};
|
|
2116
|
+
if (R.existsSync(o))
|
|
2117
|
+
try {
|
|
2118
|
+
e = JSON.parse(R.readFileSync(o, "utf-8"));
|
|
2119
|
+
} catch (P) {
|
|
2120
|
+
console.error(`β οΈ Failed to parse ${o}:`, P.message);
|
|
2121
|
+
}
|
|
2122
|
+
const t = e.name || e.componentName || H.basename(process.cwd());
|
|
2123
|
+
console.log(`
|
|
2124
|
+
π Component: ${t}`);
|
|
2125
|
+
let n;
|
|
2126
|
+
const i = R.readdirSync(".").filter(
|
|
2127
|
+
(P) => P.endsWith(".html") && !P.startsWith(".") && R.statSync(P).isFile()
|
|
2128
|
+
);
|
|
2129
|
+
i.length === 1 && !R.existsSync("./dist/index.html") ? n = i[0] : R.existsSync("./dist/index.html") ? n = "./dist/index.html" : i.length === 1 ? n = i[0] : (console.error("β No HTML file found to upload."), console.log(" Expected: a single .html file in root or ./dist/index.html"), process.exit(1));
|
|
2130
|
+
const s = R.readFileSync(n, "utf-8");
|
|
2131
|
+
console.log(` File: ${n} (${(s.length / 1024).toFixed(1)} KB)`);
|
|
2132
|
+
let l;
|
|
2133
|
+
try {
|
|
2134
|
+
l = await st();
|
|
2135
|
+
} catch (P) {
|
|
2136
|
+
console.error("β Authentication failed:", P.message), process.exit(1);
|
|
2137
|
+
}
|
|
2138
|
+
const w = it();
|
|
2139
|
+
let v = G("Uploading...").start(), m;
|
|
2140
|
+
try {
|
|
2141
|
+
const P = await fetch(`${w}/mcp`, {
|
|
2142
|
+
method: "POST",
|
|
2143
|
+
headers: {
|
|
2144
|
+
"Content-Type": "application/json",
|
|
2145
|
+
Authorization: `Bearer ${l.accessToken}`
|
|
2146
|
+
},
|
|
2147
|
+
body: JSON.stringify({
|
|
2148
|
+
jsonrpc: "2.0",
|
|
2149
|
+
id: 1,
|
|
2150
|
+
method: "tools/call",
|
|
2151
|
+
params: {
|
|
2152
|
+
name: "upload_component",
|
|
2153
|
+
arguments: {
|
|
2154
|
+
name: t,
|
|
2155
|
+
componentId: e.componentId && e.componentId !== "DEV" ? e.componentId : void 0,
|
|
2156
|
+
organization: e.organization || void 0
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
})
|
|
2160
|
+
});
|
|
2161
|
+
if (!P.ok)
|
|
2162
|
+
throw new Error(`Server returned ${P.status}`);
|
|
2163
|
+
const x = await P.json();
|
|
2164
|
+
if (x.error)
|
|
2165
|
+
throw new Error(x.error.message);
|
|
2166
|
+
const j = (S = (u = (C = x.result) == null ? void 0 : C.content) == null ? void 0 : u[0]) == null ? void 0 : S.text;
|
|
2167
|
+
if (m = JSON.parse(j), !m.success)
|
|
2168
|
+
throw new Error(m.error);
|
|
2169
|
+
} catch (P) {
|
|
2170
|
+
v.fail("Failed to get upload URL"), console.error(" ", P.message), process.exit(1);
|
|
2171
|
+
}
|
|
2172
|
+
try {
|
|
2173
|
+
let P;
|
|
2174
|
+
const x = m.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
|
|
2175
|
+
if (x)
|
|
2176
|
+
P = x[1];
|
|
2177
|
+
else {
|
|
2178
|
+
const b = m.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
|
|
2179
|
+
if (b)
|
|
2180
|
+
P = b[1];
|
|
2181
|
+
else
|
|
2182
|
+
throw new Error("Could not parse presigned URL");
|
|
2183
|
+
}
|
|
2184
|
+
const j = await fetch(P, {
|
|
2185
|
+
method: "PUT",
|
|
2186
|
+
headers: { "Content-Type": "text/html" },
|
|
2187
|
+
body: s
|
|
2188
|
+
});
|
|
2189
|
+
if (!j.ok) {
|
|
2190
|
+
const b = await j.text();
|
|
2191
|
+
throw new Error(`Upload failed: ${j.status} ${b}`);
|
|
2192
|
+
}
|
|
2193
|
+
} catch (P) {
|
|
2194
|
+
v.fail("Upload failed"), console.error(" ", P.message), process.exit(1);
|
|
2195
|
+
}
|
|
2196
|
+
let d;
|
|
2197
|
+
try {
|
|
2198
|
+
const P = await fetch(`${w}/mcp`, {
|
|
2199
|
+
method: "POST",
|
|
2200
|
+
headers: {
|
|
2201
|
+
"Content-Type": "application/json",
|
|
2202
|
+
Authorization: `Bearer ${l.accessToken}`
|
|
2203
|
+
},
|
|
2204
|
+
body: JSON.stringify({
|
|
2205
|
+
jsonrpc: "2.0",
|
|
2206
|
+
id: 2,
|
|
2207
|
+
method: "tools/call",
|
|
2208
|
+
params: {
|
|
2209
|
+
name: "confirm_upload",
|
|
2210
|
+
arguments: {
|
|
2211
|
+
uploadId: m.uploadId
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
})
|
|
2215
|
+
});
|
|
2216
|
+
if (!P.ok)
|
|
2217
|
+
throw new Error(`Server returned ${P.status}`);
|
|
2218
|
+
const x = await P.json();
|
|
2219
|
+
if (x.error)
|
|
2220
|
+
throw new Error(x.error.message);
|
|
2221
|
+
const j = (D = (T = (M = x.result) == null ? void 0 : M.content) == null ? void 0 : T[0]) == null ? void 0 : D.text;
|
|
2222
|
+
if (d = JSON.parse(j), !d.success)
|
|
2223
|
+
throw new Error(d.error);
|
|
2224
|
+
v.succeed("Pushed successfully");
|
|
2225
|
+
} catch (P) {
|
|
2226
|
+
v.fail("Confirmation failed"), console.error(" ", P.message), process.exit(1);
|
|
2227
|
+
}
|
|
2228
|
+
if (d.isNewComponent || !e.componentId || e.componentId === "DEV") {
|
|
2229
|
+
e.componentId = d.componentId, e.organization = d.orgId, e.name || (e.name = d.componentName);
|
|
2230
|
+
try {
|
|
2231
|
+
R.writeFileSync(o, JSON.stringify(e, null, 2));
|
|
2232
|
+
} catch (P) {
|
|
2233
|
+
console.log(`β οΈ Could not update ${o}: ${P.message}`), console.log(` Add componentId: "${d.componentId}" manually`);
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
console.log(`
|
|
2237
|
+
${d.componentName}`), console.log(` ${d.dashboardUrl}
|
|
2238
|
+
`), process.exit(0);
|
|
2239
|
+
});
|
|
2240
|
+
y.program.command("create").description("Create a new Myop HTML component and start dev server").action(async () => {
|
|
2241
|
+
const { input: o } = await import("@inquirer/prompts"), e = await import("fs"), n = (await import("path")).default.basename(process.cwd());
|
|
2242
|
+
let i;
|
|
2012
2243
|
try {
|
|
2013
|
-
|
|
2244
|
+
i = await o({
|
|
2245
|
+
message: "Component name:",
|
|
2246
|
+
default: n
|
|
2247
|
+
});
|
|
2248
|
+
} catch (v) {
|
|
2249
|
+
throw v.name === "ExitPromptError" && (console.log(`
|
|
2250
|
+
|
|
2251
|
+
π Goodbye!
|
|
2252
|
+
`), process.exit(0)), v;
|
|
2253
|
+
}
|
|
2254
|
+
(e.existsSync("index.html") || e.existsSync("myop.config.json")) && (console.log(`
|
|
2255
|
+
β οΈ index.html or myop.config.json already exists in this directory.`), console.log(" Use `myop dev` to start the dev server for an existing component.\n"), process.exit(1));
|
|
2256
|
+
const s = {
|
|
2257
|
+
name: i,
|
|
2258
|
+
componentId: "DEV",
|
|
2259
|
+
type: "html",
|
|
2260
|
+
author: "@myop-cli",
|
|
2261
|
+
HMR: !0
|
|
2262
|
+
};
|
|
2263
|
+
e.writeFileSync("myop.config.json", JSON.stringify(s, null, 2));
|
|
2264
|
+
const l = `<!DOCTYPE html>
|
|
2265
|
+
<html lang="en">
|
|
2266
|
+
<head>
|
|
2267
|
+
<meta charset="UTF-8">
|
|
2268
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
2269
|
+
<meta name="myop:size" content='{"width":"100%","height":"100%"}'>
|
|
2270
|
+
<title>${i}</title>
|
|
2271
|
+
<script type="myop/types">
|
|
2272
|
+
// =========================================================================
|
|
2273
|
+
// MYOP COMPONENT TYPE DEFINITIONS
|
|
2274
|
+
// =========================================================================
|
|
2275
|
+
|
|
2276
|
+
/**
|
|
2277
|
+
* Data structure passed to myop_init_interface(data)
|
|
2278
|
+
*/
|
|
2279
|
+
interface MyopInitData {
|
|
2280
|
+
title: string;
|
|
2281
|
+
description?: string;
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
/**
|
|
2285
|
+
* Actions and payloads for myop_cta_handler(action, payload)
|
|
2286
|
+
*/
|
|
2287
|
+
interface MyopCtaPayloads {
|
|
2288
|
+
'button-clicked': { label: string };
|
|
2289
|
+
'size-requested': {
|
|
2290
|
+
width?: number | null;
|
|
2291
|
+
height?: number | null;
|
|
2292
|
+
minWidth?: number | null;
|
|
2293
|
+
maxWidth?: number | null;
|
|
2294
|
+
minHeight?: number | null;
|
|
2295
|
+
maxHeight?: number | null;
|
|
2296
|
+
required?: boolean;
|
|
2297
|
+
};
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
// =========================================================================
|
|
2301
|
+
// DO NOT EDIT BELOW - Standard Myop type declarations
|
|
2302
|
+
// =========================================================================
|
|
2303
|
+
|
|
2304
|
+
declare function myop_init_interface(): MyopInitData;
|
|
2305
|
+
declare function myop_init_interface(data: MyopInitData): void;
|
|
2306
|
+
|
|
2307
|
+
declare function myop_cta_handler<K extends keyof MyopCtaPayloads>(
|
|
2308
|
+
action: K,
|
|
2309
|
+
payload: MyopCtaPayloads[K]
|
|
2310
|
+
): void;
|
|
2311
|
+
<\/script>
|
|
2312
|
+
<style>
|
|
2313
|
+
* {
|
|
2314
|
+
box-sizing: border-box;
|
|
2315
|
+
margin: 0;
|
|
2316
|
+
padding: 0;
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
html, body {
|
|
2320
|
+
width: 100%;
|
|
2321
|
+
height: 100%;
|
|
2322
|
+
overflow: hidden;
|
|
2323
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
|
2324
|
+
color: #333;
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
#app-root {
|
|
2328
|
+
width: 100%;
|
|
2329
|
+
height: 100%;
|
|
2330
|
+
display: flex;
|
|
2331
|
+
flex-direction: column;
|
|
2332
|
+
align-items: center;
|
|
2333
|
+
justify-content: center;
|
|
2334
|
+
padding: 24px;
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2337
|
+
h1 {
|
|
2338
|
+
font-size: 24px;
|
|
2339
|
+
margin-bottom: 8px;
|
|
2340
|
+
color: #1a1a1a;
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
p {
|
|
2344
|
+
color: #666;
|
|
2345
|
+
line-height: 1.5;
|
|
2346
|
+
}
|
|
2347
|
+
</style>
|
|
2348
|
+
</head>
|
|
2349
|
+
<body>
|
|
2350
|
+
<div id="app-root">
|
|
2351
|
+
<h1>${i}</h1>
|
|
2352
|
+
<p>Edit index.html to get started</p>
|
|
2353
|
+
</div>
|
|
2354
|
+
|
|
2355
|
+
<script>
|
|
2356
|
+
(function() {
|
|
2357
|
+
var currentState = {};
|
|
2358
|
+
|
|
2359
|
+
function render(data) {
|
|
2360
|
+
currentState = data;
|
|
2361
|
+
var root = document.getElementById('app-root');
|
|
2362
|
+
root.innerHTML =
|
|
2363
|
+
'<h1>' + (data.title || '') + '</h1>' +
|
|
2364
|
+
(data.description ? '<p>' + data.description + '</p>' : '');
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
window.myop_init_interface = function(data) {
|
|
2368
|
+
if (!data) return currentState;
|
|
2369
|
+
render(data);
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
window.myop_cta_handler = function(action_id, payload) {
|
|
2373
|
+
// Will be overridden by host application
|
|
2374
|
+
};
|
|
2375
|
+
})();
|
|
2376
|
+
<\/script>
|
|
2377
|
+
|
|
2378
|
+
<script id="myop_preview">
|
|
2379
|
+
window.myop_init_interface({
|
|
2380
|
+
title: '${i}',
|
|
2381
|
+
description: 'Edit index.html to get started'
|
|
2382
|
+
});
|
|
2383
|
+
<\/script>
|
|
2384
|
+
</body>
|
|
2385
|
+
</html>`;
|
|
2386
|
+
e.writeFileSync("index.html", l);
|
|
2387
|
+
const w = rt(process.cwd());
|
|
2388
|
+
console.log(`
|
|
2389
|
+
β
Created ${i}`), console.log(" index.html"), console.log(" myop.config.json"), w && console.log(" .agents/skills/ (AI agent skills)"), console.log(""), await be();
|
|
2390
|
+
});
|
|
2391
|
+
y.program.command("dev").description("Start development server with file watching").action(be);
|
|
2392
|
+
const to = () => {
|
|
2393
|
+
try {
|
|
2394
|
+
q("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
2014
2395
|
} catch {
|
|
2015
2396
|
return { gitNotInstalled: !0 };
|
|
2016
2397
|
}
|
|
2017
2398
|
try {
|
|
2018
|
-
|
|
2399
|
+
q("git rev-parse --git-dir", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
2019
2400
|
} catch {
|
|
2020
2401
|
return { notARepo: !0 };
|
|
2021
2402
|
}
|
|
2022
2403
|
try {
|
|
2023
|
-
const o =
|
|
2404
|
+
const o = q("git diff --stat HEAD -- . 2>/dev/null || git diff --stat -- . 2>/dev/null", {
|
|
2024
2405
|
encoding: "utf-8",
|
|
2025
2406
|
stdio: ["pipe", "pipe", "pipe"]
|
|
2026
2407
|
}).trim();
|
|
@@ -2031,22 +2412,22 @@ const Gt = () => {
|
|
|
2031
2412
|
deletions: 0
|
|
2032
2413
|
};
|
|
2033
2414
|
const e = o.split(`
|
|
2034
|
-
`), t = e[e.length - 1], n = t.match(/(\d+) insertion/),
|
|
2415
|
+
`), t = e[e.length - 1], n = t.match(/(\d+) insertion/), i = t.match(/(\d+) deletion/), s = t.match(/(\d+) file/);
|
|
2035
2416
|
return {
|
|
2036
2417
|
files: s ? parseInt(s[1]) : 0,
|
|
2037
2418
|
insertions: n ? parseInt(n[1]) : 0,
|
|
2038
|
-
deletions:
|
|
2419
|
+
deletions: i ? parseInt(i[1]) : 0
|
|
2039
2420
|
};
|
|
2040
2421
|
} catch {
|
|
2041
2422
|
return null;
|
|
2042
2423
|
}
|
|
2043
|
-
},
|
|
2044
|
-
var
|
|
2045
|
-
const t =
|
|
2424
|
+
}, ne = async (o = !1, e = !1) => {
|
|
2425
|
+
var d, C, u;
|
|
2426
|
+
const t = xe(), n = !!(t != null && t.email), i = ((d = y.myopConfig) == null ? void 0 : d.name) || ((C = y.myopConfig) == null ? void 0 : C.componentName), s = (u = y.myopConfig) == null ? void 0 : u.componentId, l = to();
|
|
2046
2427
|
console.log(`
|
|
2047
2428
|
βββββββββββββββββββββββββββββββββββββββββββββββββββ`), console.log("β β"), console.log("β Welcome to Myop CLI - Remote UI Made Easy β"), console.log("β β"), console.log(`βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
2048
|
-
`), o &&
|
|
2049
|
-
const
|
|
2429
|
+
`), o && i ? (console.log(` Component: ${i}`), s ? (console.log(` ID: ${s}`), console.log(` Dashboard: https://dashboard.myop.dev/dashboard/2.0/component/${s}`)) : console.log(" ID: (not yet pushed)")) : console.log(" Component: No myop.config.json found"), console.log(` User: ${n ? t.email : "Not logged in"}`), l != null && l.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")) : l != null && l.notARepo ? console.log(" Changes: Not a git repository") : l && (l.insertions > 0 || l.deletions > 0) ? console.log(` Changes: ${l.files} file${l.files !== 1 ? "s" : ""} | \x1B[32m+${l.insertions}\x1B[0m \x1B[31m-${l.deletions}\x1B[0m`) : l && console.log(" Changes: No uncommitted changes"), console.log("");
|
|
2430
|
+
const v = [
|
|
2050
2431
|
{
|
|
2051
2432
|
emoji: "π",
|
|
2052
2433
|
label: "Initialize new component",
|
|
@@ -2056,26 +2437,26 @@ const Gt = () => {
|
|
|
2056
2437
|
},
|
|
2057
2438
|
{
|
|
2058
2439
|
emoji: "π οΈ ",
|
|
2059
|
-
label:
|
|
2440
|
+
label: i ? `Start dev mode for "${i}"` : "Start dev mode",
|
|
2060
2441
|
value: "dev",
|
|
2061
2442
|
help: "Starts dev server with HMR for instant preview of changes",
|
|
2062
2443
|
disabled: o ? !1 : "(no config file)"
|
|
2063
2444
|
},
|
|
2064
2445
|
{
|
|
2065
2446
|
emoji: "π¦",
|
|
2066
|
-
label:
|
|
2447
|
+
label: i ? `Push "${i}"` : "Push component",
|
|
2067
2448
|
value: "sync",
|
|
2068
2449
|
help: "Builds project & uploads dist/index.html to Myop",
|
|
2069
2450
|
disabled: o ? n ? !1 : "(login required)" : "(no config file)"
|
|
2070
2451
|
}
|
|
2071
|
-
].map((
|
|
2072
|
-
name: e && !
|
|
2073
|
-
${
|
|
2074
|
-
value:
|
|
2075
|
-
disabled:
|
|
2452
|
+
].map((S) => ({
|
|
2453
|
+
name: e && !S.disabled ? `${S.emoji} ${S.label}
|
|
2454
|
+
${S.help}` : `${S.emoji} ${S.label}`,
|
|
2455
|
+
value: S.value,
|
|
2456
|
+
disabled: S.disabled
|
|
2076
2457
|
}));
|
|
2077
|
-
|
|
2078
|
-
new
|
|
2458
|
+
v.push(
|
|
2459
|
+
new Fe(),
|
|
2079
2460
|
{
|
|
2080
2461
|
name: e && n ? `π Logout (${t.email})
|
|
2081
2462
|
Clears stored credentials from this machine` : e && !n ? `π Login to Myop
|
|
@@ -2086,124 +2467,124 @@ const Gt = () => {
|
|
|
2086
2467
|
name: e ? "π Hide help" : "π Show help",
|
|
2087
2468
|
value: "help"
|
|
2088
2469
|
},
|
|
2089
|
-
new
|
|
2470
|
+
new Fe(),
|
|
2090
2471
|
{
|
|
2091
2472
|
name: "π Exit",
|
|
2092
2473
|
value: "exit"
|
|
2093
2474
|
}
|
|
2094
2475
|
);
|
|
2095
|
-
let
|
|
2476
|
+
let m;
|
|
2096
2477
|
try {
|
|
2097
|
-
|
|
2478
|
+
m = await Ye({
|
|
2098
2479
|
message: "What would you like to do?",
|
|
2099
|
-
choices:
|
|
2480
|
+
choices: v
|
|
2100
2481
|
});
|
|
2101
|
-
} catch (
|
|
2102
|
-
throw
|
|
2482
|
+
} catch (S) {
|
|
2483
|
+
throw S.name === "ExitPromptError" && (console.log(`
|
|
2103
2484
|
|
|
2104
2485
|
π Goodbye!
|
|
2105
|
-
`), process.exit(0)),
|
|
2486
|
+
`), process.exit(0)), S;
|
|
2106
2487
|
}
|
|
2107
|
-
switch (
|
|
2488
|
+
switch (m) {
|
|
2108
2489
|
case "init":
|
|
2109
|
-
await
|
|
2490
|
+
await io();
|
|
2110
2491
|
break;
|
|
2111
2492
|
case "sync":
|
|
2112
2493
|
console.log(`
|
|
2113
2494
|
Running sync...
|
|
2114
2495
|
`);
|
|
2115
|
-
const { execSync:
|
|
2496
|
+
const { execSync: S } = await import("child_process");
|
|
2116
2497
|
try {
|
|
2117
|
-
|
|
2498
|
+
S("node " + process.argv[1] + " sync", { stdio: "inherit" });
|
|
2118
2499
|
} catch {
|
|
2119
2500
|
}
|
|
2120
|
-
await
|
|
2501
|
+
await ne(!0, e);
|
|
2121
2502
|
break;
|
|
2122
2503
|
case "dev":
|
|
2123
|
-
await
|
|
2504
|
+
await be();
|
|
2124
2505
|
break;
|
|
2125
2506
|
case "login":
|
|
2126
2507
|
try {
|
|
2127
|
-
await
|
|
2128
|
-
`), await
|
|
2129
|
-
} catch (
|
|
2130
|
-
console.error("Login failed:",
|
|
2508
|
+
await de(), console.log(`
|
|
2509
|
+
`), await ne(o, e);
|
|
2510
|
+
} catch (M) {
|
|
2511
|
+
console.error("Login failed:", M.message), await ne(o, e);
|
|
2131
2512
|
}
|
|
2132
2513
|
break;
|
|
2133
2514
|
case "logout":
|
|
2134
|
-
await
|
|
2135
|
-
`), await
|
|
2515
|
+
await nt(), console.log(`
|
|
2516
|
+
`), await ne(o, e);
|
|
2136
2517
|
break;
|
|
2137
2518
|
case "help":
|
|
2138
|
-
await
|
|
2519
|
+
await ne(o, !e);
|
|
2139
2520
|
break;
|
|
2140
2521
|
case "exit":
|
|
2141
2522
|
process.exit(0);
|
|
2142
2523
|
}
|
|
2143
|
-
}, ve = ".myop-monorepo.json",
|
|
2524
|
+
}, ve = ".myop-monorepo.json", oo = () => {
|
|
2144
2525
|
try {
|
|
2145
|
-
const o =
|
|
2526
|
+
const o = R.readFileSync(ve, "utf-8");
|
|
2146
2527
|
return JSON.parse(o);
|
|
2147
2528
|
} catch {
|
|
2148
2529
|
return null;
|
|
2149
2530
|
}
|
|
2150
|
-
},
|
|
2531
|
+
}, no = (o) => {
|
|
2151
2532
|
try {
|
|
2152
2533
|
const e = {
|
|
2153
2534
|
selectedComponents: o,
|
|
2154
2535
|
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
2155
2536
|
};
|
|
2156
|
-
|
|
2537
|
+
R.writeFileSync(ve, JSON.stringify(e, null, 2));
|
|
2157
2538
|
} catch {
|
|
2158
2539
|
}
|
|
2159
|
-
},
|
|
2160
|
-
const o =
|
|
2540
|
+
}, so = async () => {
|
|
2541
|
+
const o = xe(), e = !!(o != null && o.email);
|
|
2161
2542
|
console.log(`
|
|
2162
2543
|
βββββββββββββββββββββββββββββββββββββββββββββββββββ`), console.log("β β"), console.log("β Myop CLI - Monorepo Mode β"), console.log("β β"), console.log(`βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
2163
2544
|
`);
|
|
2164
|
-
const t =
|
|
2545
|
+
const t = G("Scanning for components...").start(), n = at(".");
|
|
2165
2546
|
t.stop(), n.length === 0 && (console.log(` β οΈ No myop.config.json files found in this directory or subdirectories.
|
|
2166
2547
|
`), console.log(" Run `myop` without -m flag to initialize a single component.\n"), process.exit(0));
|
|
2167
|
-
const
|
|
2548
|
+
const i = oo(), s = (i == null ? void 0 : i.selectedComponents) || [], l = s.length > 0;
|
|
2168
2549
|
console.log(` Found ${n.length} component${n.length > 1 ? "s" : ""}:
|
|
2169
|
-
`), n.forEach((
|
|
2170
|
-
const
|
|
2171
|
-
console.log(` ${
|
|
2172
|
-
}), console.log(` User: ${e ? o.email : "Not logged in"}`),
|
|
2173
|
-
const { checkbox:
|
|
2174
|
-
name: `${
|
|
2175
|
-
value:
|
|
2176
|
-
checked:
|
|
2550
|
+
`), n.forEach((u, S) => {
|
|
2551
|
+
const M = u.componentId ? "β
" : "βͺ", T = u.componentId ? u.componentId.substring(0, 8) + "..." : "(not pushed)";
|
|
2552
|
+
console.log(` ${M} ${u.name}`), console.log(` Path: ${u.path}`), console.log(` ID: ${T}`), console.log("");
|
|
2553
|
+
}), console.log(` User: ${e ? o.email : "Not logged in"}`), l && console.log(` π Using saved selection from ${ve}`), console.log("");
|
|
2554
|
+
const { checkbox: w } = await import("@inquirer/prompts"), v = n.map((u) => ({
|
|
2555
|
+
name: `${u.name} (${u.path})`,
|
|
2556
|
+
value: u.path,
|
|
2557
|
+
checked: l ? s.includes(u.path) : !0
|
|
2177
2558
|
}));
|
|
2178
|
-
let
|
|
2559
|
+
let m;
|
|
2179
2560
|
try {
|
|
2180
|
-
|
|
2561
|
+
m = await w({
|
|
2181
2562
|
message: "Select components to start in dev mode:",
|
|
2182
|
-
choices:
|
|
2563
|
+
choices: v
|
|
2183
2564
|
});
|
|
2184
|
-
} catch (
|
|
2185
|
-
throw
|
|
2565
|
+
} catch (u) {
|
|
2566
|
+
throw u.name === "ExitPromptError" && (console.log(`
|
|
2186
2567
|
|
|
2187
2568
|
π Goodbye!
|
|
2188
|
-
`), process.exit(0)),
|
|
2569
|
+
`), process.exit(0)), u;
|
|
2189
2570
|
}
|
|
2190
|
-
|
|
2571
|
+
m.length === 0 && (console.log(`
|
|
2191
2572
|
β οΈ No components selected.
|
|
2192
|
-
`), process.exit(0)),
|
|
2573
|
+
`), process.exit(0)), no(m), console.log(`
|
|
2193
2574
|
πΎ Selection saved to ${ve}`);
|
|
2194
|
-
const
|
|
2195
|
-
console.log(`π Starting dev mode for ${
|
|
2575
|
+
const d = n.filter((u) => m.includes(u.path));
|
|
2576
|
+
console.log(`π Starting dev mode for ${d.length} component${d.length > 1 ? "s" : ""}...
|
|
2196
2577
|
`);
|
|
2197
|
-
const { monorepoDevCommand:
|
|
2198
|
-
await
|
|
2199
|
-
},
|
|
2200
|
-
const { input: o, select: e } = await import("@inquirer/prompts"), t = await import("fs"),
|
|
2201
|
-
let s,
|
|
2578
|
+
const { monorepoDevCommand: C } = await Promise.resolve().then(() => _t);
|
|
2579
|
+
await C(d);
|
|
2580
|
+
}, io = async () => {
|
|
2581
|
+
const { input: o, select: e } = await import("@inquirer/prompts"), t = await import("fs"), n = await import("path"), i = n.default.basename(process.cwd());
|
|
2582
|
+
let s, l;
|
|
2202
2583
|
try {
|
|
2203
2584
|
s = await o({
|
|
2204
2585
|
message: "Component name:",
|
|
2205
|
-
default:
|
|
2206
|
-
}),
|
|
2586
|
+
default: i
|
|
2587
|
+
}), l = await e({
|
|
2207
2588
|
message: "Component type:",
|
|
2208
2589
|
choices: [
|
|
2209
2590
|
{ name: "π HTML", value: "html", description: "Plain HTML/JS/CSS component" },
|
|
@@ -2212,22 +2593,22 @@ Running sync...
|
|
|
2212
2593
|
{ name: "π
°οΈ Angular", value: "angular", disabled: "(coming soon)" }
|
|
2213
2594
|
]
|
|
2214
2595
|
});
|
|
2215
|
-
} catch (
|
|
2216
|
-
throw
|
|
2596
|
+
} catch (m) {
|
|
2597
|
+
throw m.name === "ExitPromptError" && (console.log(`
|
|
2217
2598
|
|
|
2218
2599
|
π Goodbye!
|
|
2219
|
-
`), process.exit(0)),
|
|
2600
|
+
`), process.exit(0)), m;
|
|
2220
2601
|
}
|
|
2221
|
-
const
|
|
2602
|
+
const w = {
|
|
2222
2603
|
name: s,
|
|
2223
|
-
type:
|
|
2604
|
+
type: l,
|
|
2224
2605
|
author: "@myop-cli",
|
|
2225
2606
|
HMR: !0
|
|
2226
|
-
},
|
|
2607
|
+
}, v = y.program.getOptionValue("config") || "./myop.config.json";
|
|
2227
2608
|
try {
|
|
2228
|
-
t.writeFileSync(
|
|
2229
|
-
β
Created ${
|
|
2230
|
-
const
|
|
2609
|
+
t.writeFileSync(v, JSON.stringify(w, null, 2)), console.log(`
|
|
2610
|
+
β
Created ${v}`);
|
|
2611
|
+
const m = {
|
|
2231
2612
|
name: s.toLowerCase().replace(/\s+/g, "-"),
|
|
2232
2613
|
version: "1.0.0",
|
|
2233
2614
|
type: "module",
|
|
@@ -2239,7 +2620,7 @@ Running sync...
|
|
|
2239
2620
|
esbuild: "^0.24.0"
|
|
2240
2621
|
}
|
|
2241
2622
|
};
|
|
2242
|
-
t.writeFileSync("package.json", JSON.stringify(
|
|
2623
|
+
t.writeFileSync("package.json", JSON.stringify(m, null, 2)), console.log("β
Created package.json"), t.mkdirSync("src/modules", { recursive: !0 }), t.mkdirSync("src/styles", { recursive: !0 }), t.writeFileSync("build.js", `import * as esbuild from 'esbuild';
|
|
2243
2624
|
import fs from 'fs';
|
|
2244
2625
|
import path from 'path';
|
|
2245
2626
|
|
|
@@ -2319,7 +2700,7 @@ fs.writeFileSync('dist/index.html', html);
|
|
|
2319
2700
|
console.log('β
Built dist/index.html');
|
|
2320
2701
|
console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS files\`);
|
|
2321
2702
|
`), console.log("β
Created build.js");
|
|
2322
|
-
const
|
|
2703
|
+
const C = `<!DOCTYPE html>
|
|
2323
2704
|
<html lang="en">
|
|
2324
2705
|
<head>
|
|
2325
2706
|
<meta charset="UTF-8">
|
|
@@ -2336,8 +2717,8 @@ console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS
|
|
|
2336
2717
|
</body>
|
|
2337
2718
|
</html>
|
|
2338
2719
|
`;
|
|
2339
|
-
t.writeFileSync("index.html",
|
|
2340
|
-
const
|
|
2720
|
+
t.writeFileSync("index.html", C), console.log("β
Created index.html");
|
|
2721
|
+
const u = `// ${s} - Entry Point
|
|
2341
2722
|
import { init } from './modules/app.js';
|
|
2342
2723
|
import { setupMyopInterface } from './modules/myop.js';
|
|
2343
2724
|
|
|
@@ -2346,8 +2727,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
2346
2727
|
setupMyopInterface();
|
|
2347
2728
|
});
|
|
2348
2729
|
`;
|
|
2349
|
-
t.writeFileSync("src/index.js",
|
|
2350
|
-
const
|
|
2730
|
+
t.writeFileSync("src/index.js", u), console.log("β
Created src/index.js");
|
|
2731
|
+
const S = `// ${s} - Main Application Logic
|
|
2351
2732
|
|
|
2352
2733
|
export function init() {
|
|
2353
2734
|
console.log('${s} loaded');
|
|
@@ -2355,7 +2736,7 @@ export function init() {
|
|
|
2355
2736
|
// Your component logic here
|
|
2356
2737
|
}
|
|
2357
2738
|
`;
|
|
2358
|
-
t.writeFileSync("src/modules/app.js",
|
|
2739
|
+
t.writeFileSync("src/modules/app.js", S), console.log("β
Created src/modules/app.js"), t.writeFileSync("src/modules/myop.js", `// Myop Interface - Communication with host app
|
|
2359
2740
|
|
|
2360
2741
|
export function setupMyopInterface() {
|
|
2361
2742
|
// Called when host app sends data to this component
|
|
@@ -2371,12 +2752,12 @@ export function setupMyopInterface() {
|
|
|
2371
2752
|
};
|
|
2372
2753
|
}
|
|
2373
2754
|
`), console.log("β
Created src/modules/myop.js");
|
|
2374
|
-
const
|
|
2755
|
+
const T = `/* ${s} - Styles Entry Point */
|
|
2375
2756
|
/* Add your CSS imports here - they will be auto-bundled */
|
|
2376
2757
|
@import './main.css';
|
|
2377
2758
|
`;
|
|
2378
|
-
t.writeFileSync("src/styles/index.css",
|
|
2379
|
-
const
|
|
2759
|
+
t.writeFileSync("src/styles/index.css", T), console.log("β
Created src/styles/index.css");
|
|
2760
|
+
const D = `/* ${s} - Main Styles */
|
|
2380
2761
|
|
|
2381
2762
|
* {
|
|
2382
2763
|
box-sizing: border-box;
|
|
@@ -2405,16 +2786,18 @@ p {
|
|
|
2405
2786
|
line-height: 1.5;
|
|
2406
2787
|
}
|
|
2407
2788
|
`;
|
|
2408
|
-
t.writeFileSync("src/styles/main.css",
|
|
2789
|
+
t.writeFileSync("src/styles/main.css", D), console.log("β
Created src/styles/main.css"), t.writeFileSync(".gitignore", `node_modules/
|
|
2409
2790
|
dist/
|
|
2410
2791
|
.temp-entry.js
|
|
2411
2792
|
.temp-styles.css
|
|
2412
2793
|
.DS_Store
|
|
2413
2794
|
`), console.log("β
Created .gitignore");
|
|
2414
|
-
const
|
|
2795
|
+
const x = rt(process.cwd());
|
|
2796
|
+
x && console.log("β
Installed AI agent skills");
|
|
2797
|
+
const j = await import("./index-DuEoKctW.js").then((f) => f.i), b = process.cwd();
|
|
2415
2798
|
try {
|
|
2416
|
-
await
|
|
2417
|
-
const
|
|
2799
|
+
await j.init({ fs: t, dir: b });
|
|
2800
|
+
const f = [
|
|
2418
2801
|
"myop.config.json",
|
|
2419
2802
|
"package.json",
|
|
2420
2803
|
"build.js",
|
|
@@ -2426,64 +2809,77 @@ dist/
|
|
|
2426
2809
|
"src/styles/index.css",
|
|
2427
2810
|
"src/styles/main.css"
|
|
2428
2811
|
];
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2812
|
+
if (x) {
|
|
2813
|
+
const E = (_, B) => {
|
|
2814
|
+
try {
|
|
2815
|
+
const U = t.readdirSync(_, { withFileTypes: !0 });
|
|
2816
|
+
for (const k of U) {
|
|
2817
|
+
const z = n.join(_, k.name), I = n.join(B, k.name);
|
|
2818
|
+
k.isDirectory() ? E(z, I) : f.push(I);
|
|
2819
|
+
}
|
|
2820
|
+
} catch {
|
|
2821
|
+
}
|
|
2822
|
+
};
|
|
2823
|
+
E(".agents/skills", ".agents/skills");
|
|
2824
|
+
}
|
|
2825
|
+
for (const E of f)
|
|
2826
|
+
await j.add({ fs: t, dir: b, filepath: E });
|
|
2827
|
+
await j.commit({
|
|
2432
2828
|
fs: t,
|
|
2433
|
-
dir:
|
|
2829
|
+
dir: b,
|
|
2434
2830
|
message: "init",
|
|
2435
2831
|
author: { name: "myop-cli", email: "cli@myop.dev" }
|
|
2436
2832
|
}), console.log("β
Initialized git repository");
|
|
2437
|
-
} catch (
|
|
2438
|
-
console.log("β οΈ Failed to initialize git repository:",
|
|
2833
|
+
} catch (f) {
|
|
2834
|
+
console.log("β οΈ Failed to initialize git repository:", f.message);
|
|
2439
2835
|
}
|
|
2440
2836
|
console.log(`
|
|
2441
2837
|
π¦ Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
|
|
2442
|
-
`), y.myopConfig =
|
|
2443
|
-
} catch (
|
|
2444
|
-
console.error(`Failed to initialize component: ${
|
|
2838
|
+
`), y.myopConfig = w, await ne(!0);
|
|
2839
|
+
} catch (m) {
|
|
2840
|
+
console.error(`Failed to initialize component: ${m.message}`), process.exit(1);
|
|
2445
2841
|
}
|
|
2446
2842
|
};
|
|
2447
2843
|
y.program.command("default", { isDefault: !0 }).action(async () => {
|
|
2448
|
-
if (y.program.getOptionValue("help") && (console.log(
|
|
2449
|
-
await
|
|
2844
|
+
if (y.program.getOptionValue("help") && (console.log(bt), process.exit()), y.program.getOptionValue("monorepo")) {
|
|
2845
|
+
await so();
|
|
2450
2846
|
return;
|
|
2451
2847
|
}
|
|
2452
2848
|
if (y.program.getOptionValue("ci")) {
|
|
2453
|
-
const
|
|
2454
|
-
let
|
|
2849
|
+
const w = await import("fs"), v = y.program.getOptionValue("config") || "./myop.config.json", m = y.program.version(), d = xe();
|
|
2850
|
+
let C = { found: !1 };
|
|
2455
2851
|
try {
|
|
2456
|
-
if (
|
|
2457
|
-
const
|
|
2458
|
-
|
|
2852
|
+
if (w.existsSync(v)) {
|
|
2853
|
+
const S = w.readFileSync(v, "utf-8"), M = JSON.parse(S);
|
|
2854
|
+
C = {
|
|
2459
2855
|
found: !0,
|
|
2460
|
-
path:
|
|
2461
|
-
name:
|
|
2462
|
-
componentId:
|
|
2463
|
-
organization:
|
|
2856
|
+
path: v,
|
|
2857
|
+
name: M.name || M.componentName || null,
|
|
2858
|
+
componentId: M.componentId || null,
|
|
2859
|
+
organization: M.organization || null
|
|
2464
2860
|
};
|
|
2465
2861
|
}
|
|
2466
|
-
} catch (
|
|
2467
|
-
|
|
2862
|
+
} catch (S) {
|
|
2863
|
+
C = { found: !1, error: S.message };
|
|
2468
2864
|
}
|
|
2469
|
-
const
|
|
2470
|
-
version:
|
|
2471
|
-
config:
|
|
2865
|
+
const u = {
|
|
2866
|
+
version: m,
|
|
2867
|
+
config: C,
|
|
2472
2868
|
auth: {
|
|
2473
|
-
loggedIn: !!(
|
|
2474
|
-
email: (
|
|
2869
|
+
loggedIn: !!(d != null && d.email),
|
|
2870
|
+
email: (d == null ? void 0 : d.email) || null
|
|
2475
2871
|
}
|
|
2476
2872
|
};
|
|
2477
|
-
console.log(JSON.stringify(
|
|
2873
|
+
console.log(JSON.stringify(u, null, 2)), process.exit(0);
|
|
2478
2874
|
}
|
|
2479
|
-
let n =
|
|
2875
|
+
let n = G({
|
|
2480
2876
|
text: "Loading Myop CLI...",
|
|
2481
2877
|
color: "green"
|
|
2482
2878
|
}).start();
|
|
2483
|
-
const
|
|
2484
|
-
await
|
|
2879
|
+
const i = $e();
|
|
2880
|
+
await Xt(500), n.stop();
|
|
2485
2881
|
const s = y.program.version();
|
|
2486
|
-
await
|
|
2882
|
+
await Zt(s) || await ne(i.configFound);
|
|
2487
2883
|
});
|
|
2488
2884
|
y.program.parse(process.argv);
|
|
2489
2885
|
y.program.opts();
|