@myop/cli 0.1.20 → 0.1.22
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/index-DuEoKctW.js +11988 -0
- package/dist/myop-cli.js +1231 -767
- package/package.json +3 -1
package/dist/myop-cli.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
2
|
+
var rt = Object.defineProperty;
|
|
3
|
+
var at = (o, e, t) => e in o ? rt(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
4
|
+
var ue = (o, e, t) => at(o, typeof e != "symbol" ? e + "" : e, t);
|
|
5
|
+
import W from "ora";
|
|
6
|
+
import { select as Je, Separator as Re } from "@inquirer/prompts";
|
|
7
|
+
import { Command as lt, Option as le } from "commander";
|
|
8
|
+
import { execSync as fe, spawn as ct } from "child_process";
|
|
9
|
+
import ee from "path";
|
|
10
|
+
import H from "fs";
|
|
11
|
+
import Ie from "crypto";
|
|
12
|
+
import dt from "http";
|
|
13
|
+
import { URL as ze, URLSearchParams as We } from "url";
|
|
14
|
+
import pt from "open";
|
|
15
|
+
import mt from "os";
|
|
16
|
+
const ut = `
|
|
14
17
|
Usage: myop [OPTIONS] COMMAND [ARGS]...
|
|
15
18
|
|
|
16
19
|
A powerful command-line interface for managing your Myop projects.
|
|
@@ -44,7 +47,7 @@ Examples:
|
|
|
44
47
|
|
|
45
48
|
|
|
46
49
|
|
|
47
|
-
`,
|
|
50
|
+
`, h = {
|
|
48
51
|
program: null,
|
|
49
52
|
executionPath: "",
|
|
50
53
|
options: {
|
|
@@ -52,89 +55,89 @@ Examples:
|
|
|
52
55
|
verbose: !1
|
|
53
56
|
},
|
|
54
57
|
myopConfig: null
|
|
55
|
-
},
|
|
58
|
+
}, Ve = {
|
|
56
59
|
name: "📥 Install Myop generated dependencies",
|
|
57
60
|
value: "myopInstall",
|
|
58
61
|
description: "Fetch and generates Myop dependencies. flows including components, refs and props.",
|
|
59
62
|
action: async () => {
|
|
60
63
|
console.info("installing... ");
|
|
61
|
-
for (const
|
|
62
|
-
const
|
|
63
|
-
console.info(`Generate flow at ${
|
|
64
|
+
for (const o of h.myopConfig.flows) {
|
|
65
|
+
const e = ee.join(h.executionPath, "/node_modules/@myop/flow-types/");
|
|
66
|
+
console.info(`Generate flow at ${e}`), console.info(`Generated flow at ${e}`);
|
|
64
67
|
}
|
|
65
68
|
process.exit();
|
|
66
69
|
}
|
|
67
|
-
},
|
|
68
|
-
const
|
|
69
|
-
console.info(`reading config file from: ${
|
|
70
|
-
const
|
|
71
|
-
return console.info("config file loaded, ",
|
|
72
|
-
},
|
|
73
|
-
const
|
|
74
|
-
console.info(`writing config file to: ${
|
|
70
|
+
}, gt = (o) => {
|
|
71
|
+
const e = ee.join(h.executionPath, o);
|
|
72
|
+
console.info(`reading config file from: ${e}`);
|
|
73
|
+
const t = H.readFileSync(e, "utf8"), n = JSON.parse(t);
|
|
74
|
+
return console.info("config file loaded, ", n), n;
|
|
75
|
+
}, Oe = (o, e) => {
|
|
76
|
+
const t = ee.join(h.executionPath, o);
|
|
77
|
+
console.info(`writing config file to: ${t}`);
|
|
75
78
|
try {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
} catch (
|
|
79
|
-
throw console.info(`error ${
|
|
80
|
-
⚠️ Failed write config file to ${
|
|
79
|
+
const n = JSON.stringify(e, null, 2);
|
|
80
|
+
H.writeFileSync(t, n), console.info(`config file updated ${n}`);
|
|
81
|
+
} catch (n) {
|
|
82
|
+
throw console.info(`error ${n} while writing to ${t}, JSON: ${e}`), console.log(`
|
|
83
|
+
⚠️ Failed write config file to ${t}, for more info use verbose flag`), n;
|
|
81
84
|
}
|
|
82
|
-
},
|
|
85
|
+
}, Ge = {
|
|
83
86
|
name: "🌟 Add flow definition to your project",
|
|
84
87
|
value: "addFlow",
|
|
85
88
|
description: "Adds flow to yours myop.config.json",
|
|
86
|
-
_action: (
|
|
87
|
-
|
|
89
|
+
_action: (o) => {
|
|
90
|
+
h.myopConfig.flows.includes(o) || h.myopConfig.flows.push(o), Oe(h.options.configPath, h.myopConfig);
|
|
88
91
|
},
|
|
89
92
|
action: async () => {
|
|
90
93
|
}
|
|
91
|
-
},
|
|
94
|
+
}, Ye = {
|
|
92
95
|
name: "🚫 Remove flow definition from your project",
|
|
93
96
|
value: "removeFlow",
|
|
94
97
|
description: "Removes flow to yours myop.config.json",
|
|
95
|
-
_action: (
|
|
96
|
-
|
|
98
|
+
_action: (o) => {
|
|
99
|
+
h.myopConfig.flows = h.myopConfig.flows.filter((e) => e !== o), Oe(h.options.configPath, h.myopConfig);
|
|
97
100
|
},
|
|
98
101
|
action: () => {
|
|
99
102
|
}
|
|
100
|
-
},
|
|
103
|
+
}, ft = {
|
|
101
104
|
name: "👋 Quit",
|
|
102
105
|
value: "quit",
|
|
103
106
|
description: "Quit and continue coding.",
|
|
104
107
|
action: () => {
|
|
105
108
|
process.exit();
|
|
106
109
|
}
|
|
107
|
-
},
|
|
110
|
+
}, ht = {
|
|
108
111
|
name: "🟢 Create new component",
|
|
109
112
|
value: "-",
|
|
110
113
|
disabled: "(not available yet)"
|
|
111
|
-
},
|
|
114
|
+
}, yt = {
|
|
112
115
|
name: "🔵 Create new experience",
|
|
113
116
|
value: "-",
|
|
114
117
|
disabled: "(not available yet)"
|
|
115
|
-
},
|
|
118
|
+
}, wt = {
|
|
116
119
|
name: "🟡 Create new skin",
|
|
117
120
|
value: "-",
|
|
118
121
|
disabled: "(not available yet)"
|
|
119
|
-
},
|
|
122
|
+
}, vt = {
|
|
120
123
|
name: "🔴 Create new flow",
|
|
121
124
|
value: "-",
|
|
122
125
|
disabled: "(not available yet)"
|
|
123
|
-
},
|
|
126
|
+
}, bt = {
|
|
124
127
|
name: "🆕 Define new custom Myop message",
|
|
125
128
|
value: "generateMyopMessage",
|
|
126
129
|
description: "️Help you creates the right structure for a new Myop message, including types and handlers.",
|
|
127
130
|
disabled: "(not available yet)"
|
|
128
|
-
},
|
|
129
|
-
function
|
|
131
|
+
}, St = [bt, ht, yt, wt, vt];
|
|
132
|
+
function xt(o, e, t, n) {
|
|
130
133
|
return `<!DOCTYPE html>
|
|
131
134
|
<html lang="en">
|
|
132
135
|
<head>
|
|
133
136
|
<meta charset="UTF-8">
|
|
134
137
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
135
|
-
<title>Myop DevTools - localhost:${
|
|
138
|
+
<title>Myop DevTools - localhost:${o}</title>
|
|
136
139
|
<style>
|
|
137
|
-
${
|
|
140
|
+
${t}
|
|
138
141
|
</style>
|
|
139
142
|
</head>
|
|
140
143
|
<body>
|
|
@@ -142,8 +145,8 @@ ${s}
|
|
|
142
145
|
<div class="toolbar">
|
|
143
146
|
<div class="toolbar-title">Myop DevTools</div>
|
|
144
147
|
<div class="toolbar-info">
|
|
145
|
-
<span><div class="status-dot"></div> localhost:${
|
|
146
|
-
<span>Management: ${
|
|
148
|
+
<span><div class="status-dot"></div> localhost:${o}</span>
|
|
149
|
+
<span>Management: ${e}</span>
|
|
147
150
|
</div>
|
|
148
151
|
</div>
|
|
149
152
|
|
|
@@ -209,74 +212,144 @@ ${s}
|
|
|
209
212
|
|
|
210
213
|
<script>
|
|
211
214
|
// Inject PORT as a global variable for the app to use
|
|
212
|
-
window.PORT = ${
|
|
215
|
+
window.PORT = ${o};
|
|
213
216
|
|
|
214
|
-
${
|
|
217
|
+
${n}
|
|
215
218
|
<\/script>
|
|
216
219
|
</body>
|
|
217
220
|
</html>`;
|
|
218
221
|
}
|
|
222
|
+
function $t(o) {
|
|
223
|
+
return o.includes("esbuild") && o.includes("another platform");
|
|
224
|
+
}
|
|
225
|
+
function Ct(o) {
|
|
226
|
+
return o.includes("ERR_MODULE_NOT_FOUND") && o.includes("esbuild");
|
|
227
|
+
}
|
|
228
|
+
function Mt() {
|
|
229
|
+
console.error(`
|
|
230
|
+
❌ esbuild platform mismatch detected!`), console.error(" Your node_modules contains esbuild binaries for a different OS."), console.error(`
|
|
231
|
+
This usually happens when node_modules is copied between different`), console.error(` operating systems (e.g., Windows → Mac, or Mac → Linux).
|
|
232
|
+
`);
|
|
233
|
+
}
|
|
234
|
+
function Pt(o) {
|
|
235
|
+
return new Promise((e) => {
|
|
236
|
+
console.log(`🔧 Attempting to fix: removing node_modules and reinstalling...
|
|
237
|
+
`);
|
|
238
|
+
const n = process.platform === "win32" ? "rmdir /s /q node_modules" : "rm -rf node_modules";
|
|
239
|
+
o(n, (i) => {
|
|
240
|
+
if (i) {
|
|
241
|
+
console.error("❌ Failed to remove node_modules:", i.message), console.error(`
|
|
242
|
+
Please run manually:`), console.error(` \x1B[36m${n} && npm install\x1B[0m
|
|
243
|
+
`), e(!1);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
console.log(" ✓ Removed node_modules"), console.log(` ⏳ Running npm install...
|
|
247
|
+
`), o("npm install", { maxBuffer: 10 * 1024 * 1024 }, (s, d, w) => {
|
|
248
|
+
if (s) {
|
|
249
|
+
console.error("❌ npm install failed:", s.message), w && console.error(w), e(!1);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
console.log(` ✓ Dependencies reinstalled successfully!
|
|
253
|
+
`), e(!0);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
async function Ke(o, e, t, n, i = {}) {
|
|
259
|
+
const {
|
|
260
|
+
hasTriedPlatformFix: s = !1,
|
|
261
|
+
hasTriedInstall: d = !1,
|
|
262
|
+
onRetry: w
|
|
263
|
+
} = i, M = ((o == null ? void 0 : o.message) || "") + (e || "") + (t || "");
|
|
264
|
+
return !s && $t(M) ? (Mt(), await Pt(n) && w ? (console.log(`🔄 Retrying build...
|
|
265
|
+
`), w(), { handled: !0, hasTriedPlatformFix: !0, hasTriedInstall: d }) : { handled: !0, hasTriedPlatformFix: !0, hasTriedInstall: d }) : !d && Ct(M) ? (console.log("📦 Missing dependencies detected, running npm install..."), new Promise((m) => {
|
|
266
|
+
n("npm install", (p, b, u) => {
|
|
267
|
+
if (p) {
|
|
268
|
+
console.error("❌ Failed to install dependencies:", p.message), u && console.error(u), m({ handled: !0, hasTriedPlatformFix: s, hasTriedInstall: !0 });
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
console.log("✅ Dependencies installed"), w && w(), m({ handled: !0, hasTriedPlatformFix: s, hasTriedInstall: !0 });
|
|
272
|
+
});
|
|
273
|
+
})) : { handled: !1, hasTriedPlatformFix: s, hasTriedInstall: d };
|
|
274
|
+
}
|
|
219
275
|
async function Fe() {
|
|
220
|
-
const
|
|
221
|
-
let
|
|
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
|
+
let s;
|
|
222
278
|
if (import.meta.url.startsWith("file://")) {
|
|
223
|
-
const
|
|
224
|
-
|
|
279
|
+
const a = new URL(import.meta.url).pathname, l = process.platform === "win32" && a.startsWith("/") ? a.slice(1) : a;
|
|
280
|
+
s = e.default.dirname(l);
|
|
225
281
|
} else
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
let
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
282
|
+
s = e.default.dirname(import.meta.url);
|
|
283
|
+
const d = e.default.join(s, "commands", "dev", "management-website"), w = o.default.readFileSync(e.default.join(d, "styles.css"), "utf-8"), M = o.default.readFileSync(e.default.join(d, "app.js"), "utf-8"), m = 9292, p = 9293;
|
|
284
|
+
let b = "./dist", u = !1, v = !1, x = !1, $ = null;
|
|
285
|
+
const _ = () => {
|
|
286
|
+
try {
|
|
287
|
+
const r = o.default.readdirSync(".").filter((a) => !a.endsWith(".html") || a.startsWith(".") ? !1 : o.default.statSync(a).isFile());
|
|
288
|
+
if (r.length === 1)
|
|
289
|
+
return r[0];
|
|
290
|
+
} catch {
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}, D = () => {
|
|
294
|
+
try {
|
|
295
|
+
const r = JSON.parse(o.default.readFileSync("package.json", "utf-8"));
|
|
296
|
+
return !!(r.scripts && r.scripts.build);
|
|
297
|
+
} catch {
|
|
298
|
+
return !1;
|
|
299
|
+
}
|
|
300
|
+
}, g = (r) => {
|
|
301
|
+
const a = process.platform;
|
|
302
|
+
let l;
|
|
303
|
+
a === "darwin" ? l = `open "${r}"` : a === "win32" ? l = `start "" "${r}"` : l = `xdg-open "${r}"`, t(l, (c) => {
|
|
233
304
|
});
|
|
234
|
-
},
|
|
235
|
-
let
|
|
305
|
+
}, P = /* @__PURE__ */ new Map(), E = h.program.getOptionValue("config") || "./myop.config.json";
|
|
306
|
+
let C, I, L = !1;
|
|
307
|
+
$ = _();
|
|
308
|
+
const Z = D();
|
|
236
309
|
try {
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
} catch (
|
|
240
|
-
console.error("❌ Error reading myop.config.json:",
|
|
310
|
+
const r = o.default.readFileSync(E, "utf-8"), a = JSON.parse(r);
|
|
311
|
+
C = a.componentId || "DEV", I = a.componentName || a.name || null, L = a.HMR === !0, $ && !Z && (x = !0, L = !0, console.log(`📄 Single HTML file mode: ${$}`)), L && console.log("🔥 HMR enabled");
|
|
312
|
+
} catch (r) {
|
|
313
|
+
$ && !Z ? (x = !0, C = "DEV", I = e.default.basename($, ".html"), L = !0, console.log(`📄 Single HTML file mode: ${$}`), console.log("🔥 HMR enabled")) : (console.error("❌ Error reading myop.config.json:", r.message), process.exit(1));
|
|
241
314
|
}
|
|
242
|
-
const
|
|
243
|
-
if (
|
|
244
|
-
return
|
|
315
|
+
const U = async () => {
|
|
316
|
+
if (C !== "DEV" && C !== "NEW")
|
|
317
|
+
return C;
|
|
245
318
|
try {
|
|
246
|
-
const
|
|
247
|
-
const
|
|
319
|
+
const a = ((await new Promise((f, y) => {
|
|
320
|
+
const S = {
|
|
248
321
|
hostname: "localhost",
|
|
249
|
-
port:
|
|
322
|
+
port: p,
|
|
250
323
|
path: "/_list",
|
|
251
324
|
method: "GET",
|
|
252
325
|
timeout: 1e3
|
|
253
|
-
},
|
|
254
|
-
let
|
|
255
|
-
N.on("data", (
|
|
326
|
+
}, F = n.default.request(S, (N) => {
|
|
327
|
+
let J = "";
|
|
328
|
+
N.on("data", (Q) => J += Q), N.on("end", () => {
|
|
256
329
|
try {
|
|
257
|
-
|
|
330
|
+
f(JSON.parse(J));
|
|
258
331
|
} catch {
|
|
259
|
-
|
|
332
|
+
f({ components: [] });
|
|
260
333
|
}
|
|
261
334
|
});
|
|
262
335
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}),
|
|
266
|
-
})).components || []).map(([
|
|
267
|
-
if (
|
|
336
|
+
F.on("error", () => f({ components: [] })), F.on("timeout", () => {
|
|
337
|
+
F.destroy(), f({ components: [] });
|
|
338
|
+
}), F.end();
|
|
339
|
+
})).components || []).map(([f]) => f).filter((f) => f === "DEV" || f === "NEW" || /^DEV\d+$/.test(f) || /^NEW\d+$/.test(f));
|
|
340
|
+
if (a.length === 0)
|
|
268
341
|
return "DEV1";
|
|
269
|
-
const
|
|
270
|
-
if (
|
|
271
|
-
const
|
|
272
|
-
return
|
|
273
|
-
}).filter((
|
|
274
|
-
return `DEV${Math.max(...
|
|
342
|
+
const l = a.map((f) => {
|
|
343
|
+
if (f === "DEV" || f === "NEW") return 1;
|
|
344
|
+
const y = f.match(/^DEV(\d+)$/), S = f.match(/^NEW(\d+)$/);
|
|
345
|
+
return y ? parseInt(y[1], 10) : S ? parseInt(S[1], 10) : 0;
|
|
346
|
+
}).filter((f) => f > 0);
|
|
347
|
+
return `DEV${Math.max(...l, 0) + 1}`;
|
|
275
348
|
} catch {
|
|
276
349
|
return "DEV1";
|
|
277
350
|
}
|
|
278
|
-
},
|
|
279
|
-
const
|
|
351
|
+
}, O = process.cwd(), V = (r) => {
|
|
352
|
+
const a = e.default.extname(r).toLowerCase();
|
|
280
353
|
return {
|
|
281
354
|
".html": "text/html",
|
|
282
355
|
".js": "text/javascript",
|
|
@@ -287,305 +360,306 @@ async function Fe() {
|
|
|
287
360
|
".gif": "image/gif",
|
|
288
361
|
".svg": "image/svg+xml",
|
|
289
362
|
".ico": "image/x-icon"
|
|
290
|
-
}[
|
|
291
|
-
},
|
|
292
|
-
if (
|
|
293
|
-
const
|
|
294
|
-
|
|
363
|
+
}[a] || "application/octet-stream";
|
|
364
|
+
}, R = /* @__PURE__ */ new Map(), G = [], Se = 50, K = [], te = /* @__PURE__ */ new Map(), X = /* @__PURE__ */ new Map(), et = (r, a, l) => {
|
|
365
|
+
if (r.url.startsWith("/_hmr/")) {
|
|
366
|
+
const c = r.url.split("/_hmr/")[1], f = r.headers["sec-websocket-key"], y = i("sha1").update(f + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
|
|
367
|
+
a.write(
|
|
295
368
|
`HTTP/1.1 101 Switching Protocols\r
|
|
296
369
|
Upgrade: websocket\r
|
|
297
370
|
Connection: Upgrade\r
|
|
298
|
-
Sec-WebSocket-Accept: ${
|
|
371
|
+
Sec-WebSocket-Accept: ${y}\r
|
|
299
372
|
\r
|
|
300
373
|
`
|
|
301
|
-
),
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
}),
|
|
305
|
-
const
|
|
306
|
-
|
|
374
|
+
), X.has(c) || X.set(c, /* @__PURE__ */ new Set()), X.get(c).add(a), console.log(`🔌 HMR client connected: ${c}`), a.on("close", () => {
|
|
375
|
+
const S = X.get(c);
|
|
376
|
+
S && (S.delete(a), S.size === 0 && X.delete(c)), console.log(`🔌 HMR client disconnected: ${c}`);
|
|
377
|
+
}), a.on("error", () => {
|
|
378
|
+
const S = X.get(c);
|
|
379
|
+
S && S.delete(a);
|
|
307
380
|
});
|
|
308
381
|
}
|
|
309
|
-
},
|
|
310
|
-
if (
|
|
311
|
-
let
|
|
312
|
-
|
|
382
|
+
}, xe = n.default.createServer((r, a) => {
|
|
383
|
+
if (a.setHeader("Content-Type", "application/json"), r.method === "POST" && r.url === "/_register") {
|
|
384
|
+
let l = "";
|
|
385
|
+
r.on("data", (c) => l += c), r.on("end", () => {
|
|
313
386
|
try {
|
|
314
|
-
const { componentId:
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
console.log(`✅ Registered: ${
|
|
318
|
-
const
|
|
319
|
-
id:
|
|
320
|
-
path:
|
|
321
|
-
name:
|
|
387
|
+
const { componentId: c, distPath: f, componentName: y, htmlFile: S } = JSON.parse(l);
|
|
388
|
+
R.set(c, { path: f, name: y || null, htmlFile: S || null });
|
|
389
|
+
const F = y ? ` (${y})` : "";
|
|
390
|
+
console.log(`✅ Registered: ${c}${F} -> ${f}${S ? "/" + S : ""}`), a.writeHead(200), a.end(JSON.stringify({ success: !0, registered: Array.from(R.keys()) }));
|
|
391
|
+
const N = Array.from(R.entries()).map(([J, Q]) => ({
|
|
392
|
+
id: J,
|
|
393
|
+
path: Q.path,
|
|
394
|
+
name: Q.name
|
|
322
395
|
}));
|
|
323
|
-
|
|
396
|
+
K.forEach((J) => {
|
|
324
397
|
try {
|
|
325
|
-
|
|
398
|
+
J.write(`data: ${JSON.stringify({
|
|
326
399
|
type: "components",
|
|
327
|
-
components:
|
|
400
|
+
components: N
|
|
328
401
|
})}
|
|
329
402
|
|
|
330
403
|
`);
|
|
331
404
|
} catch {
|
|
332
405
|
}
|
|
333
406
|
});
|
|
334
|
-
} catch (
|
|
335
|
-
|
|
407
|
+
} catch (c) {
|
|
408
|
+
a.writeHead(400), a.end(JSON.stringify({ error: c.message }));
|
|
336
409
|
}
|
|
337
410
|
});
|
|
338
|
-
} else if (
|
|
339
|
-
let
|
|
340
|
-
|
|
411
|
+
} else if (r.method === "POST" && r.url === "/_unregister") {
|
|
412
|
+
let l = "";
|
|
413
|
+
r.on("data", (c) => l += c), r.on("end", () => {
|
|
341
414
|
try {
|
|
342
|
-
const { componentId:
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
id:
|
|
346
|
-
path:
|
|
347
|
-
name:
|
|
415
|
+
const { componentId: c } = JSON.parse(l);
|
|
416
|
+
R.delete(c), console.log(`❌ Unregistered: ${c}`), a.writeHead(200), a.end(JSON.stringify({ success: !0 }));
|
|
417
|
+
const f = Array.from(R.entries()).map(([y, S]) => ({
|
|
418
|
+
id: y,
|
|
419
|
+
path: S.path,
|
|
420
|
+
name: S.name
|
|
348
421
|
}));
|
|
349
|
-
|
|
422
|
+
K.forEach((y) => {
|
|
350
423
|
try {
|
|
351
|
-
|
|
424
|
+
y.write(`data: ${JSON.stringify({
|
|
352
425
|
type: "components",
|
|
353
|
-
components:
|
|
426
|
+
components: f
|
|
354
427
|
})}
|
|
355
428
|
|
|
356
429
|
`);
|
|
357
430
|
} catch {
|
|
358
431
|
}
|
|
359
432
|
});
|
|
360
|
-
} catch (
|
|
361
|
-
|
|
433
|
+
} catch (c) {
|
|
434
|
+
a.writeHead(400), a.end(JSON.stringify({ error: c.message }));
|
|
362
435
|
}
|
|
363
436
|
});
|
|
364
|
-
} else
|
|
365
|
-
}),
|
|
366
|
-
if (
|
|
367
|
-
|
|
437
|
+
} else r.method === "GET" && r.url === "/_list" ? (a.writeHead(200), a.end(JSON.stringify({ components: Array.from(R.entries()) }))) : (a.writeHead(404), a.end(JSON.stringify({ error: "Not found" })));
|
|
438
|
+
}), ce = n.default.createServer((r, a) => {
|
|
439
|
+
if (r.url.includes("..")) {
|
|
440
|
+
a.writeHead(403, { "Content-Type": "text/plain" }), a.end("Forbidden");
|
|
368
441
|
return;
|
|
369
442
|
}
|
|
370
|
-
const
|
|
371
|
-
if (
|
|
372
|
-
const
|
|
373
|
-
if (!
|
|
374
|
-
|
|
443
|
+
const l = new URL(r.url, `http://localhost:${m}`), c = l.pathname, f = c.split("/").filter((A) => A);
|
|
444
|
+
if (c.startsWith("/consume")) {
|
|
445
|
+
const A = l.searchParams.get("id");
|
|
446
|
+
if (!A) {
|
|
447
|
+
a.writeHead(400, { "Content-Type": "application/json" }), a.end(JSON.stringify({ error: "Component ID required. Use /consume?id=<componentId>" }));
|
|
375
448
|
return;
|
|
376
449
|
}
|
|
377
|
-
const
|
|
378
|
-
let
|
|
379
|
-
if (
|
|
380
|
-
const
|
|
450
|
+
const B = R.get(A), Y = B ? B.path : null, Be = (oe) => {
|
|
451
|
+
let j = "Unknown", z = "Unknown";
|
|
452
|
+
if (r.headers.referer || r.headers.referrer) {
|
|
453
|
+
const k = r.headers.referer || r.headers.referrer;
|
|
381
454
|
try {
|
|
382
|
-
const
|
|
383
|
-
|
|
455
|
+
const ne = new URL(k);
|
|
456
|
+
j = ne.origin, z = ne.hostname || ne.origin;
|
|
384
457
|
} catch {
|
|
385
|
-
|
|
458
|
+
j = k, z = k;
|
|
386
459
|
}
|
|
387
|
-
} else if (
|
|
460
|
+
} else if (r.headers.origin)
|
|
388
461
|
try {
|
|
389
|
-
const
|
|
390
|
-
|
|
462
|
+
const k = new URL(r.headers.origin);
|
|
463
|
+
j = k.origin, z = k.hostname || k.origin;
|
|
391
464
|
} catch {
|
|
392
|
-
|
|
465
|
+
j = r.headers.origin, z = r.headers.origin;
|
|
393
466
|
}
|
|
394
|
-
else if (
|
|
395
|
-
const
|
|
396
|
-
|
|
467
|
+
else if (r.socket.remoteAddress) {
|
|
468
|
+
const k = r.socket.remoteAddress;
|
|
469
|
+
k === "::1" || k === "::ffff:127.0.0.1" ? (j = "localhost", z = "localhost (direct)") : (j = k, z = k.replace("::ffff:", ""));
|
|
397
470
|
}
|
|
398
|
-
const
|
|
471
|
+
const Me = r.headers.referer || r.headers.referrer || j, me = {
|
|
399
472
|
type: "request",
|
|
400
|
-
componentId:
|
|
473
|
+
componentId: A,
|
|
401
474
|
timestamp: Date.now(),
|
|
402
|
-
servedLocally:
|
|
403
|
-
referrer:
|
|
404
|
-
origin:
|
|
405
|
-
originLabel:
|
|
475
|
+
servedLocally: oe,
|
|
476
|
+
referrer: Me,
|
|
477
|
+
origin: j,
|
|
478
|
+
originLabel: z
|
|
406
479
|
};
|
|
407
|
-
|
|
408
|
-
url:
|
|
409
|
-
label:
|
|
480
|
+
te.has(j) || (te.set(j, {
|
|
481
|
+
url: j,
|
|
482
|
+
label: z,
|
|
410
483
|
firstSeen: Date.now(),
|
|
411
484
|
requestCount: 0
|
|
412
|
-
}),
|
|
485
|
+
}), K.forEach((k) => {
|
|
413
486
|
try {
|
|
414
|
-
|
|
487
|
+
k.write(`data: ${JSON.stringify({
|
|
415
488
|
type: "origins",
|
|
416
|
-
origins: Array.from(
|
|
489
|
+
origins: Array.from(te.values())
|
|
417
490
|
})}
|
|
418
491
|
|
|
419
492
|
`);
|
|
420
493
|
} catch {
|
|
421
494
|
}
|
|
422
495
|
}));
|
|
423
|
-
const
|
|
424
|
-
|
|
496
|
+
const Pe = te.get(j);
|
|
497
|
+
Pe.requestCount++, K.forEach((k) => {
|
|
425
498
|
try {
|
|
426
|
-
|
|
499
|
+
k.write(`data: ${JSON.stringify({
|
|
427
500
|
type: "origins",
|
|
428
|
-
origins: Array.from(
|
|
501
|
+
origins: Array.from(te.values())
|
|
429
502
|
})}
|
|
430
503
|
|
|
431
504
|
`);
|
|
432
505
|
} catch {
|
|
433
506
|
}
|
|
434
|
-
}),
|
|
507
|
+
}), G.push(me), G.length > Se && G.shift(), K.forEach((k) => {
|
|
435
508
|
try {
|
|
436
|
-
|
|
509
|
+
k.write(`data: ${JSON.stringify(me)}
|
|
437
510
|
|
|
438
511
|
`);
|
|
439
512
|
} catch {
|
|
440
513
|
}
|
|
441
514
|
});
|
|
442
515
|
};
|
|
443
|
-
if (
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
if (
|
|
447
|
-
console.log(`❌ File not found: ${
|
|
516
|
+
if (Y) {
|
|
517
|
+
const oe = B.htmlFile ? e.default.join(Y, B.htmlFile) : e.default.join(Y, "index.html");
|
|
518
|
+
o.default.readFile(oe, "utf-8", (j, z) => {
|
|
519
|
+
if (j) {
|
|
520
|
+
console.log(`❌ File not found: ${oe}`), a.writeHead(404, { "Content-Type": "application/json" }), a.end(JSON.stringify({ error: "index.html not found" }));
|
|
448
521
|
return;
|
|
449
522
|
}
|
|
450
|
-
const
|
|
523
|
+
const Me = _e(z, A), me = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, Pe = {
|
|
451
524
|
item: {
|
|
452
|
-
name:
|
|
453
|
-
id:
|
|
525
|
+
name: A,
|
|
526
|
+
id: A,
|
|
454
527
|
consume_variant: [
|
|
455
528
|
{
|
|
456
|
-
id:
|
|
529
|
+
id: me,
|
|
457
530
|
name: "dev version",
|
|
458
531
|
loader: {
|
|
459
532
|
type: "HTMLLoader",
|
|
460
533
|
shadowRootMode: "localFrame",
|
|
461
|
-
HTML:
|
|
534
|
+
HTML: Me
|
|
462
535
|
}
|
|
463
536
|
}
|
|
464
537
|
]
|
|
465
538
|
}
|
|
466
539
|
};
|
|
467
|
-
console.log(`✅ Serving consume JSON for: ${
|
|
540
|
+
console.log(`✅ Serving consume JSON for: ${A}`), Be(!0), a.writeHead(200, {
|
|
468
541
|
"Content-Type": "application/json",
|
|
469
542
|
"Access-Control-Allow-Origin": "*"
|
|
470
|
-
}),
|
|
543
|
+
}), a.end(JSON.stringify(Pe, null, 2));
|
|
471
544
|
});
|
|
472
545
|
} else {
|
|
473
|
-
console.log(`📡 Proxying consume request to cloud.myop.dev for: ${
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
546
|
+
console.log(`📡 Proxying consume request to cloud.myop.dev for: ${A}`);
|
|
547
|
+
const oe = `https://cloud.myop.dev/consume${l.search}`;
|
|
548
|
+
Be(!1), fetch(oe).then((j) => j.text()).then((j) => {
|
|
549
|
+
a.writeHead(200, {
|
|
477
550
|
"Content-Type": "application/json",
|
|
478
551
|
"Access-Control-Allow-Origin": "*"
|
|
479
|
-
}),
|
|
480
|
-
}).catch((
|
|
481
|
-
console.error(`❌ Proxy error: ${
|
|
552
|
+
}), a.end(j);
|
|
553
|
+
}).catch((j) => {
|
|
554
|
+
console.error(`❌ Proxy error: ${j.message}`), a.writeHead(502, { "Content-Type": "application/json" }), a.end(JSON.stringify({ error: "Failed to fetch from cloud.myop.dev" }));
|
|
482
555
|
});
|
|
483
556
|
}
|
|
484
557
|
return;
|
|
485
558
|
}
|
|
486
|
-
if (
|
|
487
|
-
|
|
559
|
+
if (c === "/events") {
|
|
560
|
+
a.writeHead(200, {
|
|
488
561
|
"Content-Type": "text/event-stream",
|
|
489
562
|
"Cache-Control": "no-cache",
|
|
490
563
|
Connection: "keep-alive",
|
|
491
564
|
"Access-Control-Allow-Origin": "*"
|
|
492
|
-
}),
|
|
493
|
-
const
|
|
494
|
-
id:
|
|
495
|
-
path:
|
|
496
|
-
name:
|
|
565
|
+
}), K.push(a);
|
|
566
|
+
const A = Array.from(R.entries()).map(([B, Y]) => ({
|
|
567
|
+
id: B,
|
|
568
|
+
path: Y.path,
|
|
569
|
+
name: Y.name
|
|
497
570
|
}));
|
|
498
|
-
|
|
571
|
+
a.write(`data: ${JSON.stringify({
|
|
499
572
|
type: "components",
|
|
500
|
-
components:
|
|
573
|
+
components: A
|
|
501
574
|
})}
|
|
502
575
|
|
|
503
|
-
`),
|
|
576
|
+
`), a.write(`data: ${JSON.stringify({
|
|
504
577
|
type: "origins",
|
|
505
|
-
origins: Array.from(
|
|
578
|
+
origins: Array.from(te.values())
|
|
506
579
|
})}
|
|
507
580
|
|
|
508
|
-
`),
|
|
581
|
+
`), a.write(`data: ${JSON.stringify({
|
|
509
582
|
type: "requestLog",
|
|
510
|
-
log:
|
|
583
|
+
log: G
|
|
511
584
|
})}
|
|
512
585
|
|
|
513
|
-
`),
|
|
514
|
-
const
|
|
515
|
-
|
|
586
|
+
`), r.on("close", () => {
|
|
587
|
+
const B = K.indexOf(a);
|
|
588
|
+
B !== -1 && K.splice(B, 1);
|
|
516
589
|
});
|
|
517
590
|
return;
|
|
518
591
|
}
|
|
519
|
-
if (
|
|
520
|
-
|
|
592
|
+
if (f.length === 0) {
|
|
593
|
+
a.writeHead(200, { "Content-Type": "text/html" }), a.end(xt(m, p, w, M));
|
|
521
594
|
return;
|
|
522
595
|
}
|
|
523
|
-
if (
|
|
524
|
-
|
|
596
|
+
if (f[0] !== "view") {
|
|
597
|
+
a.writeHead(404, { "Content-Type": "text/plain" }), a.end("Not found. Use /view/<componentId>/ to access components.");
|
|
525
598
|
return;
|
|
526
599
|
}
|
|
527
|
-
if (
|
|
528
|
-
|
|
600
|
+
if (f.length < 2) {
|
|
601
|
+
a.writeHead(400, { "Content-Type": "text/plain" }), a.end("Component ID required. Use /view/<componentId>/");
|
|
529
602
|
return;
|
|
530
603
|
}
|
|
531
|
-
const
|
|
532
|
-
if (!
|
|
533
|
-
|
|
604
|
+
const y = f[1], S = R.get(y);
|
|
605
|
+
if (!S) {
|
|
606
|
+
a.writeHead(404, { "Content-Type": "text/plain" }), a.end(`Component not found: ${y}`);
|
|
534
607
|
return;
|
|
535
608
|
}
|
|
536
|
-
const
|
|
537
|
-
console.log(`📥 Request: ${
|
|
538
|
-
if (
|
|
539
|
-
console.log(`❌ File not found: ${
|
|
609
|
+
const F = S.path, N = f.slice(2), J = S.htmlFile || "index.html", Q = N.length === 0 ? J : N.join("/"), ie = e.default.join(F, Q);
|
|
610
|
+
console.log(`📥 Request: ${r.url} -> ${ie}`), o.default.readFile(ie, (A, B) => {
|
|
611
|
+
if (A) {
|
|
612
|
+
console.log(`❌ File not found: ${ie}`), a.writeHead(404, { "Content-Type": "text/plain" }), a.end("Not Found");
|
|
540
613
|
return;
|
|
541
614
|
}
|
|
542
|
-
const
|
|
543
|
-
console.log(`✅ Serving: ${
|
|
544
|
-
"Content-Type":
|
|
615
|
+
const Y = V(ie);
|
|
616
|
+
console.log(`✅ Serving: ${ie} (${Y})`), a.writeHead(200, {
|
|
617
|
+
"Content-Type": Y,
|
|
545
618
|
"Access-Control-Allow-Origin": "*"
|
|
546
|
-
}),
|
|
619
|
+
}), a.end(B);
|
|
547
620
|
});
|
|
548
|
-
}),
|
|
549
|
-
const
|
|
550
|
-
componentId:
|
|
551
|
-
distPath:
|
|
552
|
-
componentName:
|
|
553
|
-
|
|
621
|
+
}), Ne = () => new Promise((r, a) => {
|
|
622
|
+
const l = x ? e.default.resolve(O) : e.default.resolve(O, b), c = JSON.stringify({
|
|
623
|
+
componentId: C,
|
|
624
|
+
distPath: l,
|
|
625
|
+
componentName: I,
|
|
626
|
+
htmlFile: x ? $ : null
|
|
627
|
+
}), f = {
|
|
554
628
|
hostname: "localhost",
|
|
555
|
-
port:
|
|
629
|
+
port: p,
|
|
556
630
|
path: "/_register",
|
|
557
631
|
method: "POST",
|
|
558
632
|
headers: {
|
|
559
633
|
"Content-Type": "application/json",
|
|
560
|
-
"Content-Length": Buffer.byteLength(
|
|
634
|
+
"Content-Length": Buffer.byteLength(c)
|
|
561
635
|
}
|
|
562
|
-
},
|
|
563
|
-
let
|
|
564
|
-
|
|
565
|
-
|
|
636
|
+
}, y = n.default.request(f, (S) => {
|
|
637
|
+
let F = "";
|
|
638
|
+
S.on("data", (N) => F += N), S.on("end", () => {
|
|
639
|
+
S.statusCode === 200 ? r(JSON.parse(F)) : a(new Error(`Registration failed: ${S.statusCode}`));
|
|
566
640
|
});
|
|
567
641
|
});
|
|
568
|
-
|
|
569
|
-
}),
|
|
570
|
-
const
|
|
642
|
+
y.on("error", a), y.write(c), y.end();
|
|
643
|
+
}), tt = () => new Promise((r, a) => {
|
|
644
|
+
const l = JSON.stringify({ componentId: C }), c = {
|
|
571
645
|
hostname: "localhost",
|
|
572
|
-
port:
|
|
646
|
+
port: p,
|
|
573
647
|
path: "/_unregister",
|
|
574
648
|
method: "POST",
|
|
575
649
|
headers: {
|
|
576
650
|
"Content-Type": "application/json",
|
|
577
|
-
"Content-Length": Buffer.byteLength(
|
|
651
|
+
"Content-Length": Buffer.byteLength(l)
|
|
578
652
|
}
|
|
579
|
-
},
|
|
580
|
-
|
|
653
|
+
}, f = n.default.request(c, (y) => {
|
|
654
|
+
r();
|
|
581
655
|
});
|
|
582
|
-
|
|
583
|
-
}),
|
|
656
|
+
f.on("error", () => r()), f.write(l), f.end();
|
|
657
|
+
}), ot = (r) => `
|
|
584
658
|
<!-- MYOP HMR -->
|
|
585
659
|
<script>
|
|
586
660
|
(function() {
|
|
587
|
-
const componentId = '${
|
|
588
|
-
const wsUrl = 'ws://localhost:${
|
|
661
|
+
const componentId = '${r}';
|
|
662
|
+
const wsUrl = 'ws://localhost:${p}/_hmr/' + componentId;
|
|
589
663
|
let ws;
|
|
590
664
|
let reconnectAttempts = 0;
|
|
591
665
|
const maxReconnectAttempts = 10;
|
|
@@ -685,281 +759,536 @@ Sec-WebSocket-Accept: ${p}\r
|
|
|
685
759
|
connect();
|
|
686
760
|
})();
|
|
687
761
|
<\/script>
|
|
688
|
-
`,
|
|
689
|
-
if (!
|
|
690
|
-
const
|
|
691
|
-
return
|
|
692
|
-
},
|
|
693
|
-
const
|
|
694
|
-
let
|
|
695
|
-
return
|
|
696
|
-
Buffer.from([129,
|
|
762
|
+
`, _e = (r, a) => {
|
|
763
|
+
if (!L) return r;
|
|
764
|
+
const l = ot(a);
|
|
765
|
+
return r.includes("</body>") ? r.replace("</body>", `${l}</body>`) : r.includes("</html>") ? r.replace("</html>", `${l}</html>`) : r + l;
|
|
766
|
+
}, nt = (r) => {
|
|
767
|
+
const a = Buffer.from(r), l = a.length;
|
|
768
|
+
let c;
|
|
769
|
+
return l < 126 ? c = Buffer.concat([
|
|
770
|
+
Buffer.from([129, l]),
|
|
697
771
|
// FIN + text frame, length
|
|
698
|
-
|
|
699
|
-
]) :
|
|
772
|
+
a
|
|
773
|
+
]) : l < 65536 ? c = Buffer.concat([
|
|
700
774
|
Buffer.from([129, 126]),
|
|
701
775
|
// FIN + text frame, extended length
|
|
702
|
-
Buffer.from([
|
|
776
|
+
Buffer.from([l >> 8, l & 255]),
|
|
703
777
|
// 16-bit length
|
|
704
|
-
|
|
705
|
-
]) :
|
|
778
|
+
a
|
|
779
|
+
]) : c = Buffer.concat([
|
|
706
780
|
Buffer.from([129, 127]),
|
|
707
781
|
// FIN + text frame, extended length
|
|
708
|
-
Buffer.from([0, 0, 0, 0,
|
|
782
|
+
Buffer.from([0, 0, 0, 0, l >> 24, l >> 16 & 255, l >> 8 & 255, l & 255]),
|
|
709
783
|
// 64-bit length
|
|
710
|
-
|
|
711
|
-
]),
|
|
712
|
-
},
|
|
713
|
-
if (!
|
|
714
|
-
const
|
|
715
|
-
if (!
|
|
784
|
+
a
|
|
785
|
+
]), c;
|
|
786
|
+
}, Le = () => {
|
|
787
|
+
if (!L) return;
|
|
788
|
+
const r = X.get(C);
|
|
789
|
+
if (!r || r.size === 0)
|
|
716
790
|
return;
|
|
717
|
-
console.log(`🔥 Notifying ${
|
|
718
|
-
const
|
|
791
|
+
console.log(`🔥 Notifying ${r.size} HMR client(s)`);
|
|
792
|
+
const a = x ? $ : e.default.join(b, "index.html");
|
|
719
793
|
try {
|
|
720
|
-
const
|
|
794
|
+
const l = o.default.readFileSync(a, "utf-8"), c = _e(l, C), f = JSON.stringify({
|
|
721
795
|
type: "update",
|
|
722
|
-
html:
|
|
723
|
-
}),
|
|
724
|
-
|
|
796
|
+
html: c
|
|
797
|
+
}), y = nt(f);
|
|
798
|
+
r.forEach((S) => {
|
|
725
799
|
try {
|
|
726
|
-
|
|
800
|
+
S.write(y);
|
|
727
801
|
} catch {
|
|
728
|
-
|
|
802
|
+
r.delete(S);
|
|
729
803
|
}
|
|
730
804
|
});
|
|
731
|
-
} catch (
|
|
732
|
-
console.error("❌ Failed to read HTML for HMR:",
|
|
805
|
+
} catch (l) {
|
|
806
|
+
console.error("❌ Failed to read HTML for HMR:", l.message);
|
|
733
807
|
}
|
|
734
808
|
};
|
|
735
|
-
let
|
|
736
|
-
const
|
|
737
|
-
if (
|
|
809
|
+
let $e = { hasTriedPlatformFix: !1, hasTriedInstall: !1 };
|
|
810
|
+
const de = (r) => {
|
|
811
|
+
if (u) {
|
|
738
812
|
v = !0;
|
|
739
813
|
return;
|
|
740
814
|
}
|
|
741
|
-
|
|
742
|
-
🔨 Building...`),
|
|
743
|
-
if (
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
return;
|
|
750
|
-
}
|
|
751
|
-
console.error("❌ Build failed:", t.message), i && console.error(i);
|
|
815
|
+
u = !0, console.log(`
|
|
816
|
+
🔨 Building...`), t("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (a, l, c) => {
|
|
817
|
+
if (u = !1, a) {
|
|
818
|
+
const f = await Ke(a, l, c, t, {
|
|
819
|
+
...$e,
|
|
820
|
+
onRetry: () => de(r)
|
|
821
|
+
});
|
|
822
|
+
$e = { ...$e, ...f }, f.handled || (console.error("❌ Build failed:", a.message), c && console.error(c));
|
|
752
823
|
} else
|
|
753
|
-
console.log("✅ Build completed"),
|
|
754
|
-
v && (v = !1,
|
|
824
|
+
console.log("✅ Build completed"), l && console.log(l), Le(), r && r();
|
|
825
|
+
v && (v = !1, de());
|
|
755
826
|
});
|
|
756
|
-
},
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
const
|
|
760
|
-
if (
|
|
761
|
-
|
|
762
|
-
else if (
|
|
763
|
-
const
|
|
764
|
-
if (
|
|
827
|
+
}, Ae = /* @__PURE__ */ new Set(), Ce = (r) => {
|
|
828
|
+
o.default.readdir(r, { withFileTypes: !0 }, (a, l) => {
|
|
829
|
+
a || (l.forEach((c) => {
|
|
830
|
+
const f = e.default.join(r, c.name);
|
|
831
|
+
if (c.isDirectory())
|
|
832
|
+
c.name !== "node_modules" && c.name !== "dist" && !c.name.startsWith(".") && Ce(f);
|
|
833
|
+
else if (c.isFile()) {
|
|
834
|
+
const y = e.default.extname(c.name);
|
|
835
|
+
if (y === ".js" || y === ".css" || y === ".html")
|
|
765
836
|
try {
|
|
766
|
-
const
|
|
767
|
-
|
|
837
|
+
const S = o.default.readFileSync(f, "utf-8");
|
|
838
|
+
P.set(f, S);
|
|
768
839
|
} catch {
|
|
769
840
|
}
|
|
770
841
|
}
|
|
771
|
-
}),
|
|
772
|
-
if (!
|
|
773
|
-
const
|
|
774
|
-
if (
|
|
775
|
-
const
|
|
842
|
+
}), Ae.has(r) || (Ae.add(r), o.default.watch(r, (c, f) => {
|
|
843
|
+
if (!f) return;
|
|
844
|
+
const y = e.default.extname(f);
|
|
845
|
+
if (y !== ".js" && y !== ".css" && y !== ".html") return;
|
|
846
|
+
const S = e.default.join(r, f);
|
|
776
847
|
setTimeout(() => {
|
|
777
848
|
try {
|
|
778
|
-
const
|
|
779
|
-
|
|
849
|
+
const F = o.default.readFileSync(S, "utf-8"), N = P.get(S);
|
|
850
|
+
F !== N && (P.set(S, F), console.log(`📝 File changed: ${S}`), x ? Le() : de());
|
|
780
851
|
} catch {
|
|
781
852
|
}
|
|
782
853
|
}, 50);
|
|
783
854
|
})));
|
|
784
855
|
});
|
|
785
|
-
},
|
|
856
|
+
}, De = (r) => {
|
|
786
857
|
console.log(`
|
|
787
|
-
🔨 Component: ${
|
|
788
|
-
`)
|
|
789
|
-
|
|
790
|
-
|
|
858
|
+
🔨 Component: ${C}`), x ? (console.log("📄 No build needed (single HTML file mode)"), Ce(O), console.log(`👀 Watching ${$} for changes...`), console.log(`Press Ctrl+C to stop
|
|
859
|
+
`), r && r()) : (de(r), Ce(O), console.log("👀 Watching .js, .css, and .html files for changes..."), console.log(`Press Ctrl+C to stop
|
|
860
|
+
`));
|
|
861
|
+
}, st = () => new Promise((r) => {
|
|
862
|
+
const a = {
|
|
791
863
|
hostname: "localhost",
|
|
792
|
-
port:
|
|
864
|
+
port: p,
|
|
793
865
|
path: "/_list",
|
|
794
866
|
method: "GET",
|
|
795
867
|
timeout: 1e3
|
|
796
|
-
},
|
|
797
|
-
|
|
868
|
+
}, l = n.default.request(a, (c) => {
|
|
869
|
+
r(!0);
|
|
798
870
|
});
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}),
|
|
802
|
-
}),
|
|
803
|
-
const
|
|
804
|
-
if (
|
|
805
|
-
let
|
|
806
|
-
|
|
871
|
+
l.on("error", () => r(!1)), l.on("timeout", () => {
|
|
872
|
+
l.destroy(), r(!1);
|
|
873
|
+
}), l.end();
|
|
874
|
+
}), it = () => new Promise((r) => {
|
|
875
|
+
const a = n.default.createServer((l, c) => {
|
|
876
|
+
if (c.setHeader("Content-Type", "application/json"), l.method === "POST" && l.url === "/_register") {
|
|
877
|
+
let f = "";
|
|
878
|
+
l.on("data", (y) => f += y), l.on("end", () => {
|
|
807
879
|
try {
|
|
808
|
-
const { componentId:
|
|
809
|
-
|
|
810
|
-
const
|
|
811
|
-
console.log(`✅ Registered: ${
|
|
812
|
-
} catch (
|
|
813
|
-
|
|
880
|
+
const { componentId: y, distPath: S, componentName: F, htmlFile: N } = JSON.parse(f);
|
|
881
|
+
R.set(y, { path: S, name: F || null, htmlFile: N || null });
|
|
882
|
+
const J = F ? ` (${F})` : "";
|
|
883
|
+
console.log(`✅ Registered: ${y}${J} -> ${S}${N ? "/" + N : ""}`), c.writeHead(200), c.end(JSON.stringify({ success: !0, registered: Array.from(R.keys()) }));
|
|
884
|
+
} catch (y) {
|
|
885
|
+
c.writeHead(400), c.end(JSON.stringify({ error: y.message }));
|
|
814
886
|
}
|
|
815
887
|
});
|
|
816
|
-
} else if (
|
|
817
|
-
let
|
|
818
|
-
|
|
888
|
+
} else if (l.method === "POST" && l.url === "/_unregister") {
|
|
889
|
+
let f = "";
|
|
890
|
+
l.on("data", (y) => f += y), l.on("end", () => {
|
|
819
891
|
try {
|
|
820
|
-
const { componentId:
|
|
821
|
-
|
|
822
|
-
} catch (
|
|
823
|
-
|
|
892
|
+
const { componentId: y } = JSON.parse(f);
|
|
893
|
+
R.delete(y), console.log(`❌ Unregistered: ${y}`), c.writeHead(200), c.end(JSON.stringify({ success: !0 }));
|
|
894
|
+
} catch (y) {
|
|
895
|
+
c.writeHead(400), c.end(JSON.stringify({ error: y.message }));
|
|
824
896
|
}
|
|
825
897
|
});
|
|
826
|
-
} else
|
|
898
|
+
} else l.method === "GET" && l.url === "/_list" ? (c.writeHead(200), c.end(JSON.stringify({ components: Array.from(R.entries()) }))) : (c.writeHead(404), c.end(JSON.stringify({ error: "Not found" })));
|
|
827
899
|
});
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
}),
|
|
900
|
+
a.on("error", () => {
|
|
901
|
+
r(!1);
|
|
902
|
+
}), a.listen(p, () => {
|
|
831
903
|
console.log(`
|
|
832
|
-
🔄 Taking over as server...`), console.log(`📡 Management server on port ${
|
|
833
|
-
|
|
834
|
-
}),
|
|
835
|
-
console.log(`📡 Main server running at http://localhost:${m}`)
|
|
836
|
-
|
|
837
|
-
|
|
904
|
+
🔄 Taking over as server...`), console.log(`📡 Management server on port ${p}`), ce.on("error", () => {
|
|
905
|
+
a.close(), r(!1);
|
|
906
|
+
}), ce.listen(m, () => {
|
|
907
|
+
console.log(`📡 Main server running at http://localhost:${m}`);
|
|
908
|
+
const l = x ? e.default.resolve(O) : e.default.resolve(O, b);
|
|
909
|
+
R.set(C, {
|
|
910
|
+
path: l,
|
|
911
|
+
name: I,
|
|
912
|
+
htmlFile: x ? $ : null
|
|
838
913
|
});
|
|
839
|
-
const
|
|
840
|
-
console.log(`✅ Registered component: ${
|
|
914
|
+
const c = I ? ` (${I})` : "";
|
|
915
|
+
console.log(`✅ Registered component: ${C}${c}`), console.log(`📡 Access at: http://localhost:${m}/view/${C}/`), r(!0);
|
|
841
916
|
});
|
|
842
917
|
});
|
|
843
918
|
});
|
|
844
|
-
let
|
|
845
|
-
const
|
|
846
|
-
|
|
847
|
-
await
|
|
848
|
-
⚠️ Server appears to be down, attempting to take over...`), await
|
|
919
|
+
let pe;
|
|
920
|
+
const He = () => {
|
|
921
|
+
pe = setInterval(async () => {
|
|
922
|
+
await st() || (clearInterval(pe), console.log(`
|
|
923
|
+
⚠️ Server appears to be down, attempting to take over...`), await it() ? console.log("✅ Successfully took over as server") : (console.log("ℹ️ Another instance took over, re-registering..."), setTimeout(async () => {
|
|
849
924
|
try {
|
|
850
|
-
await
|
|
851
|
-
} catch (
|
|
852
|
-
console.error("❌ Failed to re-register:",
|
|
925
|
+
await Ne(), console.log(`✅ Re-registered component: ${C}`), He();
|
|
926
|
+
} catch (l) {
|
|
927
|
+
console.error("❌ Failed to re-register:", l.message);
|
|
853
928
|
}
|
|
854
929
|
}, 2e3)));
|
|
855
930
|
}, 3e3);
|
|
856
|
-
},
|
|
931
|
+
}, Ue = async () => {
|
|
857
932
|
console.log(`
|
|
858
933
|
|
|
859
|
-
🛑 Shutting down...`),
|
|
934
|
+
🛑 Shutting down...`), pe && clearInterval(pe), await tt(), process.exit(0);
|
|
860
935
|
};
|
|
861
|
-
process.on("SIGINT",
|
|
862
|
-
if (
|
|
936
|
+
process.on("SIGINT", Ue), process.on("SIGTERM", Ue), xe.on("error", async (r) => {
|
|
937
|
+
if (r.code === "EADDRINUSE") {
|
|
863
938
|
console.log(`
|
|
864
939
|
🔗 Connecting to existing dev server...`);
|
|
865
940
|
try {
|
|
866
|
-
|
|
867
|
-
const
|
|
868
|
-
console.log(`✅ Registered component: ${
|
|
869
|
-
|
|
870
|
-
}),
|
|
871
|
-
} catch (
|
|
872
|
-
console.error("❌ Failed to register component:",
|
|
941
|
+
C = await U();
|
|
942
|
+
const a = await Ne();
|
|
943
|
+
console.log(`✅ Registered component: ${C}`), console.log(`📡 Access at: http://localhost:${m}/view/${C}/`), console.log(`📋 All registered components: ${a.registered.join(", ")}`), De(() => {
|
|
944
|
+
process.env.MYOP_NO_BROWSER || g(`http://localhost:${m}/view/${C}/`);
|
|
945
|
+
}), He();
|
|
946
|
+
} catch (a) {
|
|
947
|
+
console.error("❌ Failed to register component:", a.message), process.exit(1);
|
|
873
948
|
}
|
|
874
949
|
} else
|
|
875
|
-
console.error("❌ Management server error:",
|
|
876
|
-
}),
|
|
950
|
+
console.error("❌ Management server error:", r.message), process.exit(1);
|
|
951
|
+
}), xe.on("upgrade", et), xe.listen(p, async () => {
|
|
877
952
|
console.log(`
|
|
878
|
-
🚀 Starting shared dev server...`), console.log(`📡 Management server on port ${
|
|
879
|
-
console.error("❌ Main server error:",
|
|
880
|
-
}),
|
|
881
|
-
console.log(`📡 Main server running at http://localhost:${m}`), (
|
|
882
|
-
|
|
883
|
-
|
|
953
|
+
🚀 Starting shared dev server...`), console.log(`📡 Management server on port ${p}`), ce.on("error", (r) => {
|
|
954
|
+
console.error("❌ Main server error:", r.message), process.exit(1);
|
|
955
|
+
}), ce.listen(m, async () => {
|
|
956
|
+
console.log(`📡 Main server running at http://localhost:${m}`), (C === "DEV" || C === "NEW") && (C = "DEV1");
|
|
957
|
+
const r = x ? e.default.resolve(O) : e.default.resolve(O, b);
|
|
958
|
+
R.set(C, {
|
|
959
|
+
path: r,
|
|
960
|
+
name: I,
|
|
961
|
+
htmlFile: x ? $ : null
|
|
884
962
|
});
|
|
885
|
-
const
|
|
886
|
-
console.log(`✅ Registered component: ${
|
|
887
|
-
|
|
963
|
+
const a = I ? ` (${I})` : "";
|
|
964
|
+
console.log(`✅ Registered component: ${C}${a}`), console.log(`📡 Access at: http://localhost:${m}/view/${C}/`), De(() => {
|
|
965
|
+
process.env.MYOP_NO_BROWSER || g(`http://localhost:${m}/view/${C}/`);
|
|
888
966
|
});
|
|
889
967
|
});
|
|
890
968
|
});
|
|
891
969
|
}
|
|
892
|
-
const
|
|
893
|
-
|
|
894
|
-
|
|
970
|
+
const T = class T {
|
|
971
|
+
constructor(e) {
|
|
972
|
+
this.components = e.map(
|
|
973
|
+
(t) => typeof t == "string" ? { name: t, path: "", id: "" } : t
|
|
974
|
+
), this.logs = /* @__PURE__ */ new Map(), this.scrollPos = /* @__PURE__ */ new Map(), this.statuses = /* @__PURE__ */ new Map(), this.statusKeys = /* @__PURE__ */ new Map(), this.panelPositions = /* @__PURE__ */ new Map(), this.needsFullRedraw = !0, this.pendingUpdates = /* @__PURE__ */ new Set(), this.renderQueued = !1, this.startTime = Date.now(), this.visibleLogLines = 8, this.selectedPanel = 0;
|
|
975
|
+
for (const t of this.components)
|
|
976
|
+
this.logs.set(t.name, []), this.scrollPos.set(t.name, 0), this.statuses.set(t.name, "Initializing..."), this.statusKeys.set(t.name, "initializing");
|
|
977
|
+
this.cols = process.stdout.columns || 120, this.rows = process.stdout.rows || 30, process.stdout.on("resize", () => {
|
|
978
|
+
this.cols = process.stdout.columns || 120, this.rows = process.stdout.rows || 30, this.needsFullRedraw = !0, this.calculateLayout(), this.render();
|
|
979
|
+
}), this.setupKeyboardInput(), process.stdout.write(T.ESC.hideCursor), this.calculateLayout(), this.render(), this.uptimeInterval = setInterval(() => this.updateHeader(), 1e3);
|
|
980
|
+
}
|
|
981
|
+
setupKeyboardInput() {
|
|
982
|
+
process.stdin.isTTY && (process.stdin.setRawMode(!0), process.stdin.resume(), process.stdin.setEncoding("utf8"), process.stdin.on("data", (e) => {
|
|
983
|
+
var n;
|
|
984
|
+
e === "" && (this.clear(), process.exit());
|
|
985
|
+
const t = (n = this.components[this.selectedPanel]) == null ? void 0 : n.name;
|
|
986
|
+
if (t)
|
|
987
|
+
switch (e) {
|
|
988
|
+
case "\x1B[A":
|
|
989
|
+
this.scroll(t, -1);
|
|
990
|
+
break;
|
|
991
|
+
case "\x1B[B":
|
|
992
|
+
this.scroll(t, 1);
|
|
993
|
+
break;
|
|
994
|
+
case "\x1B[C":
|
|
995
|
+
this.selectedPanel = (this.selectedPanel + 1) % this.components.length, this.needsFullRedraw = !0, this.render();
|
|
996
|
+
break;
|
|
997
|
+
case "\x1B[D":
|
|
998
|
+
this.selectedPanel = (this.selectedPanel - 1 + this.components.length) % this.components.length, this.needsFullRedraw = !0, this.render();
|
|
999
|
+
break;
|
|
1000
|
+
case "\x1B[5~":
|
|
1001
|
+
this.scroll(t, -this.visibleLogLines);
|
|
1002
|
+
break;
|
|
1003
|
+
case "\x1B[6~":
|
|
1004
|
+
this.scroll(t, this.visibleLogLines);
|
|
1005
|
+
break;
|
|
1006
|
+
case "g":
|
|
1007
|
+
this.scrollPos.set(t, 0), this.queueUpdate(t);
|
|
1008
|
+
break;
|
|
1009
|
+
case "G":
|
|
1010
|
+
const i = this.logs.get(t) || [];
|
|
1011
|
+
this.scrollPos.set(t, Math.max(0, i.length - this.visibleLogLines)), this.queueUpdate(t);
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
}));
|
|
1015
|
+
}
|
|
1016
|
+
calculateLayout() {
|
|
1017
|
+
const e = this.components.length, t = 38;
|
|
1018
|
+
let n;
|
|
1019
|
+
this.cols >= t * 3 + 4 ? n = Math.min(e, 3) : this.cols >= t * 2 + 2 ? n = Math.min(e, 2) : n = 1;
|
|
1020
|
+
const i = Math.ceil(e / n), s = Math.floor(this.cols / n), d = 2, M = this.rows - d - 2, m = Math.floor(M / i);
|
|
1021
|
+
this.visibleLogLines = Math.max(2, m - 4), this.layout = { panelsPerRow: n, panelWidth: s, numRows: i, panelHeight: m }, this.panelPositions.clear();
|
|
1022
|
+
for (let p = 0; p < e; p++) {
|
|
1023
|
+
const b = this.components[p], u = Math.floor(p / n), v = p % n;
|
|
1024
|
+
this.panelPositions.set(b.name, {
|
|
1025
|
+
row: d + 1 + u * m,
|
|
1026
|
+
col: v * s + 1,
|
|
1027
|
+
width: s,
|
|
1028
|
+
height: m
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
log(e, t, n = "info") {
|
|
1033
|
+
const i = this.logs.get(e) || [], s = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
|
|
1034
|
+
hour12: !1,
|
|
1035
|
+
hour: "2-digit",
|
|
1036
|
+
minute: "2-digit",
|
|
1037
|
+
second: "2-digit"
|
|
1038
|
+
});
|
|
1039
|
+
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);
|
|
1040
|
+
}
|
|
1041
|
+
setStatus(e, t) {
|
|
1042
|
+
let n = "ready";
|
|
1043
|
+
const i = t.toLowerCase();
|
|
1044
|
+
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);
|
|
1045
|
+
}
|
|
1046
|
+
scroll(e, t) {
|
|
1047
|
+
const n = this.logs.get(e) || [], i = this.scrollPos.get(e) || 0, s = Math.max(0, n.length - this.visibleLogLines), d = Math.max(0, Math.min(s, i + t));
|
|
1048
|
+
d !== i && (this.scrollPos.set(e, d), this.queueUpdate(e));
|
|
1049
|
+
}
|
|
1050
|
+
queueUpdate(e) {
|
|
1051
|
+
this.pendingUpdates.add(e), this.renderQueued || (this.renderQueued = !0, setImmediate(() => {
|
|
1052
|
+
this.renderQueued = !1, this.flushUpdates();
|
|
1053
|
+
}));
|
|
1054
|
+
}
|
|
1055
|
+
flushUpdates() {
|
|
1056
|
+
if (this.needsFullRedraw) {
|
|
1057
|
+
this.fullRender(), this.needsFullRedraw = !1, this.pendingUpdates.clear();
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
for (const e of this.pendingUpdates)
|
|
1061
|
+
this.renderPanel(e);
|
|
1062
|
+
this.pendingUpdates.clear();
|
|
1063
|
+
}
|
|
1064
|
+
getUptime() {
|
|
1065
|
+
const e = Math.floor((Date.now() - this.startTime) / 1e3), t = Math.floor(e / 60), n = e % 60;
|
|
1066
|
+
return `${t}:${n.toString().padStart(2, "0")}`;
|
|
1067
|
+
}
|
|
1068
|
+
updateHeader() {
|
|
1069
|
+
const e = T.C, t = Array.from(this.statusKeys.values()).filter((s) => s === "ready").length, n = this.components.length;
|
|
1070
|
+
let i = `${e.dim}📡${e.reset} http://localhost:9292 ${e.gray}|${e.reset} `;
|
|
1071
|
+
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 += T.ESC.clearLine.slice(0, -1), process.stdout.write(T.ESC.moveTo(2, 1) + i);
|
|
1072
|
+
}
|
|
1073
|
+
renderPanel(e) {
|
|
1074
|
+
const t = T.C, n = T.STATUS, i = this.panelPositions.get(e);
|
|
1075
|
+
if (!i) return;
|
|
1076
|
+
const s = this.components.findIndex((U) => U.name === e), d = this.components[s], w = s === this.selectedPanel, M = this.statusKeys.get(e) || "initializing", m = n[M], p = t[m.color], b = this.logs.get(e) || [], u = this.scrollPos.get(e) || 0, v = i.width - 1, x = w ? t.cyan : t.gray, $ = [], _ = d.name.substring(0, v - 20);
|
|
1077
|
+
let D = `${x}┌─${t.reset} ${p}${m.icon}${t.reset} `;
|
|
1078
|
+
D += `${t.bold}${_}${t.reset} ${t.gray}─${t.reset} ${p}${m.label}${t.reset} `;
|
|
1079
|
+
const g = 5 + _.length + m.label.length + 3;
|
|
1080
|
+
D += `${x}${"─".repeat(Math.max(0, v - g))}┐${t.reset}`, $.push(T.ESC.moveTo(i.row, i.col) + D);
|
|
1081
|
+
const P = (d.path || "").substring(0, v - 6);
|
|
1082
|
+
let E = `${x}│${t.reset} ${t.dim}${P}${t.reset}`;
|
|
1083
|
+
E += " ".repeat(Math.max(0, v - P.length - 3)), E += `${x}│${t.reset}`, $.push(T.ESC.moveTo(i.row + 1, i.col) + E);
|
|
1084
|
+
const C = b.length, I = C > this.visibleLogLines ? `${u + 1}-${Math.min(u + this.visibleLogLines, C)}/${C}` : "";
|
|
1085
|
+
let L = `${x}├${"─".repeat(v - I.length - 4)}${t.reset}`;
|
|
1086
|
+
I && (L += `${t.dim}${I}${t.reset}`), L += `${x}${"─".repeat(2)}┤${t.reset}`, $.push(T.ESC.moveTo(i.row + 2, i.col) + L);
|
|
1087
|
+
const Z = b.slice(u, u + this.visibleLogLines);
|
|
1088
|
+
for (let U = 0; U < this.visibleLogLines; U++) {
|
|
1089
|
+
const O = Z[U];
|
|
1090
|
+
let V = `${x}│${t.reset}`;
|
|
1091
|
+
if (O) {
|
|
1092
|
+
let R = t.white;
|
|
1093
|
+
O.type === "success" ? R = t.green : O.type === "error" ? R = t.red : O.type === "warning" ? R = t.yellow : O.type === "hmr" ? R = t.magenta : O.type === "change" && (R = t.blue);
|
|
1094
|
+
const G = O.message.substring(0, v - 12);
|
|
1095
|
+
V += `${t.dim}${O.timestamp}${t.reset} ${R}${G}${t.reset}`;
|
|
1096
|
+
const Se = v - O.timestamp.length - G.length - 2;
|
|
1097
|
+
V += " ".repeat(Math.max(0, Se));
|
|
1098
|
+
} else
|
|
1099
|
+
V += " ".repeat(v - 2);
|
|
1100
|
+
V += `${x}│${t.reset}`, $.push(T.ESC.moveTo(i.row + 3 + U, i.col) + V);
|
|
1101
|
+
}
|
|
1102
|
+
$.push(T.ESC.moveTo(i.row + 3 + this.visibleLogLines, i.col) + `${x}└${"─".repeat(v - 2)}┘${t.reset}`), process.stdout.write($.join(""));
|
|
1103
|
+
}
|
|
1104
|
+
fullRender() {
|
|
1105
|
+
const e = T.C;
|
|
1106
|
+
process.stdout.write(T.ESC.clearScreen + T.ESC.moveTo(1, 1));
|
|
1107
|
+
const t = " MYOP MONOREPO DEV ", n = Math.floor((this.cols - t.length) / 2);
|
|
1108
|
+
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();
|
|
1109
|
+
for (const i of this.components)
|
|
1110
|
+
this.renderPanel(i.name);
|
|
1111
|
+
this.renderFooter();
|
|
1112
|
+
}
|
|
1113
|
+
renderFooter() {
|
|
1114
|
+
const e = T.C, t = this.rows - 1;
|
|
1115
|
+
let n = `${e.gray}`;
|
|
1116
|
+
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(T.ESC.moveTo(t, 1) + n);
|
|
1117
|
+
}
|
|
1118
|
+
render() {
|
|
1119
|
+
this.needsFullRedraw = !0, this.queueUpdate("__full__");
|
|
1120
|
+
}
|
|
1121
|
+
clear() {
|
|
1122
|
+
this.uptimeInterval && clearInterval(this.uptimeInterval), process.stdin.isTTY && process.stdin.setRawMode(!1), process.stdout.write(T.ESC.clearScreen + T.ESC.moveTo(1, 1) + T.ESC.showCursor);
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
// ANSI escape codes
|
|
1126
|
+
ue(T, "ESC", {
|
|
1127
|
+
moveTo: (e, t) => `\x1B[${e};${t}H`,
|
|
1128
|
+
hideCursor: "\x1B[?25l",
|
|
1129
|
+
showCursor: "\x1B[?25h",
|
|
1130
|
+
clearScreen: "\x1B[2J",
|
|
1131
|
+
clearLine: "\x1B[2K"
|
|
1132
|
+
}), // Colors
|
|
1133
|
+
ue(T, "C", {
|
|
1134
|
+
reset: "\x1B[0m",
|
|
1135
|
+
bold: "\x1B[1m",
|
|
1136
|
+
dim: "\x1B[2m",
|
|
1137
|
+
red: "\x1B[31m",
|
|
1138
|
+
green: "\x1B[32m",
|
|
1139
|
+
yellow: "\x1B[33m",
|
|
1140
|
+
blue: "\x1B[34m",
|
|
1141
|
+
magenta: "\x1B[35m",
|
|
1142
|
+
cyan: "\x1B[36m",
|
|
1143
|
+
white: "\x1B[37m",
|
|
1144
|
+
gray: "\x1B[90m",
|
|
1145
|
+
bgCyan: "\x1B[46m",
|
|
1146
|
+
black: "\x1B[30m"
|
|
1147
|
+
}), // Status configs
|
|
1148
|
+
ue(T, "STATUS", {
|
|
1149
|
+
initializing: { icon: "◔", color: "yellow", label: "Initializing" },
|
|
1150
|
+
starting: { icon: "◑", color: "yellow", label: "Starting" },
|
|
1151
|
+
building: { icon: "⟳", color: "yellow", label: "Building" },
|
|
1152
|
+
ready: { icon: "●", color: "green", label: "Ready" },
|
|
1153
|
+
changed: { icon: "○", color: "blue", label: "Changed" },
|
|
1154
|
+
hmr: { icon: "⚡", color: "magenta", label: "HMR" },
|
|
1155
|
+
hmr_update: { icon: "⚡", color: "magenta", label: "HMR Update" },
|
|
1156
|
+
hmr_connected: { icon: "⚡", color: "magenta", label: "HMR" },
|
|
1157
|
+
error: { icon: "✖", color: "red", label: "Error" },
|
|
1158
|
+
warning: { icon: "⚠", color: "yellow", label: "Warning" },
|
|
1159
|
+
stopped: { icon: "■", color: "gray", label: "Stopped" }
|
|
1160
|
+
});
|
|
1161
|
+
let Te = T;
|
|
1162
|
+
async function Rt(o) {
|
|
1163
|
+
const { spawn: e, exec: t } = await import("child_process"), n = await import("path"), i = o.map((p) => ({
|
|
1164
|
+
name: p.name,
|
|
1165
|
+
path: p.path,
|
|
1166
|
+
id: p.componentId || ""
|
|
1167
|
+
})), s = new Te(i), d = [], w = (p) => {
|
|
1168
|
+
const b = process.platform;
|
|
1169
|
+
let u;
|
|
1170
|
+
b === "darwin" ? u = `open "${p}"` : b === "win32" ? u = `start "" "${p}"` : u = `xdg-open "${p}"`, t(u, () => {
|
|
1171
|
+
});
|
|
1172
|
+
}, M = () => {
|
|
1173
|
+
s.clear(), console.log(`
|
|
1174
|
+
🛑 Shutting down all components...`), d.forEach((p) => {
|
|
1175
|
+
try {
|
|
1176
|
+
p.kill("SIGTERM");
|
|
1177
|
+
} catch {
|
|
1178
|
+
}
|
|
1179
|
+
}), setTimeout(() => process.exit(0), 500);
|
|
1180
|
+
};
|
|
1181
|
+
process.on("SIGINT", M), process.on("SIGTERM", M);
|
|
1182
|
+
const m = process.argv[1];
|
|
1183
|
+
for (let p = 0; p < o.length; p++) {
|
|
1184
|
+
const b = o[p], u = b.name;
|
|
1185
|
+
s.setStatus(u, "⏳ Starting..."), s.log(u, `Starting in ${b.path}`);
|
|
1186
|
+
const v = e("node", [m, "dev"], {
|
|
1187
|
+
cwd: n.default.resolve(b.path),
|
|
1188
|
+
env: { ...process.env, FORCE_COLOR: "1", MYOP_NO_BROWSER: "1" },
|
|
1189
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1190
|
+
});
|
|
1191
|
+
d.push(v);
|
|
1192
|
+
let x = "";
|
|
1193
|
+
v.stdout.on("data", ($) => {
|
|
1194
|
+
x += $.toString();
|
|
1195
|
+
const _ = x.split(`
|
|
1196
|
+
`);
|
|
1197
|
+
x = _.pop() || "";
|
|
1198
|
+
for (const D of _) {
|
|
1199
|
+
const g = D.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "").trim();
|
|
1200
|
+
g && (g.includes("Registered component") || g.includes("Registered:") ? s.setStatus(u, "✅ Ready") : g.includes("Building...") || g.includes("Running initial build") ? s.setStatus(u, "🔨 Building...") : g.includes("Build completed") || g.includes("Build succeeded") ? s.setStatus(u, "✅ Ready") : g.includes("Build failed") ? s.setStatus(u, "❌ Build Error") : g.includes("File changed") ? (s.setStatus(u, "📝 Changed"), setTimeout(() => s.setStatus(u, "✅ Ready"), 1500)) : g.includes("Notifying") && g.includes("HMR") ? (s.setStatus(u, "🔥 HMR Update"), setTimeout(() => s.setStatus(u, "✅ Ready"), 1e3)) : g.includes("HMR client connected") && (s.setStatus(u, "🔥 HMR Connected"), setTimeout(() => s.setStatus(u, "✅ Ready"), 1e3)), !g.includes("Watching") && !g.includes("Press Ctrl+C") && !g.includes("Starting shared") && !g.includes("Management server") && !g.includes("Main server") && !g.includes("Access at:") && !g.includes("No build needed") && s.log(u, g));
|
|
1201
|
+
}
|
|
1202
|
+
}), v.stderr.on("data", ($) => {
|
|
1203
|
+
const _ = $.toString().split(`
|
|
1204
|
+
`);
|
|
1205
|
+
for (const D of _) {
|
|
1206
|
+
const g = D.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "").trim();
|
|
1207
|
+
g && (s.log(u, `⚠️ ${g}`), s.setStatus(u, "⚠️ Warning"));
|
|
1208
|
+
}
|
|
1209
|
+
}), v.on("exit", ($) => {
|
|
1210
|
+
$ !== 0 && $ !== null && (s.setStatus(u, `❌ Exited (${$})`), s.log(u, `Process exited with code ${$}`));
|
|
1211
|
+
}), p < o.length - 1 && await new Promise(($) => setTimeout($, 500));
|
|
1212
|
+
}
|
|
1213
|
+
s.render(), setTimeout(() => {
|
|
1214
|
+
w("http://localhost:9292");
|
|
1215
|
+
}, 2e3);
|
|
895
1216
|
}
|
|
896
|
-
|
|
1217
|
+
const Tt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1218
|
+
__proto__: null,
|
|
1219
|
+
devCommand: Fe,
|
|
1220
|
+
monorepoDevCommand: Rt
|
|
1221
|
+
}, Symbol.toStringTag, { value: "Module" })), Ee = ee.join(mt.homedir(), ".myop"), ae = ee.join(Ee, "credentials.json");
|
|
1222
|
+
function Et() {
|
|
1223
|
+
H.existsSync(Ee) || H.mkdirSync(Ee, { recursive: !0, mode: 448 });
|
|
1224
|
+
}
|
|
1225
|
+
function je() {
|
|
897
1226
|
try {
|
|
898
|
-
if (!
|
|
1227
|
+
if (!H.existsSync(ae))
|
|
899
1228
|
return null;
|
|
900
|
-
const
|
|
901
|
-
return JSON.parse(
|
|
902
|
-
} catch (
|
|
903
|
-
return console.info("Failed to read credentials:",
|
|
1229
|
+
const o = H.readFileSync(ae, "utf8");
|
|
1230
|
+
return JSON.parse(o);
|
|
1231
|
+
} catch (o) {
|
|
1232
|
+
return console.info("Failed to read credentials:", o.message), null;
|
|
904
1233
|
}
|
|
905
1234
|
}
|
|
906
|
-
function
|
|
907
|
-
|
|
908
|
-
const
|
|
909
|
-
...
|
|
1235
|
+
function Qe(o) {
|
|
1236
|
+
Et();
|
|
1237
|
+
const e = {
|
|
1238
|
+
...o,
|
|
910
1239
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
911
1240
|
};
|
|
912
|
-
|
|
1241
|
+
H.writeFileSync(ae, JSON.stringify(e, null, 2), {
|
|
913
1242
|
mode: 384
|
|
914
1243
|
// Read/write for owner only
|
|
915
1244
|
});
|
|
916
1245
|
}
|
|
917
|
-
function
|
|
1246
|
+
function Ze() {
|
|
918
1247
|
try {
|
|
919
|
-
return
|
|
920
|
-
} catch (
|
|
921
|
-
return console.error("Failed to clear credentials:",
|
|
1248
|
+
return H.existsSync(ae) && H.unlinkSync(ae), !0;
|
|
1249
|
+
} catch (o) {
|
|
1250
|
+
return console.error("Failed to clear credentials:", o.message), !1;
|
|
922
1251
|
}
|
|
923
1252
|
}
|
|
924
|
-
function
|
|
925
|
-
if (!
|
|
1253
|
+
function It(o) {
|
|
1254
|
+
if (!o || !o.expiresAt)
|
|
926
1255
|
return !0;
|
|
927
|
-
const
|
|
928
|
-
return Date.now() >
|
|
1256
|
+
const e = 5 * 60 * 1e3, t = new Date(o.expiresAt).getTime();
|
|
1257
|
+
return Date.now() > t - e;
|
|
929
1258
|
}
|
|
930
1259
|
function ve() {
|
|
931
|
-
const
|
|
932
|
-
return
|
|
933
|
-
email:
|
|
934
|
-
userId:
|
|
1260
|
+
const o = je();
|
|
1261
|
+
return o ? {
|
|
1262
|
+
email: o.userEmail,
|
|
1263
|
+
userId: o.userId
|
|
935
1264
|
} : null;
|
|
936
1265
|
}
|
|
937
|
-
const
|
|
938
|
-
function
|
|
939
|
-
return
|
|
1266
|
+
const se = process.env.MYOP_MCP_URL || "https://mcp.myop.dev", he = 19284, ke = `http://localhost:${he}/callback`, Ot = "myop-cli";
|
|
1267
|
+
function Ft() {
|
|
1268
|
+
return Ie.randomBytes(32).toString("base64url");
|
|
940
1269
|
}
|
|
941
|
-
function
|
|
942
|
-
return
|
|
1270
|
+
function jt(o) {
|
|
1271
|
+
return Ie.createHash("sha256").update(o).digest("base64url");
|
|
943
1272
|
}
|
|
944
|
-
async function
|
|
945
|
-
const
|
|
1273
|
+
async function kt() {
|
|
1274
|
+
const o = await fetch(`${se}/oauth/register`, {
|
|
946
1275
|
method: "POST",
|
|
947
1276
|
headers: { "Content-Type": "application/json" },
|
|
948
1277
|
body: JSON.stringify({
|
|
949
|
-
client_name:
|
|
950
|
-
redirect_uris: [
|
|
1278
|
+
client_name: Ot,
|
|
1279
|
+
redirect_uris: [ke],
|
|
951
1280
|
grant_types: ["authorization_code", "refresh_token"],
|
|
952
1281
|
response_types: ["code"]
|
|
953
1282
|
})
|
|
954
1283
|
});
|
|
955
|
-
if (!
|
|
956
|
-
const
|
|
957
|
-
throw new Error(`Failed to register client: ${
|
|
1284
|
+
if (!o.ok) {
|
|
1285
|
+
const e = await o.text();
|
|
1286
|
+
throw new Error(`Failed to register client: ${e}`);
|
|
958
1287
|
}
|
|
959
|
-
return
|
|
1288
|
+
return o.json();
|
|
960
1289
|
}
|
|
961
|
-
function
|
|
962
|
-
const
|
|
1290
|
+
function ge(o, e, t, n = null) {
|
|
1291
|
+
const i = {
|
|
963
1292
|
success: `<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#4ade80" stroke-width="2">
|
|
964
1293
|
<circle cx="12" cy="12" r="10"/>
|
|
965
1294
|
<path d="M8 12l2.5 2.5L16 9"/>
|
|
@@ -972,17 +1301,17 @@ function re(e, n, s, a = null) {
|
|
|
972
1301
|
<path d="M12 2L2 22h20L12 2z"/>
|
|
973
1302
|
<path d="M12 9v4M12 17h.01"/>
|
|
974
1303
|
</svg>`
|
|
975
|
-
},
|
|
1304
|
+
}, s = {
|
|
976
1305
|
success: { accent: "#4ade80", glow: "rgba(74, 222, 128, 0.1)" },
|
|
977
1306
|
error: { accent: "#f87171", glow: "rgba(248, 113, 113, 0.1)" },
|
|
978
1307
|
warning: { accent: "#fbbf24", glow: "rgba(251, 191, 36, 0.1)" }
|
|
979
|
-
}, { accent:
|
|
1308
|
+
}, { accent: d, glow: w } = s[o] || s.error;
|
|
980
1309
|
return `<!DOCTYPE html>
|
|
981
1310
|
<html lang="en">
|
|
982
1311
|
<head>
|
|
983
1312
|
<meta charset="UTF-8">
|
|
984
1313
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
985
|
-
<title>myop-cli | ${
|
|
1314
|
+
<title>myop-cli | ${e}</title>
|
|
986
1315
|
<style>
|
|
987
1316
|
* {
|
|
988
1317
|
margin: 0;
|
|
@@ -1037,7 +1366,7 @@ function re(e, n, s, a = null) {
|
|
|
1037
1366
|
h1 {
|
|
1038
1367
|
font-size: 20px;
|
|
1039
1368
|
font-weight: 500;
|
|
1040
|
-
color: ${
|
|
1369
|
+
color: ${d};
|
|
1041
1370
|
margin-bottom: 12px;
|
|
1042
1371
|
letter-spacing: -0.5px;
|
|
1043
1372
|
}
|
|
@@ -1070,7 +1399,7 @@ function re(e, n, s, a = null) {
|
|
|
1070
1399
|
align-items: center;
|
|
1071
1400
|
gap: 8px;
|
|
1072
1401
|
background: ${w};
|
|
1073
|
-
border: 1px solid ${
|
|
1402
|
+
border: 1px solid ${d}33;
|
|
1074
1403
|
border-radius: 4px;
|
|
1075
1404
|
padding: 10px 16px;
|
|
1076
1405
|
font-size: 12px;
|
|
@@ -1107,11 +1436,11 @@ function re(e, n, s, a = null) {
|
|
|
1107
1436
|
<body>
|
|
1108
1437
|
<div class="container">
|
|
1109
1438
|
<div class="icon">
|
|
1110
|
-
${
|
|
1439
|
+
${i[o] || i.error}
|
|
1111
1440
|
</div>
|
|
1112
|
-
<h1>${
|
|
1113
|
-
<p class="message">${
|
|
1114
|
-
${
|
|
1441
|
+
<h1>${e}</h1>
|
|
1442
|
+
<p class="message">${t}</p>
|
|
1443
|
+
${n ? `<div class="details"><code>Error:</code> ${n}</div>` : ""}
|
|
1115
1444
|
<div class="hint">
|
|
1116
1445
|
<span>Press</span>
|
|
1117
1446
|
<kbd>⌘</kbd><kbd>W</kbd>
|
|
@@ -1124,95 +1453,95 @@ function re(e, n, s, a = null) {
|
|
|
1124
1453
|
</body>
|
|
1125
1454
|
</html>`;
|
|
1126
1455
|
}
|
|
1127
|
-
function
|
|
1128
|
-
return new Promise((
|
|
1129
|
-
const
|
|
1130
|
-
const
|
|
1131
|
-
if (
|
|
1132
|
-
const w =
|
|
1456
|
+
function Nt(o) {
|
|
1457
|
+
return new Promise((e, t) => {
|
|
1458
|
+
const n = dt.createServer((i, s) => {
|
|
1459
|
+
const d = new ze(i.url, `http://localhost:${he}`);
|
|
1460
|
+
if (d.pathname === "/callback") {
|
|
1461
|
+
const w = d.searchParams.get("code"), M = d.searchParams.get("state"), m = d.searchParams.get("error");
|
|
1133
1462
|
if (m) {
|
|
1134
|
-
|
|
1463
|
+
s.writeHead(200, { "Content-Type": "text/html" }), s.end(ge(
|
|
1135
1464
|
"error",
|
|
1136
1465
|
"Authentication Failed",
|
|
1137
1466
|
"Unable to complete the authentication process.",
|
|
1138
1467
|
m
|
|
1139
|
-
)),
|
|
1468
|
+
)), n.close(), t(new Error(`OAuth error: ${m}`));
|
|
1140
1469
|
return;
|
|
1141
1470
|
}
|
|
1142
|
-
if (
|
|
1143
|
-
|
|
1471
|
+
if (M !== o) {
|
|
1472
|
+
s.writeHead(400, { "Content-Type": "text/html" }), s.end(ge(
|
|
1144
1473
|
"warning",
|
|
1145
1474
|
"Security Error",
|
|
1146
1475
|
"State mismatch detected. This could indicate a CSRF attack. Please try authenticating again.",
|
|
1147
1476
|
"state_mismatch"
|
|
1148
|
-
)),
|
|
1477
|
+
)), n.close(), t(new Error("State mismatch"));
|
|
1149
1478
|
return;
|
|
1150
1479
|
}
|
|
1151
1480
|
if (!w) {
|
|
1152
|
-
|
|
1481
|
+
s.writeHead(400, { "Content-Type": "text/html" }), s.end(ge(
|
|
1153
1482
|
"error",
|
|
1154
1483
|
"Missing Authorization Code",
|
|
1155
1484
|
"No authorization code was received from the server.",
|
|
1156
1485
|
"missing_code"
|
|
1157
|
-
)),
|
|
1486
|
+
)), n.close(), t(new Error("No authorization code"));
|
|
1158
1487
|
return;
|
|
1159
1488
|
}
|
|
1160
|
-
|
|
1489
|
+
s.writeHead(200, { "Content-Type": "text/html" }), s.end(ge(
|
|
1161
1490
|
"success",
|
|
1162
1491
|
"Authentication Successful",
|
|
1163
1492
|
"You have been authenticated successfully. Return to the terminal to continue."
|
|
1164
|
-
)),
|
|
1493
|
+
)), n.close(), e(w);
|
|
1165
1494
|
} else
|
|
1166
|
-
|
|
1495
|
+
s.writeHead(404), s.end("Not found");
|
|
1167
1496
|
});
|
|
1168
|
-
|
|
1169
|
-
console.info(`OAuth callback server listening on port ${
|
|
1497
|
+
n.listen(he, () => {
|
|
1498
|
+
console.info(`OAuth callback server listening on port ${he}`);
|
|
1170
1499
|
}), setTimeout(() => {
|
|
1171
|
-
|
|
1500
|
+
n.close(), t(new Error("Authentication timed out"));
|
|
1172
1501
|
}, 5 * 60 * 1e3);
|
|
1173
1502
|
});
|
|
1174
1503
|
}
|
|
1175
|
-
async function
|
|
1176
|
-
const
|
|
1504
|
+
async function _t(o, e, t) {
|
|
1505
|
+
const n = await fetch(`${se}/oauth/token`, {
|
|
1177
1506
|
method: "POST",
|
|
1178
1507
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1179
|
-
body: new
|
|
1508
|
+
body: new We({
|
|
1180
1509
|
grant_type: "authorization_code",
|
|
1181
|
-
code:
|
|
1182
|
-
client_id:
|
|
1183
|
-
redirect_uri:
|
|
1184
|
-
code_verifier:
|
|
1510
|
+
code: o,
|
|
1511
|
+
client_id: e,
|
|
1512
|
+
redirect_uri: ke,
|
|
1513
|
+
code_verifier: t
|
|
1185
1514
|
})
|
|
1186
1515
|
});
|
|
1187
|
-
if (!
|
|
1188
|
-
const
|
|
1189
|
-
throw new Error(
|
|
1516
|
+
if (!n.ok) {
|
|
1517
|
+
const i = await n.json();
|
|
1518
|
+
throw new Error(i.error_description || i.error || "Token exchange failed");
|
|
1190
1519
|
}
|
|
1191
|
-
return
|
|
1520
|
+
return n.json();
|
|
1192
1521
|
}
|
|
1193
|
-
async function
|
|
1194
|
-
const
|
|
1522
|
+
async function Lt(o, e) {
|
|
1523
|
+
const t = await fetch(`${se}/oauth/token`, {
|
|
1195
1524
|
method: "POST",
|
|
1196
1525
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1197
|
-
body: new
|
|
1526
|
+
body: new We({
|
|
1198
1527
|
grant_type: "refresh_token",
|
|
1199
|
-
refresh_token:
|
|
1200
|
-
client_id:
|
|
1528
|
+
refresh_token: o,
|
|
1529
|
+
client_id: e
|
|
1201
1530
|
})
|
|
1202
1531
|
});
|
|
1203
|
-
if (!
|
|
1204
|
-
const
|
|
1205
|
-
throw new Error(
|
|
1532
|
+
if (!t.ok) {
|
|
1533
|
+
const n = await t.json();
|
|
1534
|
+
throw new Error(n.error_description || n.error || "Token refresh failed");
|
|
1206
1535
|
}
|
|
1207
|
-
return
|
|
1536
|
+
return t.json();
|
|
1208
1537
|
}
|
|
1209
|
-
async function
|
|
1210
|
-
var
|
|
1211
|
-
const
|
|
1538
|
+
async function At(o) {
|
|
1539
|
+
var i, s, d;
|
|
1540
|
+
const e = await fetch(`${se}/mcp`, {
|
|
1212
1541
|
method: "POST",
|
|
1213
1542
|
headers: {
|
|
1214
1543
|
"Content-Type": "application/json",
|
|
1215
|
-
Authorization: `Bearer ${
|
|
1544
|
+
Authorization: `Bearer ${o}`
|
|
1216
1545
|
},
|
|
1217
1546
|
body: JSON.stringify({
|
|
1218
1547
|
jsonrpc: "2.0",
|
|
@@ -1224,244 +1553,287 @@ async function wt(e) {
|
|
|
1224
1553
|
}
|
|
1225
1554
|
})
|
|
1226
1555
|
});
|
|
1227
|
-
if (!
|
|
1556
|
+
if (!e.ok)
|
|
1228
1557
|
throw new Error("Failed to get user info");
|
|
1229
|
-
const
|
|
1230
|
-
if (
|
|
1231
|
-
throw new Error(
|
|
1232
|
-
const
|
|
1233
|
-
if (
|
|
1234
|
-
return JSON.parse(
|
|
1558
|
+
const t = await e.json();
|
|
1559
|
+
if (t.error)
|
|
1560
|
+
throw new Error(t.error.message);
|
|
1561
|
+
const n = (d = (s = (i = t.result) == null ? void 0 : i.content) == null ? void 0 : s[0]) == null ? void 0 : d.text;
|
|
1562
|
+
if (n)
|
|
1563
|
+
return JSON.parse(n);
|
|
1235
1564
|
throw new Error("Invalid response from whoami");
|
|
1236
1565
|
}
|
|
1237
|
-
async function
|
|
1238
|
-
const
|
|
1566
|
+
async function re() {
|
|
1567
|
+
const o = W("Starting authentication...").start();
|
|
1239
1568
|
try {
|
|
1240
|
-
|
|
1241
|
-
const
|
|
1242
|
-
|
|
1243
|
-
const
|
|
1244
|
-
w.searchParams.set("response_type", "code"), w.searchParams.set("client_id",
|
|
1569
|
+
o.text = "Registering OAuth client...";
|
|
1570
|
+
const t = (await kt()).client_id, n = Ft(), i = jt(n), s = Ie.randomBytes(16).toString("hex");
|
|
1571
|
+
o.text = "Waiting for authorization...";
|
|
1572
|
+
const d = Nt(s), w = new ze(`${se}/oauth/authorize`);
|
|
1573
|
+
w.searchParams.set("response_type", "code"), w.searchParams.set("client_id", t), w.searchParams.set("redirect_uri", ke), w.searchParams.set("code_challenge", i), w.searchParams.set("code_challenge_method", "S256"), w.searchParams.set("state", s), o.stop(), console.log(`
|
|
1245
1574
|
🌐 Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${w.toString()}
|
|
1246
|
-
`), await
|
|
1247
|
-
const
|
|
1248
|
-
|
|
1249
|
-
const m = await
|
|
1250
|
-
|
|
1251
|
-
const
|
|
1575
|
+
`), await pt(w.toString());
|
|
1576
|
+
const M = await d;
|
|
1577
|
+
o.start("Exchanging authorization code...");
|
|
1578
|
+
const m = await _t(M, t, n);
|
|
1579
|
+
o.text = "Getting user info...";
|
|
1580
|
+
const p = await At(m.access_token), b = {
|
|
1252
1581
|
accessToken: m.access_token,
|
|
1253
1582
|
refreshToken: m.refresh_token,
|
|
1254
1583
|
expiresAt: new Date(Date.now() + m.expires_in * 1e3).toISOString(),
|
|
1255
|
-
clientId:
|
|
1256
|
-
userId:
|
|
1257
|
-
userEmail:
|
|
1584
|
+
clientId: t,
|
|
1585
|
+
userId: p.userId,
|
|
1586
|
+
userEmail: p.email
|
|
1258
1587
|
};
|
|
1259
|
-
return
|
|
1260
|
-
} catch (
|
|
1261
|
-
throw
|
|
1588
|
+
return Qe(b), o.succeed(`Authenticated as ${p.email}`), b;
|
|
1589
|
+
} catch (e) {
|
|
1590
|
+
throw o.fail(`Authentication failed: ${e.message}`), e;
|
|
1262
1591
|
}
|
|
1263
1592
|
}
|
|
1264
|
-
async function
|
|
1265
|
-
const
|
|
1266
|
-
if (!
|
|
1593
|
+
async function Xe() {
|
|
1594
|
+
const o = je();
|
|
1595
|
+
if (!o) {
|
|
1267
1596
|
console.log("Not currently logged in.");
|
|
1268
1597
|
return;
|
|
1269
1598
|
}
|
|
1270
|
-
|
|
1599
|
+
Ze(), console.log(`✅ Logged out (was: ${o.userEmail})`);
|
|
1271
1600
|
}
|
|
1272
|
-
async function
|
|
1273
|
-
let
|
|
1274
|
-
if (!
|
|
1601
|
+
async function Dt() {
|
|
1602
|
+
let o = je();
|
|
1603
|
+
if (!o)
|
|
1275
1604
|
return console.log(`Not logged in. Starting authentication...
|
|
1276
|
-
`), await
|
|
1277
|
-
if (!
|
|
1278
|
-
return
|
|
1279
|
-
if (
|
|
1280
|
-
const
|
|
1605
|
+
`), await re();
|
|
1606
|
+
if (!It(o))
|
|
1607
|
+
return o;
|
|
1608
|
+
if (o.refreshToken) {
|
|
1609
|
+
const e = W("Refreshing access token...").start();
|
|
1281
1610
|
try {
|
|
1282
|
-
const
|
|
1283
|
-
|
|
1284
|
-
|
|
1611
|
+
const t = await Lt(
|
|
1612
|
+
o.refreshToken,
|
|
1613
|
+
o.clientId
|
|
1285
1614
|
);
|
|
1286
|
-
return
|
|
1287
|
-
...
|
|
1288
|
-
accessToken:
|
|
1289
|
-
refreshToken:
|
|
1290
|
-
expiresAt: new Date(Date.now() +
|
|
1291
|
-
},
|
|
1615
|
+
return o = {
|
|
1616
|
+
...o,
|
|
1617
|
+
accessToken: t.access_token,
|
|
1618
|
+
refreshToken: t.refresh_token,
|
|
1619
|
+
expiresAt: new Date(Date.now() + t.expires_in * 1e3).toISOString()
|
|
1620
|
+
}, Qe(o), e.succeed("Token refreshed"), o;
|
|
1292
1621
|
} catch {
|
|
1293
|
-
return
|
|
1622
|
+
return e.warn("Token refresh failed, please log in again"), Ze(), await re();
|
|
1294
1623
|
}
|
|
1295
1624
|
}
|
|
1296
1625
|
return console.log(`Session expired. Please log in again.
|
|
1297
|
-
`), await
|
|
1626
|
+
`), await re();
|
|
1298
1627
|
}
|
|
1299
|
-
function
|
|
1300
|
-
return
|
|
1628
|
+
function Ht() {
|
|
1629
|
+
return se;
|
|
1301
1630
|
}
|
|
1302
|
-
const
|
|
1303
|
-
async function
|
|
1631
|
+
const ye = "@myop/cli";
|
|
1632
|
+
async function Ut() {
|
|
1304
1633
|
try {
|
|
1305
|
-
const
|
|
1306
|
-
return
|
|
1634
|
+
const o = await fetch(`https://registry.npmjs.org/${ye}/latest`);
|
|
1635
|
+
return o.ok ? (await o.json()).version : null;
|
|
1307
1636
|
} catch {
|
|
1308
1637
|
return null;
|
|
1309
1638
|
}
|
|
1310
1639
|
}
|
|
1311
|
-
function
|
|
1312
|
-
const
|
|
1313
|
-
for (let
|
|
1314
|
-
const
|
|
1315
|
-
if (
|
|
1316
|
-
if (
|
|
1640
|
+
function Bt(o, e) {
|
|
1641
|
+
const t = o.split(".").map(Number), n = e.split(".").map(Number);
|
|
1642
|
+
for (let i = 0; i < Math.max(t.length, n.length); i++) {
|
|
1643
|
+
const s = t[i] || 0, d = n[i] || 0;
|
|
1644
|
+
if (s > d) return 1;
|
|
1645
|
+
if (s < d) return -1;
|
|
1317
1646
|
}
|
|
1318
1647
|
return 0;
|
|
1319
1648
|
}
|
|
1320
|
-
async function
|
|
1321
|
-
const
|
|
1649
|
+
async function Jt(o) {
|
|
1650
|
+
const e = W({
|
|
1322
1651
|
text: "Checking for updates...",
|
|
1323
1652
|
color: "cyan"
|
|
1324
|
-
}).start(),
|
|
1325
|
-
if (
|
|
1653
|
+
}).start(), t = await Ut();
|
|
1654
|
+
if (e.stop(), !t || Bt(t, o) <= 0)
|
|
1326
1655
|
return !1;
|
|
1327
1656
|
console.log(`
|
|
1328
|
-
📦 New version available: ${
|
|
1657
|
+
📦 New version available: ${o} → ${t}
|
|
1329
1658
|
`);
|
|
1330
|
-
let
|
|
1659
|
+
let n;
|
|
1331
1660
|
try {
|
|
1332
|
-
|
|
1661
|
+
n = await Je({
|
|
1333
1662
|
message: "Would you like to update now?",
|
|
1334
1663
|
choices: [
|
|
1335
1664
|
{ name: "Yes, update now", value: !0 },
|
|
1336
1665
|
{ name: "No, continue with current version", value: !1 }
|
|
1337
1666
|
]
|
|
1338
1667
|
});
|
|
1339
|
-
} catch (
|
|
1340
|
-
throw
|
|
1668
|
+
} catch (i) {
|
|
1669
|
+
throw i.name === "ExitPromptError" && (console.log(`
|
|
1341
1670
|
|
|
1342
1671
|
👋 Goodbye!
|
|
1343
|
-
`), process.exit(0)),
|
|
1672
|
+
`), process.exit(0)), i;
|
|
1344
1673
|
}
|
|
1345
|
-
if (
|
|
1346
|
-
const
|
|
1347
|
-
text: `Updating ${
|
|
1674
|
+
if (n) {
|
|
1675
|
+
const i = W({
|
|
1676
|
+
text: `Updating ${ye} to v${t}...`,
|
|
1348
1677
|
color: "green"
|
|
1349
1678
|
}).start();
|
|
1350
1679
|
try {
|
|
1351
|
-
return
|
|
1680
|
+
return fe(`npm install -g ${ye}@latest`, { stdio: "pipe" }), i.succeed(`Updated to v${t}`), console.log(`
|
|
1352
1681
|
🔄 Restarting with new version...
|
|
1353
|
-
`),
|
|
1682
|
+
`), ct("myop", process.argv.slice(2), {
|
|
1354
1683
|
stdio: "inherit",
|
|
1355
1684
|
shell: !0
|
|
1356
|
-
}).on("close", (
|
|
1357
|
-
process.exit(
|
|
1685
|
+
}).on("close", (d) => {
|
|
1686
|
+
process.exit(d || 0);
|
|
1358
1687
|
}), !0;
|
|
1359
1688
|
} catch {
|
|
1360
|
-
return
|
|
1361
|
-
You can manually update by running: npm install -g ${
|
|
1689
|
+
return i.fail("Update failed"), console.log(`
|
|
1690
|
+
You can manually update by running: npm install -g ${ye}@latest
|
|
1362
1691
|
`), !1;
|
|
1363
1692
|
}
|
|
1364
1693
|
}
|
|
1365
1694
|
return !1;
|
|
1366
1695
|
}
|
|
1367
|
-
const
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1696
|
+
const zt = (o) => new Promise((e) => setTimeout(e, o)), qe = (o = ".", e = 3, t = 0) => {
|
|
1697
|
+
const n = [];
|
|
1698
|
+
if (t > e) return n;
|
|
1699
|
+
try {
|
|
1700
|
+
const i = H.readdirSync(o, { withFileTypes: !0 });
|
|
1701
|
+
for (const s of i) {
|
|
1702
|
+
const d = ee.join(o, s.name);
|
|
1703
|
+
if (s.isDirectory()) {
|
|
1704
|
+
if (s.name === "node_modules" || s.name === ".git" || s.name === "dist" || s.name.startsWith("."))
|
|
1705
|
+
continue;
|
|
1706
|
+
n.push(...qe(d, e, t + 1));
|
|
1707
|
+
} else if (s.name === "myop.config.json")
|
|
1708
|
+
try {
|
|
1709
|
+
const w = H.readFileSync(d, "utf-8"), M = JSON.parse(w);
|
|
1710
|
+
n.push({
|
|
1711
|
+
path: o,
|
|
1712
|
+
configPath: d,
|
|
1713
|
+
name: M.name || M.componentName || ee.basename(o),
|
|
1714
|
+
componentId: M.componentId || null,
|
|
1715
|
+
config: M
|
|
1716
|
+
});
|
|
1717
|
+
} catch {
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
} catch {
|
|
1721
|
+
}
|
|
1722
|
+
return n;
|
|
1723
|
+
};
|
|
1724
|
+
h.executionPath = process.cwd();
|
|
1725
|
+
const be = (o = !1) => {
|
|
1726
|
+
const e = h.program.getOptionValue("verbose");
|
|
1727
|
+
e || (console.info = () => {
|
|
1728
|
+
}), console.info("📝 verbose mode on"), h.options = {
|
|
1729
|
+
configPath: h.program.getOptionValue("config"),
|
|
1730
|
+
verbose: e
|
|
1375
1731
|
};
|
|
1376
1732
|
try {
|
|
1377
|
-
return
|
|
1378
|
-
} catch (
|
|
1379
|
-
if (
|
|
1733
|
+
return h.myopConfig = gt(h.options.configPath), { configFound: !0 };
|
|
1734
|
+
} catch (t) {
|
|
1735
|
+
if (o) {
|
|
1380
1736
|
console.info(`
|
|
1381
|
-
⚠️ failed read config file from ${
|
|
1737
|
+
⚠️ failed read config file from ${h.options.configPath}, trying to create new one`);
|
|
1382
1738
|
try {
|
|
1383
|
-
const
|
|
1739
|
+
const n = {
|
|
1384
1740
|
author: "@myop-cli",
|
|
1385
1741
|
flows: []
|
|
1386
1742
|
};
|
|
1387
|
-
return
|
|
1743
|
+
return Oe(h.options.configPath, n), h.myopConfig = n, { configFound: !0 };
|
|
1388
1744
|
} catch {
|
|
1389
|
-
return console.info("Error details :",
|
|
1745
|
+
return console.info("Error details :", t), { configFound: !1, error: t };
|
|
1390
1746
|
}
|
|
1391
1747
|
} else
|
|
1392
|
-
return console.info("Error details :",
|
|
1748
|
+
return console.info("Error details :", t), { configFound: !1, error: t };
|
|
1393
1749
|
}
|
|
1394
1750
|
};
|
|
1395
1751
|
[
|
|
1396
|
-
new
|
|
1397
|
-
...
|
|
1752
|
+
new Re(),
|
|
1753
|
+
...St
|
|
1398
1754
|
];
|
|
1399
|
-
const
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1755
|
+
const Wt = "0.1.22";
|
|
1756
|
+
h.program = new lt();
|
|
1757
|
+
h.program.name("@myop/cli").description("Myop CLI - Remote UI Made Easy").version(Wt);
|
|
1758
|
+
h.program.addOption(new le("-c, --config <value>", "myop.config.json file location").default("./myop.config.json", "./myop.config.json"));
|
|
1759
|
+
h.program.addOption(new le("-h, --help", "Show helpful information"));
|
|
1760
|
+
h.program.addOption(new le("-v, --verbose", "Enables verbose output mode for the command-line interface (CLI)."));
|
|
1761
|
+
h.program.addOption(new le("--ci", "CI mode: print status info (version, config, auth) as JSON and exit without prompts"));
|
|
1762
|
+
h.program.addOption(new le("-m, --monorepo", "Monorepo mode: scan for all myop.config.json files in nested directories"));
|
|
1763
|
+
h.program.command("add").description("Install Myop assets").addArgument("type").addArgument("id").action((o, e) => {
|
|
1764
|
+
be(!0), console.info("adding ", o, e, h.options.configPath), o === "flow" && Ge._action(e), process.exit();
|
|
1408
1765
|
});
|
|
1409
|
-
|
|
1410
|
-
|
|
1766
|
+
h.program.command("remove").description("Remove Myop asset").argument("<type>", "Myop asset type").argument("<id>", "Asset id").action((o, e) => {
|
|
1767
|
+
be(), console.info("removing ", o, e, h.options.configPath), o === "flow" && Ye._action(e), process.exit();
|
|
1411
1768
|
});
|
|
1412
|
-
|
|
1413
|
-
|
|
1769
|
+
h.program.command("install").description("Install Myop assets").action(async () => {
|
|
1770
|
+
be(), await Ve.action();
|
|
1414
1771
|
});
|
|
1415
|
-
|
|
1772
|
+
h.program.command("login").description("Authenticate with Myop platform").action(async () => {
|
|
1416
1773
|
try {
|
|
1417
|
-
await
|
|
1418
|
-
} catch (
|
|
1419
|
-
console.error("Login failed:",
|
|
1774
|
+
await re();
|
|
1775
|
+
} catch (o) {
|
|
1776
|
+
console.error("Login failed:", o.message), process.exit(1);
|
|
1420
1777
|
}
|
|
1421
1778
|
process.exit(0);
|
|
1422
1779
|
});
|
|
1423
|
-
|
|
1424
|
-
await
|
|
1780
|
+
h.program.command("logout").description("Clear stored credentials").action(async () => {
|
|
1781
|
+
await Xe(), process.exit(0);
|
|
1425
1782
|
});
|
|
1426
|
-
|
|
1427
|
-
const
|
|
1428
|
-
|
|
1783
|
+
h.program.command("whoami").description("Show current authenticated user").action(async () => {
|
|
1784
|
+
const o = ve();
|
|
1785
|
+
o && o.email ? console.log(`Logged in as: ${o.email}`) : console.log("Not logged in. Run `myop login` to authenticate."), process.exit(0);
|
|
1429
1786
|
});
|
|
1430
|
-
|
|
1431
|
-
var
|
|
1432
|
-
const
|
|
1433
|
-
let
|
|
1434
|
-
if (
|
|
1787
|
+
h.program.command("sync").description("Build and upload component to Myop platform").option("--skip-build", "Skip the build step").action(async (o) => {
|
|
1788
|
+
var u, v, x, $, _, D;
|
|
1789
|
+
const e = h.program.getOptionValue("config") || "./myop.config.json", t = await import("fs"), { execSync: n } = await import("child_process"), i = await import("path");
|
|
1790
|
+
let s = {};
|
|
1791
|
+
if (t.existsSync(e))
|
|
1435
1792
|
try {
|
|
1436
|
-
const
|
|
1437
|
-
|
|
1438
|
-
const
|
|
1439
|
-
console.log(`📋 Found config: ${
|
|
1440
|
-
} catch (
|
|
1441
|
-
console.error(`⚠️ Failed to parse ${
|
|
1793
|
+
const g = t.readFileSync(e, "utf-8");
|
|
1794
|
+
s = JSON.parse(g);
|
|
1795
|
+
const P = s.name || s.componentName;
|
|
1796
|
+
console.log(`📋 Found config: ${P || "Unnamed component"}`), s.componentId && console.log(` Component ID: ${s.componentId}`);
|
|
1797
|
+
} catch (g) {
|
|
1798
|
+
console.error(`⚠️ Failed to parse ${e}:`, g.message);
|
|
1442
1799
|
}
|
|
1443
1800
|
else
|
|
1444
1801
|
console.log("⚠️ No myop.config.json found. A new component will be created.");
|
|
1445
|
-
if (!
|
|
1446
|
-
const
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1802
|
+
if (!o.skipBuild) {
|
|
1803
|
+
const { exec: g } = await import("child_process");
|
|
1804
|
+
let P = { hasTriedPlatformFix: !1, hasTriedInstall: !1 };
|
|
1805
|
+
const E = (I = !1) => new Promise((L) => {
|
|
1806
|
+
const Z = W(I ? "Retrying build..." : "Building project...").start();
|
|
1807
|
+
g("npm run build", { maxBuffer: 10 * 1024 * 1024 }, async (U, O, V) => {
|
|
1808
|
+
if (!U) {
|
|
1809
|
+
Z.succeed("Build completed"), L(!0);
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
if (Z.fail("Build failed"), !P.hasTriedPlatformFix && !P.hasTriedInstall) {
|
|
1813
|
+
const R = await Ke(U, O, V, g, P);
|
|
1814
|
+
if (P = { ...P, ...R }, R.handled) {
|
|
1815
|
+
const G = await E(!0);
|
|
1816
|
+
L(G);
|
|
1817
|
+
return;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
console.error(U.message), L(!1);
|
|
1821
|
+
});
|
|
1822
|
+
});
|
|
1823
|
+
await E() || process.exit(1);
|
|
1452
1824
|
}
|
|
1453
|
-
const
|
|
1454
|
-
|
|
1825
|
+
const d = "./dist/index.html";
|
|
1826
|
+
t.existsSync(d) || (console.error("❌ Error: ./dist/index.html not found"), console.log(" Make sure your build outputs to ./dist/index.html"), process.exit(1));
|
|
1455
1827
|
let w;
|
|
1456
1828
|
try {
|
|
1457
|
-
w = await
|
|
1458
|
-
} catch (
|
|
1459
|
-
console.error("❌ Authentication failed:",
|
|
1829
|
+
w = await Dt();
|
|
1830
|
+
} catch (g) {
|
|
1831
|
+
console.error("❌ Authentication failed:", g.message), process.exit(1);
|
|
1460
1832
|
}
|
|
1461
|
-
const
|
|
1462
|
-
let m =
|
|
1833
|
+
const M = Ht();
|
|
1834
|
+
let m = W("Requesting upload URL...").start(), p;
|
|
1463
1835
|
try {
|
|
1464
|
-
const
|
|
1836
|
+
const g = await fetch(`${M}/mcp`, {
|
|
1465
1837
|
method: "POST",
|
|
1466
1838
|
headers: {
|
|
1467
1839
|
"Content-Type": "application/json",
|
|
@@ -1474,59 +1846,59 @@ d.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1474
1846
|
params: {
|
|
1475
1847
|
name: "upload_component",
|
|
1476
1848
|
arguments: {
|
|
1477
|
-
name:
|
|
1478
|
-
componentId:
|
|
1479
|
-
organization:
|
|
1849
|
+
name: s.name || s.componentName || i.default.basename(process.cwd()),
|
|
1850
|
+
componentId: s.componentId || void 0,
|
|
1851
|
+
organization: s.organization || void 0
|
|
1480
1852
|
}
|
|
1481
1853
|
}
|
|
1482
1854
|
})
|
|
1483
1855
|
});
|
|
1484
|
-
if (!
|
|
1485
|
-
throw new Error(`Server returned ${
|
|
1486
|
-
const
|
|
1487
|
-
if (
|
|
1488
|
-
throw new Error(
|
|
1489
|
-
const
|
|
1490
|
-
if (
|
|
1491
|
-
throw new Error(
|
|
1856
|
+
if (!g.ok)
|
|
1857
|
+
throw new Error(`Server returned ${g.status}`);
|
|
1858
|
+
const P = await g.json();
|
|
1859
|
+
if (P.error)
|
|
1860
|
+
throw new Error(P.error.message);
|
|
1861
|
+
const E = (x = (v = (u = P.result) == null ? void 0 : u.content) == null ? void 0 : v[0]) == null ? void 0 : x.text;
|
|
1862
|
+
if (p = JSON.parse(E), !p.success)
|
|
1863
|
+
throw new Error(p.error);
|
|
1492
1864
|
m.succeed("Upload URL obtained");
|
|
1493
|
-
} catch (
|
|
1494
|
-
m.fail("Failed to get upload URL"), console.error(" ",
|
|
1865
|
+
} catch (g) {
|
|
1866
|
+
m.fail("Failed to get upload URL"), console.error(" ", g.message), process.exit(1);
|
|
1495
1867
|
}
|
|
1496
|
-
m =
|
|
1868
|
+
m = W("Uploading component...").start();
|
|
1497
1869
|
try {
|
|
1498
|
-
const
|
|
1499
|
-
let
|
|
1500
|
-
const
|
|
1501
|
-
if (
|
|
1502
|
-
|
|
1870
|
+
const g = t.readFileSync(d, "utf-8");
|
|
1871
|
+
let P;
|
|
1872
|
+
const E = p.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
|
|
1873
|
+
if (E)
|
|
1874
|
+
P = E[1];
|
|
1503
1875
|
else {
|
|
1504
|
-
const
|
|
1505
|
-
if (
|
|
1506
|
-
|
|
1876
|
+
const I = p.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
|
|
1877
|
+
if (I)
|
|
1878
|
+
P = I[1];
|
|
1507
1879
|
else
|
|
1508
|
-
throw new Error("Could not parse presigned URL from: " +
|
|
1880
|
+
throw new Error("Could not parse presigned URL from: " + p.curlCommand);
|
|
1509
1881
|
}
|
|
1510
|
-
console.info("Uploading to:",
|
|
1511
|
-
const
|
|
1882
|
+
console.info("Uploading to:", P.substring(0, 100) + "...");
|
|
1883
|
+
const C = await fetch(P, {
|
|
1512
1884
|
method: "PUT",
|
|
1513
1885
|
headers: {
|
|
1514
1886
|
"Content-Type": "text/html"
|
|
1515
1887
|
},
|
|
1516
|
-
body:
|
|
1888
|
+
body: g
|
|
1517
1889
|
});
|
|
1518
|
-
if (!
|
|
1519
|
-
const
|
|
1520
|
-
throw new Error(`Upload failed with status ${
|
|
1890
|
+
if (!C.ok) {
|
|
1891
|
+
const I = await C.text();
|
|
1892
|
+
throw new Error(`Upload failed with status ${C.status}: ${I}`);
|
|
1521
1893
|
}
|
|
1522
1894
|
m.succeed("Component uploaded");
|
|
1523
|
-
} catch (
|
|
1524
|
-
m.fail("Upload failed"), console.error(" ",
|
|
1895
|
+
} catch (g) {
|
|
1896
|
+
m.fail("Upload failed"), console.error(" ", g.message), g.cause && console.error(" Cause:", g.cause), process.exit(1);
|
|
1525
1897
|
}
|
|
1526
|
-
m =
|
|
1898
|
+
m = W("Confirming upload...").start();
|
|
1527
1899
|
let b;
|
|
1528
1900
|
try {
|
|
1529
|
-
const
|
|
1901
|
+
const g = await fetch(`${M}/mcp`, {
|
|
1530
1902
|
method: "POST",
|
|
1531
1903
|
headers: {
|
|
1532
1904
|
"Content-Type": "application/json",
|
|
@@ -1539,116 +1911,116 @@ d.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1539
1911
|
params: {
|
|
1540
1912
|
name: "confirm_upload",
|
|
1541
1913
|
arguments: {
|
|
1542
|
-
uploadId:
|
|
1914
|
+
uploadId: p.uploadId
|
|
1543
1915
|
}
|
|
1544
1916
|
}
|
|
1545
1917
|
})
|
|
1546
1918
|
});
|
|
1547
|
-
if (!
|
|
1548
|
-
throw new Error(`Server returned ${
|
|
1549
|
-
const
|
|
1550
|
-
if (
|
|
1551
|
-
throw new Error(
|
|
1552
|
-
const
|
|
1553
|
-
if (b = JSON.parse(
|
|
1919
|
+
if (!g.ok)
|
|
1920
|
+
throw new Error(`Server returned ${g.status}`);
|
|
1921
|
+
const P = await g.json();
|
|
1922
|
+
if (P.error)
|
|
1923
|
+
throw new Error(P.error.message);
|
|
1924
|
+
const E = (D = (_ = ($ = P.result) == null ? void 0 : $.content) == null ? void 0 : _[0]) == null ? void 0 : D.text;
|
|
1925
|
+
if (b = JSON.parse(E), !b.success)
|
|
1554
1926
|
throw new Error(b.error);
|
|
1555
1927
|
m.succeed("Upload confirmed");
|
|
1556
|
-
} catch (
|
|
1557
|
-
m.fail("Confirmation failed"), console.error(" ",
|
|
1928
|
+
} catch (g) {
|
|
1929
|
+
m.fail("Confirmation failed"), console.error(" ", g.message), process.exit(1);
|
|
1558
1930
|
}
|
|
1559
|
-
if (b.isNewComponent || !
|
|
1560
|
-
|
|
1931
|
+
if (b.isNewComponent || !s.componentId) {
|
|
1932
|
+
s.componentId = b.componentId, s.organization = b.orgId, s.name || (s.name = b.componentName);
|
|
1561
1933
|
try {
|
|
1562
|
-
|
|
1563
|
-
📝 Updated ${
|
|
1564
|
-
} catch (
|
|
1934
|
+
t.writeFileSync(e, JSON.stringify(s, null, 2)), console.log(`
|
|
1935
|
+
📝 Updated ${e} with componentId`);
|
|
1936
|
+
} catch (g) {
|
|
1565
1937
|
console.log(`
|
|
1566
|
-
⚠️ Could not update ${
|
|
1938
|
+
⚠️ Could not update ${e}: ${g.message}`), console.log(` Please add componentId: "${b.componentId}" manually`);
|
|
1567
1939
|
}
|
|
1568
1940
|
}
|
|
1569
1941
|
console.log(`
|
|
1570
1942
|
✅ Sync completed successfully!`), console.log(` Component: ${b.componentName}`), console.log(` Dashboard: ${b.dashboardUrl}`), process.exit(0);
|
|
1571
1943
|
});
|
|
1572
|
-
|
|
1573
|
-
const
|
|
1944
|
+
h.program.command("dev").description("Start development server with file watching").action(Fe);
|
|
1945
|
+
const Vt = () => {
|
|
1574
1946
|
try {
|
|
1575
|
-
|
|
1947
|
+
fe("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
1576
1948
|
} catch {
|
|
1577
1949
|
return { gitNotInstalled: !0 };
|
|
1578
1950
|
}
|
|
1579
1951
|
try {
|
|
1580
|
-
|
|
1952
|
+
fe("git rev-parse --git-dir", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
1581
1953
|
} catch {
|
|
1582
1954
|
return { notARepo: !0 };
|
|
1583
1955
|
}
|
|
1584
1956
|
try {
|
|
1585
|
-
const
|
|
1957
|
+
const o = fe("git diff --stat HEAD -- . 2>/dev/null || git diff --stat -- . 2>/dev/null", {
|
|
1586
1958
|
encoding: "utf-8",
|
|
1587
1959
|
stdio: ["pipe", "pipe", "pipe"]
|
|
1588
1960
|
}).trim();
|
|
1589
|
-
if (!
|
|
1961
|
+
if (!o)
|
|
1590
1962
|
return {
|
|
1591
1963
|
files: 0,
|
|
1592
1964
|
insertions: 0,
|
|
1593
1965
|
deletions: 0
|
|
1594
1966
|
};
|
|
1595
|
-
const
|
|
1596
|
-
`),
|
|
1967
|
+
const e = o.split(`
|
|
1968
|
+
`), t = e[e.length - 1], n = t.match(/(\d+) insertion/), i = t.match(/(\d+) deletion/), s = t.match(/(\d+) file/);
|
|
1597
1969
|
return {
|
|
1598
|
-
files:
|
|
1599
|
-
insertions:
|
|
1600
|
-
deletions:
|
|
1970
|
+
files: s ? parseInt(s[1]) : 0,
|
|
1971
|
+
insertions: n ? parseInt(n[1]) : 0,
|
|
1972
|
+
deletions: i ? parseInt(i[1]) : 0
|
|
1601
1973
|
};
|
|
1602
1974
|
} catch {
|
|
1603
1975
|
return null;
|
|
1604
1976
|
}
|
|
1605
|
-
},
|
|
1606
|
-
var
|
|
1607
|
-
const
|
|
1977
|
+
}, q = async (o = !1, e = !1) => {
|
|
1978
|
+
var p, b, u;
|
|
1979
|
+
const t = ve(), n = !!(t != null && t.email), i = ((p = h.myopConfig) == null ? void 0 : p.name) || ((b = h.myopConfig) == null ? void 0 : b.componentName), s = (u = h.myopConfig) == null ? void 0 : u.componentId, d = Vt();
|
|
1608
1980
|
console.log(`
|
|
1609
1981
|
┌─────────────────────────────────────────────────┐`), console.log("│ │"), console.log("│ Welcome to Myop CLI - Remote UI Made Easy │"), console.log("│ │"), console.log(`└─────────────────────────────────────────────────┘
|
|
1610
|
-
`),
|
|
1611
|
-
const
|
|
1982
|
+
`), 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"}`), d != null && d.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")) : d != null && d.notARepo ? console.log(" Changes: Not a git repository") : d && (d.insertions > 0 || d.deletions > 0) ? console.log(` Changes: ${d.files} file${d.files !== 1 ? "s" : ""} | \x1B[32m+${d.insertions}\x1B[0m \x1B[31m-${d.deletions}\x1B[0m`) : d && console.log(" Changes: No uncommitted changes"), console.log("");
|
|
1983
|
+
const M = [
|
|
1612
1984
|
{
|
|
1613
1985
|
emoji: "🚀",
|
|
1614
1986
|
label: "Initialize new component",
|
|
1615
1987
|
value: "init",
|
|
1616
1988
|
help: "Creates myop.config.json in current directory",
|
|
1617
|
-
disabled:
|
|
1989
|
+
disabled: o ? "(config already exists)" : !1
|
|
1618
1990
|
},
|
|
1619
1991
|
{
|
|
1620
1992
|
emoji: "🛠️ ",
|
|
1621
|
-
label:
|
|
1993
|
+
label: i ? `Start dev mode for "${i}"` : "Start dev mode",
|
|
1622
1994
|
value: "dev",
|
|
1623
1995
|
help: "Starts dev server with HMR for instant preview of changes",
|
|
1624
|
-
disabled:
|
|
1996
|
+
disabled: o ? !1 : "(no config file)"
|
|
1625
1997
|
},
|
|
1626
1998
|
{
|
|
1627
1999
|
emoji: "📦",
|
|
1628
|
-
label:
|
|
2000
|
+
label: i ? `Push "${i}"` : "Push component",
|
|
1629
2001
|
value: "sync",
|
|
1630
2002
|
help: "Builds project & uploads dist/index.html to Myop",
|
|
1631
|
-
disabled:
|
|
2003
|
+
disabled: o ? n ? !1 : "(login required)" : "(no config file)"
|
|
1632
2004
|
}
|
|
1633
2005
|
].map((v) => ({
|
|
1634
|
-
name:
|
|
2006
|
+
name: e && !v.disabled ? `${v.emoji} ${v.label}
|
|
1635
2007
|
${v.help}` : `${v.emoji} ${v.label}`,
|
|
1636
2008
|
value: v.value,
|
|
1637
2009
|
disabled: v.disabled
|
|
1638
2010
|
}));
|
|
1639
|
-
|
|
1640
|
-
new
|
|
2011
|
+
M.push(
|
|
2012
|
+
new Re(),
|
|
1641
2013
|
{
|
|
1642
|
-
name:
|
|
1643
|
-
Clears stored credentials from this machine` :
|
|
1644
|
-
Opens browser to authenticate with Myop` :
|
|
1645
|
-
value:
|
|
2014
|
+
name: e && n ? `🔓 Logout (${t.email})
|
|
2015
|
+
Clears stored credentials from this machine` : e && !n ? `🔐 Login to Myop
|
|
2016
|
+
Opens browser to authenticate with Myop` : n ? `🔓 Logout (${t.email})` : "🔐 Login to Myop",
|
|
2017
|
+
value: n ? "logout" : "login"
|
|
1646
2018
|
},
|
|
1647
2019
|
{
|
|
1648
|
-
name:
|
|
2020
|
+
name: e ? "📖 Hide help" : "📖 Show help",
|
|
1649
2021
|
value: "help"
|
|
1650
2022
|
},
|
|
1651
|
-
new
|
|
2023
|
+
new Re(),
|
|
1652
2024
|
{
|
|
1653
2025
|
name: "👋 Exit",
|
|
1654
2026
|
value: "exit"
|
|
@@ -1656,9 +2028,9 @@ const Ot = () => {
|
|
|
1656
2028
|
);
|
|
1657
2029
|
let m;
|
|
1658
2030
|
try {
|
|
1659
|
-
m = await
|
|
2031
|
+
m = await Je({
|
|
1660
2032
|
message: "What would you like to do?",
|
|
1661
|
-
choices:
|
|
2033
|
+
choices: M
|
|
1662
2034
|
});
|
|
1663
2035
|
} catch (v) {
|
|
1664
2036
|
throw v.name === "ExitPromptError" && (console.log(`
|
|
@@ -1668,7 +2040,7 @@ const Ot = () => {
|
|
|
1668
2040
|
}
|
|
1669
2041
|
switch (m) {
|
|
1670
2042
|
case "init":
|
|
1671
|
-
await
|
|
2043
|
+
await Qt();
|
|
1672
2044
|
break;
|
|
1673
2045
|
case "sync":
|
|
1674
2046
|
console.log(`
|
|
@@ -1679,37 +2051,93 @@ Running sync...
|
|
|
1679
2051
|
v("node " + process.argv[1] + " sync", { stdio: "inherit" });
|
|
1680
2052
|
} catch {
|
|
1681
2053
|
}
|
|
1682
|
-
await
|
|
2054
|
+
await q(!0, e);
|
|
1683
2055
|
break;
|
|
1684
2056
|
case "dev":
|
|
1685
2057
|
await Fe();
|
|
1686
2058
|
break;
|
|
1687
2059
|
case "login":
|
|
1688
2060
|
try {
|
|
1689
|
-
await
|
|
1690
|
-
`), await
|
|
1691
|
-
} catch (
|
|
1692
|
-
console.error("Login failed:",
|
|
2061
|
+
await re(), console.log(`
|
|
2062
|
+
`), await q(o, e);
|
|
2063
|
+
} catch (x) {
|
|
2064
|
+
console.error("Login failed:", x.message), await q(o, e);
|
|
1693
2065
|
}
|
|
1694
2066
|
break;
|
|
1695
2067
|
case "logout":
|
|
1696
|
-
await
|
|
1697
|
-
`), await
|
|
2068
|
+
await Xe(), console.log(`
|
|
2069
|
+
`), await q(o, e);
|
|
1698
2070
|
break;
|
|
1699
2071
|
case "help":
|
|
1700
|
-
await
|
|
2072
|
+
await q(o, !e);
|
|
1701
2073
|
break;
|
|
1702
2074
|
case "exit":
|
|
1703
2075
|
process.exit(0);
|
|
1704
2076
|
}
|
|
1705
|
-
},
|
|
1706
|
-
const { input: e, select: n } = await import("@inquirer/prompts"), s = await import("fs"), f = (await import("path")).default.basename(process.cwd());
|
|
1707
|
-
let c, u;
|
|
2077
|
+
}, we = ".myop-monorepo.json", Gt = () => {
|
|
1708
2078
|
try {
|
|
1709
|
-
|
|
2079
|
+
const o = H.readFileSync(we, "utf-8");
|
|
2080
|
+
return JSON.parse(o);
|
|
2081
|
+
} catch {
|
|
2082
|
+
return null;
|
|
2083
|
+
}
|
|
2084
|
+
}, Yt = (o) => {
|
|
2085
|
+
try {
|
|
2086
|
+
const e = {
|
|
2087
|
+
selectedComponents: o,
|
|
2088
|
+
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
2089
|
+
};
|
|
2090
|
+
H.writeFileSync(we, JSON.stringify(e, null, 2));
|
|
2091
|
+
} catch {
|
|
2092
|
+
}
|
|
2093
|
+
}, Kt = async () => {
|
|
2094
|
+
const o = ve(), e = !!(o != null && o.email);
|
|
2095
|
+
console.log(`
|
|
2096
|
+
┌─────────────────────────────────────────────────┐`), console.log("│ │"), console.log("│ Myop CLI - Monorepo Mode │"), console.log("│ │"), console.log(`└─────────────────────────────────────────────────┘
|
|
2097
|
+
`);
|
|
2098
|
+
const t = W("Scanning for components...").start(), n = qe(".");
|
|
2099
|
+
t.stop(), n.length === 0 && (console.log(` ⚠️ No myop.config.json files found in this directory or subdirectories.
|
|
2100
|
+
`), console.log(" Run `myop` without -m flag to initialize a single component.\n"), process.exit(0));
|
|
2101
|
+
const i = Gt(), s = (i == null ? void 0 : i.selectedComponents) || [], d = s.length > 0;
|
|
2102
|
+
console.log(` Found ${n.length} component${n.length > 1 ? "s" : ""}:
|
|
2103
|
+
`), n.forEach((u, v) => {
|
|
2104
|
+
const x = u.componentId ? "✅" : "⚪", $ = u.componentId ? u.componentId.substring(0, 8) + "..." : "(not pushed)";
|
|
2105
|
+
console.log(` ${x} ${u.name}`), console.log(` Path: ${u.path}`), console.log(` ID: ${$}`), console.log("");
|
|
2106
|
+
}), console.log(` User: ${e ? o.email : "Not logged in"}`), d && console.log(` 📋 Using saved selection from ${we}`), console.log("");
|
|
2107
|
+
const { checkbox: w } = await import("@inquirer/prompts"), M = n.map((u) => ({
|
|
2108
|
+
name: `${u.name} (${u.path})`,
|
|
2109
|
+
value: u.path,
|
|
2110
|
+
checked: d ? s.includes(u.path) : !0
|
|
2111
|
+
}));
|
|
2112
|
+
let m;
|
|
2113
|
+
try {
|
|
2114
|
+
m = await w({
|
|
2115
|
+
message: "Select components to start in dev mode:",
|
|
2116
|
+
choices: M
|
|
2117
|
+
});
|
|
2118
|
+
} catch (u) {
|
|
2119
|
+
throw u.name === "ExitPromptError" && (console.log(`
|
|
2120
|
+
|
|
2121
|
+
👋 Goodbye!
|
|
2122
|
+
`), process.exit(0)), u;
|
|
2123
|
+
}
|
|
2124
|
+
m.length === 0 && (console.log(`
|
|
2125
|
+
⚠️ No components selected.
|
|
2126
|
+
`), process.exit(0)), Yt(m), console.log(`
|
|
2127
|
+
💾 Selection saved to ${we}`);
|
|
2128
|
+
const p = n.filter((u) => m.includes(u.path));
|
|
2129
|
+
console.log(`🚀 Starting dev mode for ${p.length} component${p.length > 1 ? "s" : ""}...
|
|
2130
|
+
`);
|
|
2131
|
+
const { monorepoDevCommand: b } = await Promise.resolve().then(() => Tt);
|
|
2132
|
+
await b(p);
|
|
2133
|
+
}, Qt = async () => {
|
|
2134
|
+
const { input: o, select: e } = await import("@inquirer/prompts"), t = await import("fs"), i = (await import("path")).default.basename(process.cwd());
|
|
2135
|
+
let s, d;
|
|
2136
|
+
try {
|
|
2137
|
+
s = await o({
|
|
1710
2138
|
message: "Component name:",
|
|
1711
|
-
default:
|
|
1712
|
-
}),
|
|
2139
|
+
default: i
|
|
2140
|
+
}), d = await e({
|
|
1713
2141
|
message: "Component type:",
|
|
1714
2142
|
choices: [
|
|
1715
2143
|
{ name: "📄 HTML", value: "html", description: "Plain HTML/JS/CSS component" },
|
|
@@ -1725,16 +2153,16 @@ Running sync...
|
|
|
1725
2153
|
`), process.exit(0)), m;
|
|
1726
2154
|
}
|
|
1727
2155
|
const w = {
|
|
1728
|
-
name:
|
|
1729
|
-
type:
|
|
2156
|
+
name: s,
|
|
2157
|
+
type: d,
|
|
1730
2158
|
author: "@myop-cli",
|
|
1731
2159
|
HMR: !0
|
|
1732
|
-
},
|
|
2160
|
+
}, M = h.program.getOptionValue("config") || "./myop.config.json";
|
|
1733
2161
|
try {
|
|
1734
|
-
|
|
1735
|
-
✅ Created ${
|
|
2162
|
+
t.writeFileSync(M, JSON.stringify(w, null, 2)), console.log(`
|
|
2163
|
+
✅ Created ${M}`);
|
|
1736
2164
|
const m = {
|
|
1737
|
-
name:
|
|
2165
|
+
name: s.toLowerCase().replace(/\s+/g, "-"),
|
|
1738
2166
|
version: "1.0.0",
|
|
1739
2167
|
type: "module",
|
|
1740
2168
|
scripts: {
|
|
@@ -1745,7 +2173,7 @@ Running sync...
|
|
|
1745
2173
|
esbuild: "^0.24.0"
|
|
1746
2174
|
}
|
|
1747
2175
|
};
|
|
1748
|
-
|
|
2176
|
+
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';
|
|
1749
2177
|
import fs from 'fs';
|
|
1750
2178
|
import path from 'path';
|
|
1751
2179
|
|
|
@@ -1830,20 +2258,20 @@ console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS
|
|
|
1830
2258
|
<head>
|
|
1831
2259
|
<meta charset="UTF-8">
|
|
1832
2260
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1833
|
-
<title>${
|
|
2261
|
+
<title>${s}</title>
|
|
1834
2262
|
<link rel="stylesheet" href="./src/styles/index.css">
|
|
1835
2263
|
</head>
|
|
1836
2264
|
<body>
|
|
1837
2265
|
<div id="app">
|
|
1838
|
-
<h1>${
|
|
2266
|
+
<h1>${s}</h1>
|
|
1839
2267
|
<p>Your Myop component is ready!</p>
|
|
1840
2268
|
</div>
|
|
1841
2269
|
<script type="module" src="./src/index.js"><\/script>
|
|
1842
2270
|
</body>
|
|
1843
2271
|
</html>
|
|
1844
2272
|
`;
|
|
1845
|
-
|
|
1846
|
-
const
|
|
2273
|
+
t.writeFileSync("index.html", b), console.log("✅ Created index.html");
|
|
2274
|
+
const u = `// ${s} - Entry Point
|
|
1847
2275
|
import { init } from './modules/app.js';
|
|
1848
2276
|
import { setupMyopInterface } from './modules/myop.js';
|
|
1849
2277
|
|
|
@@ -1852,16 +2280,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
1852
2280
|
setupMyopInterface();
|
|
1853
2281
|
});
|
|
1854
2282
|
`;
|
|
1855
|
-
|
|
1856
|
-
const v = `// ${
|
|
2283
|
+
t.writeFileSync("src/index.js", u), console.log("✅ Created src/index.js");
|
|
2284
|
+
const v = `// ${s} - Main Application Logic
|
|
1857
2285
|
|
|
1858
2286
|
export function init() {
|
|
1859
|
-
console.log('${
|
|
2287
|
+
console.log('${s} loaded');
|
|
1860
2288
|
|
|
1861
2289
|
// Your component logic here
|
|
1862
2290
|
}
|
|
1863
2291
|
`;
|
|
1864
|
-
|
|
2292
|
+
t.writeFileSync("src/modules/app.js", v), console.log("✅ Created src/modules/app.js"), t.writeFileSync("src/modules/myop.js", `// Myop Interface - Communication with host app
|
|
1865
2293
|
|
|
1866
2294
|
export function setupMyopInterface() {
|
|
1867
2295
|
// Called when host app sends data to this component
|
|
@@ -1877,12 +2305,12 @@ export function setupMyopInterface() {
|
|
|
1877
2305
|
};
|
|
1878
2306
|
}
|
|
1879
2307
|
`), console.log("✅ Created src/modules/myop.js");
|
|
1880
|
-
const
|
|
2308
|
+
const $ = `/* ${s} - Styles Entry Point */
|
|
1881
2309
|
/* Add your CSS imports here - they will be auto-bundled */
|
|
1882
2310
|
@import './main.css';
|
|
1883
2311
|
`;
|
|
1884
|
-
|
|
1885
|
-
const
|
|
2312
|
+
t.writeFileSync("src/styles/index.css", $), console.log("✅ Created src/styles/index.css");
|
|
2313
|
+
const _ = `/* ${s} - Main Styles */
|
|
1886
2314
|
|
|
1887
2315
|
* {
|
|
1888
2316
|
box-sizing: border-box;
|
|
@@ -1911,49 +2339,85 @@ p {
|
|
|
1911
2339
|
line-height: 1.5;
|
|
1912
2340
|
}
|
|
1913
2341
|
`;
|
|
1914
|
-
|
|
2342
|
+
t.writeFileSync("src/styles/main.css", _), console.log("✅ Created src/styles/main.css"), t.writeFileSync(".gitignore", `node_modules/
|
|
2343
|
+
dist/
|
|
2344
|
+
.temp-entry.js
|
|
2345
|
+
.temp-styles.css
|
|
2346
|
+
.DS_Store
|
|
2347
|
+
`), console.log("✅ Created .gitignore");
|
|
2348
|
+
const g = await import("./index-DuEoKctW.js").then((E) => E.i), P = process.cwd();
|
|
2349
|
+
try {
|
|
2350
|
+
await g.init({ fs: t, dir: P });
|
|
2351
|
+
const E = [
|
|
2352
|
+
"myop.config.json",
|
|
2353
|
+
"package.json",
|
|
2354
|
+
"build.js",
|
|
2355
|
+
"index.html",
|
|
2356
|
+
".gitignore",
|
|
2357
|
+
"src/index.js",
|
|
2358
|
+
"src/modules/app.js",
|
|
2359
|
+
"src/modules/myop.js",
|
|
2360
|
+
"src/styles/index.css",
|
|
2361
|
+
"src/styles/main.css"
|
|
2362
|
+
];
|
|
2363
|
+
for (const C of E)
|
|
2364
|
+
await g.add({ fs: t, dir: P, filepath: C });
|
|
2365
|
+
await g.commit({
|
|
2366
|
+
fs: t,
|
|
2367
|
+
dir: P,
|
|
2368
|
+
message: "init",
|
|
2369
|
+
author: { name: "myop-cli", email: "cli@myop.dev" }
|
|
2370
|
+
}), console.log("✅ Initialized git repository");
|
|
2371
|
+
} catch (E) {
|
|
2372
|
+
console.log("⚠️ Failed to initialize git repository:", E.message);
|
|
2373
|
+
}
|
|
2374
|
+
console.log(`
|
|
1915
2375
|
📦 Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
|
|
1916
|
-
`),
|
|
2376
|
+
`), h.myopConfig = w, await q(!0);
|
|
1917
2377
|
} catch (m) {
|
|
1918
2378
|
console.error(`Failed to initialize component: ${m.message}`), process.exit(1);
|
|
1919
2379
|
}
|
|
1920
2380
|
};
|
|
1921
|
-
|
|
1922
|
-
if (
|
|
1923
|
-
|
|
1924
|
-
|
|
2381
|
+
h.program.command("default", { isDefault: !0 }).action(async () => {
|
|
2382
|
+
if (h.program.getOptionValue("help") && (console.log(ut), process.exit()), h.program.getOptionValue("monorepo")) {
|
|
2383
|
+
await Kt();
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2386
|
+
if (h.program.getOptionValue("ci")) {
|
|
2387
|
+
const w = await import("fs"), M = h.program.getOptionValue("config") || "./myop.config.json", m = h.program.version(), p = ve();
|
|
2388
|
+
let b = { found: !1 };
|
|
1925
2389
|
try {
|
|
1926
|
-
if (
|
|
1927
|
-
const
|
|
1928
|
-
|
|
2390
|
+
if (w.existsSync(M)) {
|
|
2391
|
+
const v = w.readFileSync(M, "utf-8"), x = JSON.parse(v);
|
|
2392
|
+
b = {
|
|
1929
2393
|
found: !0,
|
|
1930
|
-
path:
|
|
1931
|
-
name:
|
|
1932
|
-
componentId:
|
|
1933
|
-
organization:
|
|
2394
|
+
path: M,
|
|
2395
|
+
name: x.name || x.componentName || null,
|
|
2396
|
+
componentId: x.componentId || null,
|
|
2397
|
+
organization: x.organization || null
|
|
1934
2398
|
};
|
|
1935
2399
|
}
|
|
1936
|
-
} catch (
|
|
1937
|
-
|
|
2400
|
+
} catch (v) {
|
|
2401
|
+
b = { found: !1, error: v.message };
|
|
1938
2402
|
}
|
|
1939
|
-
const
|
|
1940
|
-
version:
|
|
1941
|
-
config:
|
|
2403
|
+
const u = {
|
|
2404
|
+
version: m,
|
|
2405
|
+
config: b,
|
|
1942
2406
|
auth: {
|
|
1943
|
-
loggedIn: !!(
|
|
1944
|
-
email: (
|
|
2407
|
+
loggedIn: !!(p != null && p.email),
|
|
2408
|
+
email: (p == null ? void 0 : p.email) || null
|
|
1945
2409
|
}
|
|
1946
2410
|
};
|
|
1947
|
-
console.log(JSON.stringify(
|
|
2411
|
+
console.log(JSON.stringify(u, null, 2)), process.exit(0);
|
|
1948
2412
|
}
|
|
1949
|
-
let
|
|
2413
|
+
let n = W({
|
|
1950
2414
|
text: "Loading Myop CLI...",
|
|
1951
2415
|
color: "green"
|
|
1952
2416
|
}).start();
|
|
1953
|
-
const
|
|
1954
|
-
await
|
|
1955
|
-
const
|
|
1956
|
-
await
|
|
2417
|
+
const i = be();
|
|
2418
|
+
await zt(500), n.stop();
|
|
2419
|
+
const s = h.program.version();
|
|
2420
|
+
await Jt(s) || await q(i.configFound);
|
|
1957
2421
|
});
|
|
1958
|
-
|
|
1959
|
-
|
|
2422
|
+
h.program.parse(process.argv);
|
|
2423
|
+
h.program.opts();
|