@myop/cli 0.1.21 → 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/myop-cli.js +1198 -899
- package/package.json +1 -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 @@ ${n}
|
|
|
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,127 +212,144 @@ ${n}
|
|
|
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
|
}
|
|
219
|
-
function
|
|
220
|
-
return
|
|
222
|
+
function $t(o) {
|
|
223
|
+
return o.includes("esbuild") && o.includes("another platform");
|
|
221
224
|
}
|
|
222
|
-
function
|
|
223
|
-
return
|
|
225
|
+
function Ct(o) {
|
|
226
|
+
return o.includes("ERR_MODULE_NOT_FOUND") && o.includes("esbuild");
|
|
224
227
|
}
|
|
225
|
-
function
|
|
228
|
+
function Mt() {
|
|
226
229
|
console.error(`
|
|
227
230
|
❌ esbuild platform mismatch detected!`), console.error(" Your node_modules contains esbuild binaries for a different OS."), console.error(`
|
|
228
231
|
This usually happens when node_modules is copied between different`), console.error(` operating systems (e.g., Windows → Mac, or Mac → Linux).
|
|
229
232
|
`);
|
|
230
233
|
}
|
|
231
|
-
function
|
|
232
|
-
return new Promise((
|
|
234
|
+
function Pt(o) {
|
|
235
|
+
return new Promise((e) => {
|
|
233
236
|
console.log(`🔧 Attempting to fix: removing node_modules and reinstalling...
|
|
234
237
|
`);
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
if (
|
|
238
|
-
console.error("❌ Failed to remove node_modules:",
|
|
239
|
-
Please run manually:`), console.error(` \x1B[36m${
|
|
240
|
-
`),
|
|
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);
|
|
241
244
|
return;
|
|
242
245
|
}
|
|
243
246
|
console.log(" ✓ Removed node_modules"), console.log(` ⏳ Running npm install...
|
|
244
|
-
`),
|
|
245
|
-
if (
|
|
246
|
-
console.error("❌ npm install failed:",
|
|
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);
|
|
247
250
|
return;
|
|
248
251
|
}
|
|
249
252
|
console.log(` ✓ Dependencies reinstalled successfully!
|
|
250
|
-
`),
|
|
253
|
+
`), e(!0);
|
|
251
254
|
});
|
|
252
255
|
});
|
|
253
256
|
});
|
|
254
257
|
}
|
|
255
|
-
async function
|
|
258
|
+
async function Ke(o, e, t, n, i = {}) {
|
|
256
259
|
const {
|
|
257
|
-
hasTriedPlatformFix:
|
|
258
|
-
hasTriedInstall:
|
|
259
|
-
onRetry:
|
|
260
|
-
} =
|
|
261
|
-
return !
|
|
262
|
-
`),
|
|
263
|
-
|
|
264
|
-
if (
|
|
265
|
-
console.error("❌ Failed to install dependencies:",
|
|
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 });
|
|
266
269
|
return;
|
|
267
270
|
}
|
|
268
|
-
console.log("✅ Dependencies installed"),
|
|
271
|
+
console.log("✅ Dependencies installed"), w && w(), m({ handled: !0, hasTriedPlatformFix: s, hasTriedInstall: !0 });
|
|
269
272
|
});
|
|
270
|
-
})) : { handled: !1, hasTriedPlatformFix:
|
|
273
|
+
})) : { handled: !1, hasTriedPlatformFix: s, hasTriedInstall: d };
|
|
271
274
|
}
|
|
272
|
-
async function
|
|
273
|
-
const
|
|
274
|
-
let
|
|
275
|
+
async function Fe() {
|
|
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;
|
|
275
278
|
if (import.meta.url.startsWith("file://")) {
|
|
276
|
-
const
|
|
277
|
-
|
|
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);
|
|
278
281
|
} else
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
let
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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) => {
|
|
286
304
|
});
|
|
287
|
-
},
|
|
288
|
-
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();
|
|
289
309
|
try {
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
} catch (
|
|
293
|
-
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));
|
|
294
314
|
}
|
|
295
|
-
const
|
|
296
|
-
if (
|
|
297
|
-
return
|
|
315
|
+
const U = async () => {
|
|
316
|
+
if (C !== "DEV" && C !== "NEW")
|
|
317
|
+
return C;
|
|
298
318
|
try {
|
|
299
|
-
const
|
|
300
|
-
const
|
|
319
|
+
const a = ((await new Promise((f, y) => {
|
|
320
|
+
const S = {
|
|
301
321
|
hostname: "localhost",
|
|
302
|
-
port:
|
|
322
|
+
port: p,
|
|
303
323
|
path: "/_list",
|
|
304
324
|
method: "GET",
|
|
305
325
|
timeout: 1e3
|
|
306
|
-
},
|
|
307
|
-
let
|
|
308
|
-
|
|
326
|
+
}, F = n.default.request(S, (N) => {
|
|
327
|
+
let J = "";
|
|
328
|
+
N.on("data", (Q) => J += Q), N.on("end", () => {
|
|
309
329
|
try {
|
|
310
|
-
|
|
330
|
+
f(JSON.parse(J));
|
|
311
331
|
} catch {
|
|
312
|
-
|
|
332
|
+
f({ components: [] });
|
|
313
333
|
}
|
|
314
334
|
});
|
|
315
335
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}),
|
|
319
|
-
})).components || []).map(([
|
|
320
|
-
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)
|
|
321
341
|
return "DEV1";
|
|
322
|
-
const
|
|
323
|
-
if (
|
|
324
|
-
const
|
|
325
|
-
return
|
|
326
|
-
}).filter((
|
|
327
|
-
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}`;
|
|
328
348
|
} catch {
|
|
329
349
|
return "DEV1";
|
|
330
350
|
}
|
|
331
|
-
},
|
|
332
|
-
const
|
|
351
|
+
}, O = process.cwd(), V = (r) => {
|
|
352
|
+
const a = e.default.extname(r).toLowerCase();
|
|
333
353
|
return {
|
|
334
354
|
".html": "text/html",
|
|
335
355
|
".js": "text/javascript",
|
|
@@ -340,44 +360,44 @@ async function Le() {
|
|
|
340
360
|
".gif": "image/gif",
|
|
341
361
|
".svg": "image/svg+xml",
|
|
342
362
|
".ico": "image/x-icon"
|
|
343
|
-
}[
|
|
344
|
-
},
|
|
345
|
-
if (
|
|
346
|
-
const c =
|
|
347
|
-
|
|
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(
|
|
348
368
|
`HTTP/1.1 101 Switching Protocols\r
|
|
349
369
|
Upgrade: websocket\r
|
|
350
370
|
Connection: Upgrade\r
|
|
351
|
-
Sec-WebSocket-Accept: ${
|
|
371
|
+
Sec-WebSocket-Accept: ${y}\r
|
|
352
372
|
\r
|
|
353
373
|
`
|
|
354
|
-
),
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
}),
|
|
358
|
-
const
|
|
359
|
-
|
|
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);
|
|
360
380
|
});
|
|
361
381
|
}
|
|
362
|
-
},
|
|
363
|
-
if (
|
|
364
|
-
let
|
|
365
|
-
|
|
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", () => {
|
|
366
386
|
try {
|
|
367
|
-
const { componentId: c, distPath:
|
|
368
|
-
|
|
369
|
-
const
|
|
370
|
-
console.log(`✅ Registered: ${c}${
|
|
371
|
-
const
|
|
372
|
-
id:
|
|
373
|
-
path:
|
|
374
|
-
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
|
|
375
395
|
}));
|
|
376
|
-
|
|
396
|
+
K.forEach((J) => {
|
|
377
397
|
try {
|
|
378
|
-
|
|
398
|
+
J.write(`data: ${JSON.stringify({
|
|
379
399
|
type: "components",
|
|
380
|
-
components:
|
|
400
|
+
components: N
|
|
381
401
|
})}
|
|
382
402
|
|
|
383
403
|
`);
|
|
@@ -385,25 +405,25 @@ Sec-WebSocket-Accept: ${g}\r
|
|
|
385
405
|
}
|
|
386
406
|
});
|
|
387
407
|
} catch (c) {
|
|
388
|
-
|
|
408
|
+
a.writeHead(400), a.end(JSON.stringify({ error: c.message }));
|
|
389
409
|
}
|
|
390
410
|
});
|
|
391
|
-
} else if (
|
|
392
|
-
let
|
|
393
|
-
|
|
411
|
+
} else if (r.method === "POST" && r.url === "/_unregister") {
|
|
412
|
+
let l = "";
|
|
413
|
+
r.on("data", (c) => l += c), r.on("end", () => {
|
|
394
414
|
try {
|
|
395
|
-
const { componentId: c } = JSON.parse(
|
|
396
|
-
|
|
397
|
-
const
|
|
398
|
-
id:
|
|
399
|
-
path:
|
|
400
|
-
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
|
|
401
421
|
}));
|
|
402
|
-
|
|
422
|
+
K.forEach((y) => {
|
|
403
423
|
try {
|
|
404
|
-
|
|
424
|
+
y.write(`data: ${JSON.stringify({
|
|
405
425
|
type: "components",
|
|
406
|
-
components:
|
|
426
|
+
components: f
|
|
407
427
|
})}
|
|
408
428
|
|
|
409
429
|
`);
|
|
@@ -411,82 +431,82 @@ Sec-WebSocket-Accept: ${g}\r
|
|
|
411
431
|
}
|
|
412
432
|
});
|
|
413
433
|
} catch (c) {
|
|
414
|
-
|
|
434
|
+
a.writeHead(400), a.end(JSON.stringify({ error: c.message }));
|
|
415
435
|
}
|
|
416
436
|
});
|
|
417
|
-
} else
|
|
418
|
-
}),
|
|
419
|
-
if (
|
|
420
|
-
|
|
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");
|
|
421
441
|
return;
|
|
422
442
|
}
|
|
423
|
-
const
|
|
443
|
+
const l = new URL(r.url, `http://localhost:${m}`), c = l.pathname, f = c.split("/").filter((A) => A);
|
|
424
444
|
if (c.startsWith("/consume")) {
|
|
425
|
-
const
|
|
426
|
-
if (!
|
|
427
|
-
|
|
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>" }));
|
|
428
448
|
return;
|
|
429
449
|
}
|
|
430
|
-
const
|
|
431
|
-
let
|
|
432
|
-
if (
|
|
433
|
-
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;
|
|
434
454
|
try {
|
|
435
|
-
const
|
|
436
|
-
|
|
455
|
+
const ne = new URL(k);
|
|
456
|
+
j = ne.origin, z = ne.hostname || ne.origin;
|
|
437
457
|
} catch {
|
|
438
|
-
|
|
458
|
+
j = k, z = k;
|
|
439
459
|
}
|
|
440
|
-
} else if (
|
|
460
|
+
} else if (r.headers.origin)
|
|
441
461
|
try {
|
|
442
|
-
const
|
|
443
|
-
|
|
462
|
+
const k = new URL(r.headers.origin);
|
|
463
|
+
j = k.origin, z = k.hostname || k.origin;
|
|
444
464
|
} catch {
|
|
445
|
-
|
|
465
|
+
j = r.headers.origin, z = r.headers.origin;
|
|
446
466
|
}
|
|
447
|
-
else if (
|
|
448
|
-
const
|
|
449
|
-
|
|
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:", ""));
|
|
450
470
|
}
|
|
451
|
-
const
|
|
471
|
+
const Me = r.headers.referer || r.headers.referrer || j, me = {
|
|
452
472
|
type: "request",
|
|
453
|
-
componentId:
|
|
473
|
+
componentId: A,
|
|
454
474
|
timestamp: Date.now(),
|
|
455
|
-
servedLocally:
|
|
456
|
-
referrer:
|
|
457
|
-
origin:
|
|
458
|
-
originLabel:
|
|
475
|
+
servedLocally: oe,
|
|
476
|
+
referrer: Me,
|
|
477
|
+
origin: j,
|
|
478
|
+
originLabel: z
|
|
459
479
|
};
|
|
460
|
-
|
|
461
|
-
url:
|
|
462
|
-
label:
|
|
480
|
+
te.has(j) || (te.set(j, {
|
|
481
|
+
url: j,
|
|
482
|
+
label: z,
|
|
463
483
|
firstSeen: Date.now(),
|
|
464
484
|
requestCount: 0
|
|
465
|
-
}),
|
|
485
|
+
}), K.forEach((k) => {
|
|
466
486
|
try {
|
|
467
|
-
|
|
487
|
+
k.write(`data: ${JSON.stringify({
|
|
468
488
|
type: "origins",
|
|
469
|
-
origins: Array.from(
|
|
489
|
+
origins: Array.from(te.values())
|
|
470
490
|
})}
|
|
471
491
|
|
|
472
492
|
`);
|
|
473
493
|
} catch {
|
|
474
494
|
}
|
|
475
495
|
}));
|
|
476
|
-
const
|
|
477
|
-
|
|
496
|
+
const Pe = te.get(j);
|
|
497
|
+
Pe.requestCount++, K.forEach((k) => {
|
|
478
498
|
try {
|
|
479
|
-
|
|
499
|
+
k.write(`data: ${JSON.stringify({
|
|
480
500
|
type: "origins",
|
|
481
|
-
origins: Array.from(
|
|
501
|
+
origins: Array.from(te.values())
|
|
482
502
|
})}
|
|
483
503
|
|
|
484
504
|
`);
|
|
485
505
|
} catch {
|
|
486
506
|
}
|
|
487
|
-
}),
|
|
507
|
+
}), G.push(me), G.length > Se && G.shift(), K.forEach((k) => {
|
|
488
508
|
try {
|
|
489
|
-
|
|
509
|
+
k.write(`data: ${JSON.stringify(me)}
|
|
490
510
|
|
|
491
511
|
`);
|
|
492
512
|
} catch {
|
|
@@ -494,151 +514,152 @@ Sec-WebSocket-Accept: ${g}\r
|
|
|
494
514
|
});
|
|
495
515
|
};
|
|
496
516
|
if (Y) {
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
if (
|
|
500
|
-
console.log(`❌ File not found: ${
|
|
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" }));
|
|
501
521
|
return;
|
|
502
522
|
}
|
|
503
|
-
const
|
|
523
|
+
const Me = _e(z, A), me = `dev-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, Pe = {
|
|
504
524
|
item: {
|
|
505
|
-
name:
|
|
506
|
-
id:
|
|
525
|
+
name: A,
|
|
526
|
+
id: A,
|
|
507
527
|
consume_variant: [
|
|
508
528
|
{
|
|
509
|
-
id:
|
|
529
|
+
id: me,
|
|
510
530
|
name: "dev version",
|
|
511
531
|
loader: {
|
|
512
532
|
type: "HTMLLoader",
|
|
513
533
|
shadowRootMode: "localFrame",
|
|
514
|
-
HTML:
|
|
534
|
+
HTML: Me
|
|
515
535
|
}
|
|
516
536
|
}
|
|
517
537
|
]
|
|
518
538
|
}
|
|
519
539
|
};
|
|
520
|
-
console.log(`✅ Serving consume JSON for: ${
|
|
540
|
+
console.log(`✅ Serving consume JSON for: ${A}`), Be(!0), a.writeHead(200, {
|
|
521
541
|
"Content-Type": "application/json",
|
|
522
542
|
"Access-Control-Allow-Origin": "*"
|
|
523
|
-
}),
|
|
543
|
+
}), a.end(JSON.stringify(Pe, null, 2));
|
|
524
544
|
});
|
|
525
545
|
} else {
|
|
526
|
-
console.log(`📡 Proxying consume request to cloud.myop.dev for: ${
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
|
|
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, {
|
|
530
550
|
"Content-Type": "application/json",
|
|
531
551
|
"Access-Control-Allow-Origin": "*"
|
|
532
|
-
}),
|
|
533
|
-
}).catch((
|
|
534
|
-
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" }));
|
|
535
555
|
});
|
|
536
556
|
}
|
|
537
557
|
return;
|
|
538
558
|
}
|
|
539
559
|
if (c === "/events") {
|
|
540
|
-
|
|
560
|
+
a.writeHead(200, {
|
|
541
561
|
"Content-Type": "text/event-stream",
|
|
542
562
|
"Cache-Control": "no-cache",
|
|
543
563
|
Connection: "keep-alive",
|
|
544
564
|
"Access-Control-Allow-Origin": "*"
|
|
545
|
-
}),
|
|
546
|
-
const
|
|
547
|
-
id:
|
|
565
|
+
}), K.push(a);
|
|
566
|
+
const A = Array.from(R.entries()).map(([B, Y]) => ({
|
|
567
|
+
id: B,
|
|
548
568
|
path: Y.path,
|
|
549
569
|
name: Y.name
|
|
550
570
|
}));
|
|
551
|
-
|
|
571
|
+
a.write(`data: ${JSON.stringify({
|
|
552
572
|
type: "components",
|
|
553
|
-
components:
|
|
573
|
+
components: A
|
|
554
574
|
})}
|
|
555
575
|
|
|
556
|
-
`),
|
|
576
|
+
`), a.write(`data: ${JSON.stringify({
|
|
557
577
|
type: "origins",
|
|
558
|
-
origins: Array.from(
|
|
578
|
+
origins: Array.from(te.values())
|
|
559
579
|
})}
|
|
560
580
|
|
|
561
|
-
`),
|
|
581
|
+
`), a.write(`data: ${JSON.stringify({
|
|
562
582
|
type: "requestLog",
|
|
563
|
-
log:
|
|
583
|
+
log: G
|
|
564
584
|
})}
|
|
565
585
|
|
|
566
|
-
`),
|
|
567
|
-
const
|
|
568
|
-
|
|
586
|
+
`), r.on("close", () => {
|
|
587
|
+
const B = K.indexOf(a);
|
|
588
|
+
B !== -1 && K.splice(B, 1);
|
|
569
589
|
});
|
|
570
590
|
return;
|
|
571
591
|
}
|
|
572
|
-
if (
|
|
573
|
-
|
|
592
|
+
if (f.length === 0) {
|
|
593
|
+
a.writeHead(200, { "Content-Type": "text/html" }), a.end(xt(m, p, w, M));
|
|
574
594
|
return;
|
|
575
595
|
}
|
|
576
|
-
if (
|
|
577
|
-
|
|
596
|
+
if (f[0] !== "view") {
|
|
597
|
+
a.writeHead(404, { "Content-Type": "text/plain" }), a.end("Not found. Use /view/<componentId>/ to access components.");
|
|
578
598
|
return;
|
|
579
599
|
}
|
|
580
|
-
if (
|
|
581
|
-
|
|
600
|
+
if (f.length < 2) {
|
|
601
|
+
a.writeHead(400, { "Content-Type": "text/plain" }), a.end("Component ID required. Use /view/<componentId>/");
|
|
582
602
|
return;
|
|
583
603
|
}
|
|
584
|
-
const
|
|
585
|
-
if (!
|
|
586
|
-
|
|
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}`);
|
|
587
607
|
return;
|
|
588
608
|
}
|
|
589
|
-
const
|
|
590
|
-
console.log(`📥 Request: ${
|
|
591
|
-
if (
|
|
592
|
-
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");
|
|
593
613
|
return;
|
|
594
614
|
}
|
|
595
|
-
const Y =
|
|
596
|
-
console.log(`✅ Serving: ${
|
|
615
|
+
const Y = V(ie);
|
|
616
|
+
console.log(`✅ Serving: ${ie} (${Y})`), a.writeHead(200, {
|
|
597
617
|
"Content-Type": Y,
|
|
598
618
|
"Access-Control-Allow-Origin": "*"
|
|
599
|
-
}),
|
|
619
|
+
}), a.end(B);
|
|
600
620
|
});
|
|
601
|
-
}),
|
|
602
|
-
const
|
|
603
|
-
componentId:
|
|
604
|
-
distPath:
|
|
605
|
-
componentName:
|
|
606
|
-
|
|
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 = {
|
|
607
628
|
hostname: "localhost",
|
|
608
|
-
port:
|
|
629
|
+
port: p,
|
|
609
630
|
path: "/_register",
|
|
610
631
|
method: "POST",
|
|
611
632
|
headers: {
|
|
612
633
|
"Content-Type": "application/json",
|
|
613
|
-
"Content-Length": Buffer.byteLength(
|
|
634
|
+
"Content-Length": Buffer.byteLength(c)
|
|
614
635
|
}
|
|
615
|
-
},
|
|
616
|
-
let
|
|
617
|
-
|
|
618
|
-
|
|
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}`));
|
|
619
640
|
});
|
|
620
641
|
});
|
|
621
|
-
|
|
622
|
-
}),
|
|
623
|
-
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 = {
|
|
624
645
|
hostname: "localhost",
|
|
625
|
-
port:
|
|
646
|
+
port: p,
|
|
626
647
|
path: "/_unregister",
|
|
627
648
|
method: "POST",
|
|
628
649
|
headers: {
|
|
629
650
|
"Content-Type": "application/json",
|
|
630
|
-
"Content-Length": Buffer.byteLength(
|
|
651
|
+
"Content-Length": Buffer.byteLength(l)
|
|
631
652
|
}
|
|
632
|
-
},
|
|
633
|
-
|
|
653
|
+
}, f = n.default.request(c, (y) => {
|
|
654
|
+
r();
|
|
634
655
|
});
|
|
635
|
-
|
|
636
|
-
}),
|
|
656
|
+
f.on("error", () => r()), f.write(l), f.end();
|
|
657
|
+
}), ot = (r) => `
|
|
637
658
|
<!-- MYOP HMR -->
|
|
638
659
|
<script>
|
|
639
660
|
(function() {
|
|
640
|
-
const componentId = '${
|
|
641
|
-
const wsUrl = 'ws://localhost:${
|
|
661
|
+
const componentId = '${r}';
|
|
662
|
+
const wsUrl = 'ws://localhost:${p}/_hmr/' + componentId;
|
|
642
663
|
let ws;
|
|
643
664
|
let reconnectAttempts = 0;
|
|
644
665
|
const maxReconnectAttempts = 10;
|
|
@@ -738,278 +759,536 @@ Sec-WebSocket-Accept: ${g}\r
|
|
|
738
759
|
connect();
|
|
739
760
|
})();
|
|
740
761
|
<\/script>
|
|
741
|
-
`,
|
|
742
|
-
if (!
|
|
743
|
-
const
|
|
744
|
-
return
|
|
745
|
-
},
|
|
746
|
-
const
|
|
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;
|
|
747
768
|
let c;
|
|
748
|
-
return
|
|
749
|
-
Buffer.from([129,
|
|
769
|
+
return l < 126 ? c = Buffer.concat([
|
|
770
|
+
Buffer.from([129, l]),
|
|
750
771
|
// FIN + text frame, length
|
|
751
|
-
|
|
752
|
-
]) :
|
|
772
|
+
a
|
|
773
|
+
]) : l < 65536 ? c = Buffer.concat([
|
|
753
774
|
Buffer.from([129, 126]),
|
|
754
775
|
// FIN + text frame, extended length
|
|
755
|
-
Buffer.from([
|
|
776
|
+
Buffer.from([l >> 8, l & 255]),
|
|
756
777
|
// 16-bit length
|
|
757
|
-
|
|
778
|
+
a
|
|
758
779
|
]) : c = Buffer.concat([
|
|
759
780
|
Buffer.from([129, 127]),
|
|
760
781
|
// FIN + text frame, extended length
|
|
761
|
-
Buffer.from([0, 0, 0, 0,
|
|
782
|
+
Buffer.from([0, 0, 0, 0, l >> 24, l >> 16 & 255, l >> 8 & 255, l & 255]),
|
|
762
783
|
// 64-bit length
|
|
763
|
-
|
|
784
|
+
a
|
|
764
785
|
]), c;
|
|
765
|
-
},
|
|
766
|
-
if (!
|
|
767
|
-
const
|
|
768
|
-
if (!
|
|
786
|
+
}, Le = () => {
|
|
787
|
+
if (!L) return;
|
|
788
|
+
const r = X.get(C);
|
|
789
|
+
if (!r || r.size === 0)
|
|
769
790
|
return;
|
|
770
|
-
console.log(`🔥 Notifying ${
|
|
771
|
-
const
|
|
791
|
+
console.log(`🔥 Notifying ${r.size} HMR client(s)`);
|
|
792
|
+
const a = x ? $ : e.default.join(b, "index.html");
|
|
772
793
|
try {
|
|
773
|
-
const
|
|
794
|
+
const l = o.default.readFileSync(a, "utf-8"), c = _e(l, C), f = JSON.stringify({
|
|
774
795
|
type: "update",
|
|
775
796
|
html: c
|
|
776
|
-
}),
|
|
777
|
-
|
|
797
|
+
}), y = nt(f);
|
|
798
|
+
r.forEach((S) => {
|
|
778
799
|
try {
|
|
779
|
-
|
|
800
|
+
S.write(y);
|
|
780
801
|
} catch {
|
|
781
|
-
|
|
802
|
+
r.delete(S);
|
|
782
803
|
}
|
|
783
804
|
});
|
|
784
|
-
} catch (
|
|
785
|
-
console.error("❌ Failed to read HTML for HMR:",
|
|
805
|
+
} catch (l) {
|
|
806
|
+
console.error("❌ Failed to read HTML for HMR:", l.message);
|
|
786
807
|
}
|
|
787
808
|
};
|
|
788
|
-
let
|
|
789
|
-
const
|
|
790
|
-
if (
|
|
791
|
-
|
|
809
|
+
let $e = { hasTriedPlatformFix: !1, hasTriedInstall: !1 };
|
|
810
|
+
const de = (r) => {
|
|
811
|
+
if (u) {
|
|
812
|
+
v = !0;
|
|
792
813
|
return;
|
|
793
814
|
}
|
|
794
|
-
|
|
795
|
-
🔨 Building...`),
|
|
796
|
-
if (
|
|
797
|
-
const
|
|
798
|
-
|
|
799
|
-
onRetry: () =>
|
|
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)
|
|
800
821
|
});
|
|
801
|
-
|
|
822
|
+
$e = { ...$e, ...f }, f.handled || (console.error("❌ Build failed:", a.message), c && console.error(c));
|
|
802
823
|
} else
|
|
803
|
-
console.log("✅ Build completed"),
|
|
804
|
-
|
|
824
|
+
console.log("✅ Build completed"), l && console.log(l), Le(), r && r();
|
|
825
|
+
v && (v = !1, de());
|
|
805
826
|
});
|
|
806
|
-
},
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
const
|
|
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);
|
|
810
831
|
if (c.isDirectory())
|
|
811
|
-
c.name !== "node_modules" && c.name !== "dist" && !c.name.startsWith(".") &&
|
|
832
|
+
c.name !== "node_modules" && c.name !== "dist" && !c.name.startsWith(".") && Ce(f);
|
|
812
833
|
else if (c.isFile()) {
|
|
813
|
-
const
|
|
814
|
-
if (
|
|
834
|
+
const y = e.default.extname(c.name);
|
|
835
|
+
if (y === ".js" || y === ".css" || y === ".html")
|
|
815
836
|
try {
|
|
816
|
-
const
|
|
817
|
-
|
|
837
|
+
const S = o.default.readFileSync(f, "utf-8");
|
|
838
|
+
P.set(f, S);
|
|
818
839
|
} catch {
|
|
819
840
|
}
|
|
820
841
|
}
|
|
821
|
-
}),
|
|
822
|
-
if (!
|
|
823
|
-
const
|
|
824
|
-
if (
|
|
825
|
-
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);
|
|
826
847
|
setTimeout(() => {
|
|
827
848
|
try {
|
|
828
|
-
const
|
|
829
|
-
|
|
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());
|
|
830
851
|
} catch {
|
|
831
852
|
}
|
|
832
853
|
}, 50);
|
|
833
854
|
})));
|
|
834
855
|
});
|
|
835
|
-
},
|
|
856
|
+
}, De = (r) => {
|
|
836
857
|
console.log(`
|
|
837
|
-
🔨 Component: ${
|
|
838
|
-
`)
|
|
839
|
-
|
|
840
|
-
|
|
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 = {
|
|
841
863
|
hostname: "localhost",
|
|
842
|
-
port:
|
|
864
|
+
port: p,
|
|
843
865
|
path: "/_list",
|
|
844
866
|
method: "GET",
|
|
845
867
|
timeout: 1e3
|
|
846
|
-
},
|
|
847
|
-
|
|
868
|
+
}, l = n.default.request(a, (c) => {
|
|
869
|
+
r(!0);
|
|
848
870
|
});
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
}),
|
|
852
|
-
}),
|
|
853
|
-
const
|
|
854
|
-
if (c.setHeader("Content-Type", "application/json"),
|
|
855
|
-
let
|
|
856
|
-
|
|
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", () => {
|
|
857
879
|
try {
|
|
858
|
-
const { componentId:
|
|
859
|
-
|
|
860
|
-
const
|
|
861
|
-
console.log(`✅ Registered: ${
|
|
862
|
-
} catch (
|
|
863
|
-
c.writeHead(400), c.end(JSON.stringify({ error:
|
|
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 }));
|
|
864
886
|
}
|
|
865
887
|
});
|
|
866
|
-
} else if (
|
|
867
|
-
let
|
|
868
|
-
|
|
888
|
+
} else if (l.method === "POST" && l.url === "/_unregister") {
|
|
889
|
+
let f = "";
|
|
890
|
+
l.on("data", (y) => f += y), l.on("end", () => {
|
|
869
891
|
try {
|
|
870
|
-
const { componentId:
|
|
871
|
-
|
|
872
|
-
} catch (
|
|
873
|
-
c.writeHead(400), c.end(JSON.stringify({ error:
|
|
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 }));
|
|
874
896
|
}
|
|
875
897
|
});
|
|
876
|
-
} 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" })));
|
|
877
899
|
});
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
}),
|
|
900
|
+
a.on("error", () => {
|
|
901
|
+
r(!1);
|
|
902
|
+
}), a.listen(p, () => {
|
|
881
903
|
console.log(`
|
|
882
|
-
🔄 Taking over as server...`), console.log(`📡 Management server on port ${
|
|
883
|
-
|
|
884
|
-
}),
|
|
885
|
-
console.log(`📡 Main server running at http://localhost:${
|
|
886
|
-
|
|
887
|
-
|
|
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
|
|
888
913
|
});
|
|
889
|
-
const
|
|
890
|
-
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);
|
|
891
916
|
});
|
|
892
917
|
});
|
|
893
918
|
});
|
|
894
|
-
let
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
await
|
|
898
|
-
⚠️ 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 () => {
|
|
899
924
|
try {
|
|
900
|
-
await
|
|
901
|
-
} catch (
|
|
902
|
-
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);
|
|
903
928
|
}
|
|
904
929
|
}, 2e3)));
|
|
905
930
|
}, 3e3);
|
|
906
|
-
},
|
|
931
|
+
}, Ue = async () => {
|
|
907
932
|
console.log(`
|
|
908
933
|
|
|
909
|
-
🛑 Shutting down...`),
|
|
934
|
+
🛑 Shutting down...`), pe && clearInterval(pe), await tt(), process.exit(0);
|
|
910
935
|
};
|
|
911
|
-
process.on("SIGINT",
|
|
912
|
-
if (
|
|
936
|
+
process.on("SIGINT", Ue), process.on("SIGTERM", Ue), xe.on("error", async (r) => {
|
|
937
|
+
if (r.code === "EADDRINUSE") {
|
|
913
938
|
console.log(`
|
|
914
939
|
🔗 Connecting to existing dev server...`);
|
|
915
940
|
try {
|
|
916
|
-
|
|
917
|
-
const
|
|
918
|
-
console.log(`✅ Registered component: ${
|
|
919
|
-
|
|
920
|
-
}),
|
|
921
|
-
} catch (
|
|
922
|
-
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);
|
|
923
948
|
}
|
|
924
949
|
} else
|
|
925
|
-
console.error("❌ Management server error:",
|
|
926
|
-
}),
|
|
950
|
+
console.error("❌ Management server error:", r.message), process.exit(1);
|
|
951
|
+
}), xe.on("upgrade", et), xe.listen(p, async () => {
|
|
927
952
|
console.log(`
|
|
928
|
-
🚀 Starting shared dev server...`), console.log(`📡 Management server on port ${
|
|
929
|
-
console.error("❌ Main server error:",
|
|
930
|
-
}),
|
|
931
|
-
console.log(`📡 Main server running at http://localhost:${
|
|
932
|
-
|
|
933
|
-
|
|
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
|
|
934
962
|
});
|
|
935
|
-
const
|
|
936
|
-
console.log(`✅ Registered component: ${
|
|
937
|
-
|
|
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}/`);
|
|
938
966
|
});
|
|
939
967
|
});
|
|
940
968
|
});
|
|
941
969
|
}
|
|
942
|
-
const
|
|
943
|
-
|
|
944
|
-
|
|
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);
|
|
945
1216
|
}
|
|
946
|
-
|
|
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() {
|
|
947
1226
|
try {
|
|
948
|
-
if (!
|
|
1227
|
+
if (!H.existsSync(ae))
|
|
949
1228
|
return null;
|
|
950
|
-
const
|
|
951
|
-
return JSON.parse(
|
|
952
|
-
} catch (
|
|
953
|
-
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;
|
|
954
1233
|
}
|
|
955
1234
|
}
|
|
956
|
-
function
|
|
957
|
-
|
|
958
|
-
const
|
|
959
|
-
...
|
|
1235
|
+
function Qe(o) {
|
|
1236
|
+
Et();
|
|
1237
|
+
const e = {
|
|
1238
|
+
...o,
|
|
960
1239
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
961
1240
|
};
|
|
962
|
-
|
|
1241
|
+
H.writeFileSync(ae, JSON.stringify(e, null, 2), {
|
|
963
1242
|
mode: 384
|
|
964
1243
|
// Read/write for owner only
|
|
965
1244
|
});
|
|
966
1245
|
}
|
|
967
|
-
function
|
|
1246
|
+
function Ze() {
|
|
968
1247
|
try {
|
|
969
|
-
return
|
|
970
|
-
} catch (
|
|
971
|
-
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;
|
|
972
1251
|
}
|
|
973
1252
|
}
|
|
974
|
-
function
|
|
975
|
-
if (!
|
|
1253
|
+
function It(o) {
|
|
1254
|
+
if (!o || !o.expiresAt)
|
|
976
1255
|
return !0;
|
|
977
|
-
const
|
|
978
|
-
return Date.now() >
|
|
1256
|
+
const e = 5 * 60 * 1e3, t = new Date(o.expiresAt).getTime();
|
|
1257
|
+
return Date.now() > t - e;
|
|
979
1258
|
}
|
|
980
|
-
function
|
|
981
|
-
const
|
|
982
|
-
return
|
|
983
|
-
email:
|
|
984
|
-
userId:
|
|
1259
|
+
function ve() {
|
|
1260
|
+
const o = je();
|
|
1261
|
+
return o ? {
|
|
1262
|
+
email: o.userEmail,
|
|
1263
|
+
userId: o.userId
|
|
985
1264
|
} : null;
|
|
986
1265
|
}
|
|
987
|
-
const
|
|
988
|
-
function
|
|
989
|
-
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");
|
|
990
1269
|
}
|
|
991
|
-
function
|
|
992
|
-
return
|
|
1270
|
+
function jt(o) {
|
|
1271
|
+
return Ie.createHash("sha256").update(o).digest("base64url");
|
|
993
1272
|
}
|
|
994
|
-
async function
|
|
995
|
-
const
|
|
1273
|
+
async function kt() {
|
|
1274
|
+
const o = await fetch(`${se}/oauth/register`, {
|
|
996
1275
|
method: "POST",
|
|
997
1276
|
headers: { "Content-Type": "application/json" },
|
|
998
1277
|
body: JSON.stringify({
|
|
999
|
-
client_name:
|
|
1000
|
-
redirect_uris: [
|
|
1278
|
+
client_name: Ot,
|
|
1279
|
+
redirect_uris: [ke],
|
|
1001
1280
|
grant_types: ["authorization_code", "refresh_token"],
|
|
1002
1281
|
response_types: ["code"]
|
|
1003
1282
|
})
|
|
1004
1283
|
});
|
|
1005
|
-
if (!
|
|
1006
|
-
const
|
|
1007
|
-
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}`);
|
|
1008
1287
|
}
|
|
1009
|
-
return
|
|
1288
|
+
return o.json();
|
|
1010
1289
|
}
|
|
1011
|
-
function
|
|
1012
|
-
const
|
|
1290
|
+
function ge(o, e, t, n = null) {
|
|
1291
|
+
const i = {
|
|
1013
1292
|
success: `<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="#4ade80" stroke-width="2">
|
|
1014
1293
|
<circle cx="12" cy="12" r="10"/>
|
|
1015
1294
|
<path d="M8 12l2.5 2.5L16 9"/>
|
|
@@ -1022,17 +1301,17 @@ function ie(e, t, n, r = null) {
|
|
|
1022
1301
|
<path d="M12 2L2 22h20L12 2z"/>
|
|
1023
1302
|
<path d="M12 9v4M12 17h.01"/>
|
|
1024
1303
|
</svg>`
|
|
1025
|
-
},
|
|
1304
|
+
}, s = {
|
|
1026
1305
|
success: { accent: "#4ade80", glow: "rgba(74, 222, 128, 0.1)" },
|
|
1027
1306
|
error: { accent: "#f87171", glow: "rgba(248, 113, 113, 0.1)" },
|
|
1028
1307
|
warning: { accent: "#fbbf24", glow: "rgba(251, 191, 36, 0.1)" }
|
|
1029
|
-
}, { accent:
|
|
1308
|
+
}, { accent: d, glow: w } = s[o] || s.error;
|
|
1030
1309
|
return `<!DOCTYPE html>
|
|
1031
1310
|
<html lang="en">
|
|
1032
1311
|
<head>
|
|
1033
1312
|
<meta charset="UTF-8">
|
|
1034
1313
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1035
|
-
<title>myop-cli | ${
|
|
1314
|
+
<title>myop-cli | ${e}</title>
|
|
1036
1315
|
<style>
|
|
1037
1316
|
* {
|
|
1038
1317
|
margin: 0;
|
|
@@ -1087,7 +1366,7 @@ function ie(e, t, n, r = null) {
|
|
|
1087
1366
|
h1 {
|
|
1088
1367
|
font-size: 20px;
|
|
1089
1368
|
font-weight: 500;
|
|
1090
|
-
color: ${
|
|
1369
|
+
color: ${d};
|
|
1091
1370
|
margin-bottom: 12px;
|
|
1092
1371
|
letter-spacing: -0.5px;
|
|
1093
1372
|
}
|
|
@@ -1119,8 +1398,8 @@ function ie(e, t, n, r = null) {
|
|
|
1119
1398
|
display: inline-flex;
|
|
1120
1399
|
align-items: center;
|
|
1121
1400
|
gap: 8px;
|
|
1122
|
-
background: ${
|
|
1123
|
-
border: 1px solid ${
|
|
1401
|
+
background: ${w};
|
|
1402
|
+
border: 1px solid ${d}33;
|
|
1124
1403
|
border-radius: 4px;
|
|
1125
1404
|
padding: 10px 16px;
|
|
1126
1405
|
font-size: 12px;
|
|
@@ -1157,11 +1436,11 @@ function ie(e, t, n, r = null) {
|
|
|
1157
1436
|
<body>
|
|
1158
1437
|
<div class="container">
|
|
1159
1438
|
<div class="icon">
|
|
1160
|
-
${
|
|
1439
|
+
${i[o] || i.error}
|
|
1161
1440
|
</div>
|
|
1162
|
-
<h1>${
|
|
1163
|
-
<p class="message">${
|
|
1164
|
-
${
|
|
1441
|
+
<h1>${e}</h1>
|
|
1442
|
+
<p class="message">${t}</p>
|
|
1443
|
+
${n ? `<div class="details"><code>Error:</code> ${n}</div>` : ""}
|
|
1165
1444
|
<div class="hint">
|
|
1166
1445
|
<span>Press</span>
|
|
1167
1446
|
<kbd>⌘</kbd><kbd>W</kbd>
|
|
@@ -1174,95 +1453,95 @@ function ie(e, t, n, r = null) {
|
|
|
1174
1453
|
</body>
|
|
1175
1454
|
</html>`;
|
|
1176
1455
|
}
|
|
1177
|
-
function
|
|
1178
|
-
return new Promise((
|
|
1179
|
-
const
|
|
1180
|
-
const
|
|
1181
|
-
if (
|
|
1182
|
-
const
|
|
1183
|
-
if (
|
|
1184
|
-
|
|
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");
|
|
1462
|
+
if (m) {
|
|
1463
|
+
s.writeHead(200, { "Content-Type": "text/html" }), s.end(ge(
|
|
1185
1464
|
"error",
|
|
1186
1465
|
"Authentication Failed",
|
|
1187
1466
|
"Unable to complete the authentication process.",
|
|
1188
|
-
|
|
1189
|
-
)),
|
|
1467
|
+
m
|
|
1468
|
+
)), n.close(), t(new Error(`OAuth error: ${m}`));
|
|
1190
1469
|
return;
|
|
1191
1470
|
}
|
|
1192
|
-
if (
|
|
1193
|
-
|
|
1471
|
+
if (M !== o) {
|
|
1472
|
+
s.writeHead(400, { "Content-Type": "text/html" }), s.end(ge(
|
|
1194
1473
|
"warning",
|
|
1195
1474
|
"Security Error",
|
|
1196
1475
|
"State mismatch detected. This could indicate a CSRF attack. Please try authenticating again.",
|
|
1197
1476
|
"state_mismatch"
|
|
1198
|
-
)),
|
|
1477
|
+
)), n.close(), t(new Error("State mismatch"));
|
|
1199
1478
|
return;
|
|
1200
1479
|
}
|
|
1201
|
-
if (!
|
|
1202
|
-
|
|
1480
|
+
if (!w) {
|
|
1481
|
+
s.writeHead(400, { "Content-Type": "text/html" }), s.end(ge(
|
|
1203
1482
|
"error",
|
|
1204
1483
|
"Missing Authorization Code",
|
|
1205
1484
|
"No authorization code was received from the server.",
|
|
1206
1485
|
"missing_code"
|
|
1207
|
-
)),
|
|
1486
|
+
)), n.close(), t(new Error("No authorization code"));
|
|
1208
1487
|
return;
|
|
1209
1488
|
}
|
|
1210
|
-
|
|
1489
|
+
s.writeHead(200, { "Content-Type": "text/html" }), s.end(ge(
|
|
1211
1490
|
"success",
|
|
1212
1491
|
"Authentication Successful",
|
|
1213
1492
|
"You have been authenticated successfully. Return to the terminal to continue."
|
|
1214
|
-
)),
|
|
1493
|
+
)), n.close(), e(w);
|
|
1215
1494
|
} else
|
|
1216
|
-
|
|
1495
|
+
s.writeHead(404), s.end("Not found");
|
|
1217
1496
|
});
|
|
1218
|
-
|
|
1219
|
-
console.info(`OAuth callback server listening on port ${
|
|
1497
|
+
n.listen(he, () => {
|
|
1498
|
+
console.info(`OAuth callback server listening on port ${he}`);
|
|
1220
1499
|
}), setTimeout(() => {
|
|
1221
|
-
|
|
1500
|
+
n.close(), t(new Error("Authentication timed out"));
|
|
1222
1501
|
}, 5 * 60 * 1e3);
|
|
1223
1502
|
});
|
|
1224
1503
|
}
|
|
1225
|
-
async function
|
|
1226
|
-
const
|
|
1504
|
+
async function _t(o, e, t) {
|
|
1505
|
+
const n = await fetch(`${se}/oauth/token`, {
|
|
1227
1506
|
method: "POST",
|
|
1228
1507
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1229
|
-
body: new
|
|
1508
|
+
body: new We({
|
|
1230
1509
|
grant_type: "authorization_code",
|
|
1231
|
-
code:
|
|
1232
|
-
client_id:
|
|
1233
|
-
redirect_uri:
|
|
1234
|
-
code_verifier:
|
|
1510
|
+
code: o,
|
|
1511
|
+
client_id: e,
|
|
1512
|
+
redirect_uri: ke,
|
|
1513
|
+
code_verifier: t
|
|
1235
1514
|
})
|
|
1236
1515
|
});
|
|
1237
|
-
if (!
|
|
1238
|
-
const
|
|
1239
|
-
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");
|
|
1240
1519
|
}
|
|
1241
|
-
return
|
|
1520
|
+
return n.json();
|
|
1242
1521
|
}
|
|
1243
|
-
async function
|
|
1244
|
-
const
|
|
1522
|
+
async function Lt(o, e) {
|
|
1523
|
+
const t = await fetch(`${se}/oauth/token`, {
|
|
1245
1524
|
method: "POST",
|
|
1246
1525
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1247
|
-
body: new
|
|
1526
|
+
body: new We({
|
|
1248
1527
|
grant_type: "refresh_token",
|
|
1249
|
-
refresh_token:
|
|
1250
|
-
client_id:
|
|
1528
|
+
refresh_token: o,
|
|
1529
|
+
client_id: e
|
|
1251
1530
|
})
|
|
1252
1531
|
});
|
|
1253
|
-
if (!
|
|
1254
|
-
const
|
|
1255
|
-
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");
|
|
1256
1535
|
}
|
|
1257
|
-
return
|
|
1536
|
+
return t.json();
|
|
1258
1537
|
}
|
|
1259
|
-
async function
|
|
1260
|
-
var
|
|
1261
|
-
const
|
|
1538
|
+
async function At(o) {
|
|
1539
|
+
var i, s, d;
|
|
1540
|
+
const e = await fetch(`${se}/mcp`, {
|
|
1262
1541
|
method: "POST",
|
|
1263
1542
|
headers: {
|
|
1264
1543
|
"Content-Type": "application/json",
|
|
1265
|
-
Authorization: `Bearer ${
|
|
1544
|
+
Authorization: `Bearer ${o}`
|
|
1266
1545
|
},
|
|
1267
1546
|
body: JSON.stringify({
|
|
1268
1547
|
jsonrpc: "2.0",
|
|
@@ -1274,263 +1553,291 @@ async function Ct(e) {
|
|
|
1274
1553
|
}
|
|
1275
1554
|
})
|
|
1276
1555
|
});
|
|
1277
|
-
if (!
|
|
1556
|
+
if (!e.ok)
|
|
1278
1557
|
throw new Error("Failed to get user info");
|
|
1279
|
-
const
|
|
1280
|
-
if (
|
|
1281
|
-
throw new Error(
|
|
1282
|
-
const
|
|
1283
|
-
if (
|
|
1284
|
-
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);
|
|
1285
1564
|
throw new Error("Invalid response from whoami");
|
|
1286
1565
|
}
|
|
1287
|
-
async function
|
|
1288
|
-
const
|
|
1566
|
+
async function re() {
|
|
1567
|
+
const o = W("Starting authentication...").start();
|
|
1289
1568
|
try {
|
|
1290
|
-
|
|
1291
|
-
const
|
|
1292
|
-
|
|
1293
|
-
const
|
|
1294
|
-
|
|
1295
|
-
🌐 Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${
|
|
1296
|
-
`), await
|
|
1297
|
-
const
|
|
1298
|
-
|
|
1299
|
-
const
|
|
1300
|
-
|
|
1301
|
-
const
|
|
1302
|
-
accessToken:
|
|
1303
|
-
refreshToken:
|
|
1304
|
-
expiresAt: new Date(Date.now() +
|
|
1305
|
-
clientId:
|
|
1306
|
-
userId:
|
|
1307
|
-
userEmail:
|
|
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(`
|
|
1574
|
+
🌐 Opening browser for authentication...`), console.log("If the browser does not open, visit:"), console.log(` ${w.toString()}
|
|
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 = {
|
|
1581
|
+
accessToken: m.access_token,
|
|
1582
|
+
refreshToken: m.refresh_token,
|
|
1583
|
+
expiresAt: new Date(Date.now() + m.expires_in * 1e3).toISOString(),
|
|
1584
|
+
clientId: t,
|
|
1585
|
+
userId: p.userId,
|
|
1586
|
+
userEmail: p.email
|
|
1308
1587
|
};
|
|
1309
|
-
return
|
|
1310
|
-
} catch (
|
|
1311
|
-
throw
|
|
1588
|
+
return Qe(b), o.succeed(`Authenticated as ${p.email}`), b;
|
|
1589
|
+
} catch (e) {
|
|
1590
|
+
throw o.fail(`Authentication failed: ${e.message}`), e;
|
|
1312
1591
|
}
|
|
1313
1592
|
}
|
|
1314
|
-
async function
|
|
1315
|
-
const
|
|
1316
|
-
if (!
|
|
1593
|
+
async function Xe() {
|
|
1594
|
+
const o = je();
|
|
1595
|
+
if (!o) {
|
|
1317
1596
|
console.log("Not currently logged in.");
|
|
1318
1597
|
return;
|
|
1319
1598
|
}
|
|
1320
|
-
|
|
1599
|
+
Ze(), console.log(`✅ Logged out (was: ${o.userEmail})`);
|
|
1321
1600
|
}
|
|
1322
|
-
async function
|
|
1323
|
-
let
|
|
1324
|
-
if (!
|
|
1601
|
+
async function Dt() {
|
|
1602
|
+
let o = je();
|
|
1603
|
+
if (!o)
|
|
1325
1604
|
return console.log(`Not logged in. Starting authentication...
|
|
1326
|
-
`), await
|
|
1327
|
-
if (!
|
|
1328
|
-
return
|
|
1329
|
-
if (
|
|
1330
|
-
const
|
|
1605
|
+
`), await re();
|
|
1606
|
+
if (!It(o))
|
|
1607
|
+
return o;
|
|
1608
|
+
if (o.refreshToken) {
|
|
1609
|
+
const e = W("Refreshing access token...").start();
|
|
1331
1610
|
try {
|
|
1332
|
-
const
|
|
1333
|
-
|
|
1334
|
-
|
|
1611
|
+
const t = await Lt(
|
|
1612
|
+
o.refreshToken,
|
|
1613
|
+
o.clientId
|
|
1335
1614
|
);
|
|
1336
|
-
return
|
|
1337
|
-
...
|
|
1338
|
-
accessToken:
|
|
1339
|
-
refreshToken:
|
|
1340
|
-
expiresAt: new Date(Date.now() +
|
|
1341
|
-
},
|
|
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;
|
|
1342
1621
|
} catch {
|
|
1343
|
-
return
|
|
1622
|
+
return e.warn("Token refresh failed, please log in again"), Ze(), await re();
|
|
1344
1623
|
}
|
|
1345
1624
|
}
|
|
1346
1625
|
return console.log(`Session expired. Please log in again.
|
|
1347
|
-
`), await
|
|
1626
|
+
`), await re();
|
|
1348
1627
|
}
|
|
1349
|
-
function
|
|
1350
|
-
return
|
|
1628
|
+
function Ht() {
|
|
1629
|
+
return se;
|
|
1351
1630
|
}
|
|
1352
|
-
const
|
|
1353
|
-
async function
|
|
1631
|
+
const ye = "@myop/cli";
|
|
1632
|
+
async function Ut() {
|
|
1354
1633
|
try {
|
|
1355
|
-
const
|
|
1356
|
-
return
|
|
1634
|
+
const o = await fetch(`https://registry.npmjs.org/${ye}/latest`);
|
|
1635
|
+
return o.ok ? (await o.json()).version : null;
|
|
1357
1636
|
} catch {
|
|
1358
1637
|
return null;
|
|
1359
1638
|
}
|
|
1360
1639
|
}
|
|
1361
|
-
function
|
|
1362
|
-
const
|
|
1363
|
-
for (let
|
|
1364
|
-
const
|
|
1365
|
-
if (
|
|
1366
|
-
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;
|
|
1367
1646
|
}
|
|
1368
1647
|
return 0;
|
|
1369
1648
|
}
|
|
1370
|
-
async function
|
|
1371
|
-
const
|
|
1649
|
+
async function Jt(o) {
|
|
1650
|
+
const e = W({
|
|
1372
1651
|
text: "Checking for updates...",
|
|
1373
1652
|
color: "cyan"
|
|
1374
|
-
}).start(),
|
|
1375
|
-
if (
|
|
1653
|
+
}).start(), t = await Ut();
|
|
1654
|
+
if (e.stop(), !t || Bt(t, o) <= 0)
|
|
1376
1655
|
return !1;
|
|
1377
1656
|
console.log(`
|
|
1378
|
-
📦 New version available: ${
|
|
1657
|
+
📦 New version available: ${o} → ${t}
|
|
1379
1658
|
`);
|
|
1380
|
-
let
|
|
1659
|
+
let n;
|
|
1381
1660
|
try {
|
|
1382
|
-
|
|
1661
|
+
n = await Je({
|
|
1383
1662
|
message: "Would you like to update now?",
|
|
1384
1663
|
choices: [
|
|
1385
1664
|
{ name: "Yes, update now", value: !0 },
|
|
1386
1665
|
{ name: "No, continue with current version", value: !1 }
|
|
1387
1666
|
]
|
|
1388
1667
|
});
|
|
1389
|
-
} catch (
|
|
1390
|
-
throw
|
|
1668
|
+
} catch (i) {
|
|
1669
|
+
throw i.name === "ExitPromptError" && (console.log(`
|
|
1391
1670
|
|
|
1392
1671
|
👋 Goodbye!
|
|
1393
|
-
`), process.exit(0)),
|
|
1672
|
+
`), process.exit(0)), i;
|
|
1394
1673
|
}
|
|
1395
|
-
if (
|
|
1396
|
-
const
|
|
1397
|
-
text: `Updating ${
|
|
1674
|
+
if (n) {
|
|
1675
|
+
const i = W({
|
|
1676
|
+
text: `Updating ${ye} to v${t}...`,
|
|
1398
1677
|
color: "green"
|
|
1399
1678
|
}).start();
|
|
1400
1679
|
try {
|
|
1401
|
-
return
|
|
1680
|
+
return fe(`npm install -g ${ye}@latest`, { stdio: "pipe" }), i.succeed(`Updated to v${t}`), console.log(`
|
|
1402
1681
|
🔄 Restarting with new version...
|
|
1403
|
-
`),
|
|
1682
|
+
`), ct("myop", process.argv.slice(2), {
|
|
1404
1683
|
stdio: "inherit",
|
|
1405
1684
|
shell: !0
|
|
1406
|
-
}).on("close", (
|
|
1407
|
-
process.exit(
|
|
1685
|
+
}).on("close", (d) => {
|
|
1686
|
+
process.exit(d || 0);
|
|
1408
1687
|
}), !0;
|
|
1409
1688
|
} catch {
|
|
1410
|
-
return
|
|
1411
|
-
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
|
|
1412
1691
|
`), !1;
|
|
1413
1692
|
}
|
|
1414
1693
|
}
|
|
1415
1694
|
return !1;
|
|
1416
1695
|
}
|
|
1417
|
-
const
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
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
|
|
1425
1731
|
};
|
|
1426
1732
|
try {
|
|
1427
|
-
return
|
|
1428
|
-
} catch (
|
|
1429
|
-
if (
|
|
1733
|
+
return h.myopConfig = gt(h.options.configPath), { configFound: !0 };
|
|
1734
|
+
} catch (t) {
|
|
1735
|
+
if (o) {
|
|
1430
1736
|
console.info(`
|
|
1431
|
-
⚠️ failed read config file from ${
|
|
1737
|
+
⚠️ failed read config file from ${h.options.configPath}, trying to create new one`);
|
|
1432
1738
|
try {
|
|
1433
|
-
const
|
|
1739
|
+
const n = {
|
|
1434
1740
|
author: "@myop-cli",
|
|
1435
1741
|
flows: []
|
|
1436
1742
|
};
|
|
1437
|
-
return
|
|
1743
|
+
return Oe(h.options.configPath, n), h.myopConfig = n, { configFound: !0 };
|
|
1438
1744
|
} catch {
|
|
1439
|
-
return console.info("Error details :",
|
|
1745
|
+
return console.info("Error details :", t), { configFound: !1, error: t };
|
|
1440
1746
|
}
|
|
1441
1747
|
} else
|
|
1442
|
-
return console.info("Error details :",
|
|
1748
|
+
return console.info("Error details :", t), { configFound: !1, error: t };
|
|
1443
1749
|
}
|
|
1444
1750
|
};
|
|
1445
1751
|
[
|
|
1446
|
-
new
|
|
1447
|
-
...
|
|
1752
|
+
new Re(),
|
|
1753
|
+
...St
|
|
1448
1754
|
];
|
|
1449
|
-
const
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
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();
|
|
1458
1765
|
});
|
|
1459
|
-
|
|
1460
|
-
|
|
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();
|
|
1461
1768
|
});
|
|
1462
|
-
|
|
1463
|
-
|
|
1769
|
+
h.program.command("install").description("Install Myop assets").action(async () => {
|
|
1770
|
+
be(), await Ve.action();
|
|
1464
1771
|
});
|
|
1465
|
-
|
|
1772
|
+
h.program.command("login").description("Authenticate with Myop platform").action(async () => {
|
|
1466
1773
|
try {
|
|
1467
|
-
await
|
|
1468
|
-
} catch (
|
|
1469
|
-
console.error("Login failed:",
|
|
1774
|
+
await re();
|
|
1775
|
+
} catch (o) {
|
|
1776
|
+
console.error("Login failed:", o.message), process.exit(1);
|
|
1470
1777
|
}
|
|
1471
1778
|
process.exit(0);
|
|
1472
1779
|
});
|
|
1473
|
-
|
|
1474
|
-
await
|
|
1780
|
+
h.program.command("logout").description("Clear stored credentials").action(async () => {
|
|
1781
|
+
await Xe(), process.exit(0);
|
|
1475
1782
|
});
|
|
1476
|
-
|
|
1477
|
-
const
|
|
1478
|
-
|
|
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);
|
|
1479
1786
|
});
|
|
1480
|
-
|
|
1481
|
-
var
|
|
1482
|
-
const
|
|
1483
|
-
let
|
|
1484
|
-
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))
|
|
1485
1792
|
try {
|
|
1486
|
-
const
|
|
1487
|
-
|
|
1488
|
-
const
|
|
1489
|
-
console.log(`📋 Found config: ${
|
|
1490
|
-
} catch (
|
|
1491
|
-
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);
|
|
1492
1799
|
}
|
|
1493
1800
|
else
|
|
1494
1801
|
console.log("⚠️ No myop.config.json found. A new component will be created.");
|
|
1495
|
-
if (!
|
|
1496
|
-
const { exec:
|
|
1497
|
-
let
|
|
1498
|
-
const
|
|
1499
|
-
const
|
|
1500
|
-
|
|
1501
|
-
if (!
|
|
1502
|
-
|
|
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);
|
|
1503
1810
|
return;
|
|
1504
1811
|
}
|
|
1505
|
-
if (
|
|
1506
|
-
const
|
|
1507
|
-
if (
|
|
1508
|
-
const
|
|
1509
|
-
|
|
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);
|
|
1510
1817
|
return;
|
|
1511
1818
|
}
|
|
1512
1819
|
}
|
|
1513
|
-
console.error(
|
|
1820
|
+
console.error(U.message), L(!1);
|
|
1514
1821
|
});
|
|
1515
1822
|
});
|
|
1516
|
-
await
|
|
1823
|
+
await E() || process.exit(1);
|
|
1517
1824
|
}
|
|
1518
|
-
const
|
|
1519
|
-
|
|
1520
|
-
let
|
|
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));
|
|
1827
|
+
let w;
|
|
1521
1828
|
try {
|
|
1522
|
-
|
|
1523
|
-
} catch (
|
|
1524
|
-
console.error("❌ Authentication failed:",
|
|
1829
|
+
w = await Dt();
|
|
1830
|
+
} catch (g) {
|
|
1831
|
+
console.error("❌ Authentication failed:", g.message), process.exit(1);
|
|
1525
1832
|
}
|
|
1526
|
-
const
|
|
1527
|
-
let
|
|
1833
|
+
const M = Ht();
|
|
1834
|
+
let m = W("Requesting upload URL...").start(), p;
|
|
1528
1835
|
try {
|
|
1529
|
-
const
|
|
1836
|
+
const g = await fetch(`${M}/mcp`, {
|
|
1530
1837
|
method: "POST",
|
|
1531
1838
|
headers: {
|
|
1532
1839
|
"Content-Type": "application/json",
|
|
1533
|
-
Authorization: `Bearer ${
|
|
1840
|
+
Authorization: `Bearer ${w.accessToken}`
|
|
1534
1841
|
},
|
|
1535
1842
|
body: JSON.stringify({
|
|
1536
1843
|
jsonrpc: "2.0",
|
|
@@ -1539,63 +1846,63 @@ f.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1539
1846
|
params: {
|
|
1540
1847
|
name: "upload_component",
|
|
1541
1848
|
arguments: {
|
|
1542
|
-
name:
|
|
1543
|
-
componentId:
|
|
1544
|
-
organization:
|
|
1849
|
+
name: s.name || s.componentName || i.default.basename(process.cwd()),
|
|
1850
|
+
componentId: s.componentId || void 0,
|
|
1851
|
+
organization: s.organization || void 0
|
|
1545
1852
|
}
|
|
1546
1853
|
}
|
|
1547
1854
|
})
|
|
1548
1855
|
});
|
|
1549
|
-
if (!
|
|
1550
|
-
throw new Error(`Server returned ${
|
|
1551
|
-
const
|
|
1552
|
-
if (
|
|
1553
|
-
throw new Error(
|
|
1554
|
-
const
|
|
1555
|
-
if (
|
|
1556
|
-
throw new Error(
|
|
1557
|
-
|
|
1558
|
-
} catch (
|
|
1559
|
-
|
|
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);
|
|
1864
|
+
m.succeed("Upload URL obtained");
|
|
1865
|
+
} catch (g) {
|
|
1866
|
+
m.fail("Failed to get upload URL"), console.error(" ", g.message), process.exit(1);
|
|
1560
1867
|
}
|
|
1561
|
-
|
|
1868
|
+
m = W("Uploading component...").start();
|
|
1562
1869
|
try {
|
|
1563
|
-
const
|
|
1564
|
-
let
|
|
1565
|
-
const
|
|
1566
|
-
if (
|
|
1567
|
-
|
|
1870
|
+
const g = t.readFileSync(d, "utf-8");
|
|
1871
|
+
let P;
|
|
1872
|
+
const E = p.curlCommand.match(/(?:"|\\")([^"\\]+(?:\\.[^"\\]*)*)(?:"|\\")$/);
|
|
1873
|
+
if (E)
|
|
1874
|
+
P = E[1];
|
|
1568
1875
|
else {
|
|
1569
|
-
const
|
|
1570
|
-
if (
|
|
1571
|
-
|
|
1876
|
+
const I = p.curlCommand.match(/(https:\/\/[^\s"\\]+)/);
|
|
1877
|
+
if (I)
|
|
1878
|
+
P = I[1];
|
|
1572
1879
|
else
|
|
1573
|
-
throw new Error("Could not parse presigned URL from: " +
|
|
1880
|
+
throw new Error("Could not parse presigned URL from: " + p.curlCommand);
|
|
1574
1881
|
}
|
|
1575
|
-
console.info("Uploading to:",
|
|
1576
|
-
const
|
|
1882
|
+
console.info("Uploading to:", P.substring(0, 100) + "...");
|
|
1883
|
+
const C = await fetch(P, {
|
|
1577
1884
|
method: "PUT",
|
|
1578
1885
|
headers: {
|
|
1579
1886
|
"Content-Type": "text/html"
|
|
1580
1887
|
},
|
|
1581
|
-
body:
|
|
1888
|
+
body: g
|
|
1582
1889
|
});
|
|
1583
|
-
if (!
|
|
1584
|
-
const
|
|
1585
|
-
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}`);
|
|
1586
1893
|
}
|
|
1587
|
-
|
|
1588
|
-
} catch (
|
|
1589
|
-
|
|
1894
|
+
m.succeed("Component uploaded");
|
|
1895
|
+
} catch (g) {
|
|
1896
|
+
m.fail("Upload failed"), console.error(" ", g.message), g.cause && console.error(" Cause:", g.cause), process.exit(1);
|
|
1590
1897
|
}
|
|
1591
|
-
|
|
1592
|
-
let
|
|
1898
|
+
m = W("Confirming upload...").start();
|
|
1899
|
+
let b;
|
|
1593
1900
|
try {
|
|
1594
|
-
const
|
|
1901
|
+
const g = await fetch(`${M}/mcp`, {
|
|
1595
1902
|
method: "POST",
|
|
1596
1903
|
headers: {
|
|
1597
1904
|
"Content-Type": "application/json",
|
|
1598
|
-
Authorization: `Bearer ${
|
|
1905
|
+
Authorization: `Bearer ${w.accessToken}`
|
|
1599
1906
|
},
|
|
1600
1907
|
body: JSON.stringify({
|
|
1601
1908
|
jsonrpc: "2.0",
|
|
@@ -1604,245 +1911,233 @@ f.program.command("sync").description("Build and upload component to Myop platfo
|
|
|
1604
1911
|
params: {
|
|
1605
1912
|
name: "confirm_upload",
|
|
1606
1913
|
arguments: {
|
|
1607
|
-
uploadId:
|
|
1914
|
+
uploadId: p.uploadId
|
|
1608
1915
|
}
|
|
1609
1916
|
}
|
|
1610
1917
|
})
|
|
1611
1918
|
});
|
|
1612
|
-
if (!
|
|
1613
|
-
throw new Error(`Server returned ${
|
|
1614
|
-
const
|
|
1615
|
-
if (
|
|
1616
|
-
throw new Error(
|
|
1617
|
-
const
|
|
1618
|
-
if (
|
|
1619
|
-
throw new Error(
|
|
1620
|
-
|
|
1621
|
-
} catch (
|
|
1622
|
-
|
|
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)
|
|
1926
|
+
throw new Error(b.error);
|
|
1927
|
+
m.succeed("Upload confirmed");
|
|
1928
|
+
} catch (g) {
|
|
1929
|
+
m.fail("Confirmation failed"), console.error(" ", g.message), process.exit(1);
|
|
1623
1930
|
}
|
|
1624
|
-
if (
|
|
1625
|
-
|
|
1931
|
+
if (b.isNewComponent || !s.componentId) {
|
|
1932
|
+
s.componentId = b.componentId, s.organization = b.orgId, s.name || (s.name = b.componentName);
|
|
1626
1933
|
try {
|
|
1627
|
-
|
|
1628
|
-
📝 Updated ${
|
|
1629
|
-
} catch (
|
|
1934
|
+
t.writeFileSync(e, JSON.stringify(s, null, 2)), console.log(`
|
|
1935
|
+
📝 Updated ${e} with componentId`);
|
|
1936
|
+
} catch (g) {
|
|
1630
1937
|
console.log(`
|
|
1631
|
-
⚠️ Could not update ${
|
|
1938
|
+
⚠️ Could not update ${e}: ${g.message}`), console.log(` Please add componentId: "${b.componentId}" manually`);
|
|
1632
1939
|
}
|
|
1633
1940
|
}
|
|
1634
1941
|
console.log(`
|
|
1635
|
-
✅ Sync completed successfully!`), console.log(` Component: ${
|
|
1942
|
+
✅ Sync completed successfully!`), console.log(` Component: ${b.componentName}`), console.log(` Dashboard: ${b.dashboardUrl}`), process.exit(0);
|
|
1636
1943
|
});
|
|
1637
|
-
|
|
1638
|
-
const
|
|
1944
|
+
h.program.command("dev").description("Start development server with file watching").action(Fe);
|
|
1945
|
+
const Vt = () => {
|
|
1639
1946
|
try {
|
|
1640
|
-
|
|
1947
|
+
fe("git --version", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
1641
1948
|
} catch {
|
|
1642
1949
|
return { gitNotInstalled: !0 };
|
|
1643
1950
|
}
|
|
1644
1951
|
try {
|
|
1645
|
-
|
|
1952
|
+
fe("git rev-parse --git-dir", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
1646
1953
|
} catch {
|
|
1647
1954
|
return { notARepo: !0 };
|
|
1648
1955
|
}
|
|
1649
1956
|
try {
|
|
1650
|
-
const
|
|
1957
|
+
const o = fe("git diff --stat HEAD -- . 2>/dev/null || git diff --stat -- . 2>/dev/null", {
|
|
1651
1958
|
encoding: "utf-8",
|
|
1652
1959
|
stdio: ["pipe", "pipe", "pipe"]
|
|
1653
1960
|
}).trim();
|
|
1654
|
-
if (!
|
|
1961
|
+
if (!o)
|
|
1655
1962
|
return {
|
|
1656
1963
|
files: 0,
|
|
1657
1964
|
insertions: 0,
|
|
1658
1965
|
deletions: 0
|
|
1659
1966
|
};
|
|
1660
|
-
const
|
|
1661
|
-
`),
|
|
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/);
|
|
1662
1969
|
return {
|
|
1663
|
-
files:
|
|
1664
|
-
insertions:
|
|
1665
|
-
deletions:
|
|
1970
|
+
files: s ? parseInt(s[1]) : 0,
|
|
1971
|
+
insertions: n ? parseInt(n[1]) : 0,
|
|
1972
|
+
deletions: i ? parseInt(i[1]) : 0
|
|
1666
1973
|
};
|
|
1667
1974
|
} catch {
|
|
1668
1975
|
return null;
|
|
1669
1976
|
}
|
|
1670
|
-
},
|
|
1671
|
-
var
|
|
1672
|
-
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();
|
|
1673
1980
|
console.log(`
|
|
1674
1981
|
┌─────────────────────────────────────────────────┐`), console.log("│ │"), console.log("│ Welcome to Myop CLI - Remote UI Made Easy │"), console.log("│ │"), console.log(`└─────────────────────────────────────────────────┘
|
|
1675
|
-
`),
|
|
1676
|
-
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 = [
|
|
1677
1984
|
{
|
|
1678
1985
|
emoji: "🚀",
|
|
1679
1986
|
label: "Initialize new component",
|
|
1680
1987
|
value: "init",
|
|
1681
1988
|
help: "Creates myop.config.json in current directory",
|
|
1682
|
-
disabled:
|
|
1989
|
+
disabled: o ? "(config already exists)" : !1
|
|
1683
1990
|
},
|
|
1684
1991
|
{
|
|
1685
1992
|
emoji: "🛠️ ",
|
|
1686
|
-
label:
|
|
1993
|
+
label: i ? `Start dev mode for "${i}"` : "Start dev mode",
|
|
1687
1994
|
value: "dev",
|
|
1688
1995
|
help: "Starts dev server with HMR for instant preview of changes",
|
|
1689
|
-
disabled:
|
|
1996
|
+
disabled: o ? !1 : "(no config file)"
|
|
1690
1997
|
},
|
|
1691
1998
|
{
|
|
1692
1999
|
emoji: "📦",
|
|
1693
|
-
label:
|
|
2000
|
+
label: i ? `Push "${i}"` : "Push component",
|
|
1694
2001
|
value: "sync",
|
|
1695
2002
|
help: "Builds project & uploads dist/index.html to Myop",
|
|
1696
|
-
disabled:
|
|
2003
|
+
disabled: o ? n ? !1 : "(login required)" : "(no config file)"
|
|
1697
2004
|
}
|
|
1698
|
-
].map((
|
|
1699
|
-
name:
|
|
1700
|
-
${
|
|
1701
|
-
value:
|
|
1702
|
-
disabled:
|
|
2005
|
+
].map((v) => ({
|
|
2006
|
+
name: e && !v.disabled ? `${v.emoji} ${v.label}
|
|
2007
|
+
${v.help}` : `${v.emoji} ${v.label}`,
|
|
2008
|
+
value: v.value,
|
|
2009
|
+
disabled: v.disabled
|
|
1703
2010
|
}));
|
|
1704
|
-
|
|
1705
|
-
new
|
|
2011
|
+
M.push(
|
|
2012
|
+
new Re(),
|
|
1706
2013
|
{
|
|
1707
|
-
name:
|
|
1708
|
-
Clears stored credentials from this machine` :
|
|
1709
|
-
Opens browser to authenticate with Myop` :
|
|
1710
|
-
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"
|
|
1711
2018
|
},
|
|
1712
2019
|
{
|
|
1713
|
-
name:
|
|
2020
|
+
name: e ? "📖 Hide help" : "📖 Show help",
|
|
1714
2021
|
value: "help"
|
|
1715
2022
|
},
|
|
1716
|
-
new
|
|
1717
|
-
{
|
|
1718
|
-
name: "🐛 [DEV] - git push",
|
|
1719
|
-
value: "dev-git-push",
|
|
1720
|
-
disabled: e ? !1 : "(no config file)"
|
|
1721
|
-
},
|
|
1722
|
-
new ae(),
|
|
2023
|
+
new Re(),
|
|
1723
2024
|
{
|
|
1724
2025
|
name: "👋 Exit",
|
|
1725
2026
|
value: "exit"
|
|
1726
2027
|
}
|
|
1727
2028
|
);
|
|
1728
|
-
let
|
|
2029
|
+
let m;
|
|
1729
2030
|
try {
|
|
1730
|
-
|
|
2031
|
+
m = await Je({
|
|
1731
2032
|
message: "What would you like to do?",
|
|
1732
|
-
choices:
|
|
2033
|
+
choices: M
|
|
1733
2034
|
});
|
|
1734
|
-
} catch (
|
|
1735
|
-
throw
|
|
2035
|
+
} catch (v) {
|
|
2036
|
+
throw v.name === "ExitPromptError" && (console.log(`
|
|
1736
2037
|
|
|
1737
2038
|
👋 Goodbye!
|
|
1738
|
-
`), process.exit(0)),
|
|
2039
|
+
`), process.exit(0)), v;
|
|
1739
2040
|
}
|
|
1740
|
-
switch (
|
|
2041
|
+
switch (m) {
|
|
1741
2042
|
case "init":
|
|
1742
|
-
await
|
|
2043
|
+
await Qt();
|
|
1743
2044
|
break;
|
|
1744
2045
|
case "sync":
|
|
1745
2046
|
console.log(`
|
|
1746
2047
|
Running sync...
|
|
1747
2048
|
`);
|
|
1748
|
-
const { execSync:
|
|
2049
|
+
const { execSync: v } = await import("child_process");
|
|
1749
2050
|
try {
|
|
1750
|
-
|
|
2051
|
+
v("node " + process.argv[1] + " sync", { stdio: "inherit" });
|
|
1751
2052
|
} catch {
|
|
1752
2053
|
}
|
|
1753
|
-
await
|
|
2054
|
+
await q(!0, e);
|
|
1754
2055
|
break;
|
|
1755
2056
|
case "dev":
|
|
1756
|
-
await
|
|
2057
|
+
await Fe();
|
|
1757
2058
|
break;
|
|
1758
2059
|
case "login":
|
|
1759
2060
|
try {
|
|
1760
|
-
await
|
|
1761
|
-
`), await
|
|
1762
|
-
} catch (
|
|
1763
|
-
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);
|
|
1764
2065
|
}
|
|
1765
2066
|
break;
|
|
1766
2067
|
case "logout":
|
|
1767
|
-
await
|
|
1768
|
-
`), await
|
|
2068
|
+
await Xe(), console.log(`
|
|
2069
|
+
`), await q(o, e);
|
|
1769
2070
|
break;
|
|
1770
2071
|
case "help":
|
|
1771
|
-
await
|
|
1772
|
-
break;
|
|
1773
|
-
case "dev-git-push":
|
|
1774
|
-
await Et(), await K(e, t);
|
|
2072
|
+
await q(o, !e);
|
|
1775
2073
|
break;
|
|
1776
2074
|
case "exit":
|
|
1777
2075
|
process.exit(0);
|
|
1778
2076
|
}
|
|
1779
|
-
},
|
|
1780
|
-
|
|
2077
|
+
}, we = ".myop-monorepo.json", Gt = () => {
|
|
2078
|
+
try {
|
|
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);
|
|
1781
2095
|
console.log(`
|
|
1782
|
-
|
|
2096
|
+
┌─────────────────────────────────────────────────┐`), console.log("│ │"), console.log("│ Myop CLI - Monorepo Mode │"), console.log("│ │"), console.log(`└─────────────────────────────────────────────────┘
|
|
1783
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;
|
|
1784
2113
|
try {
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
}
|
|
1789
|
-
console.log("📁 Staging all files...");
|
|
1790
|
-
const p = await n.statusMatrix({ fs: e.default, dir: r });
|
|
1791
|
-
for (const [_, S, u, h] of p)
|
|
1792
|
-
S === u && u === h || (u === 0 ? (await n.remove({ fs: e.default, dir: r, filepath: _ }), console.log(` - Removed: ${_}`)) : u !== h && (await n.add({ fs: e.default, dir: r, filepath: _ }), console.log(` + Added: ${_}`)));
|
|
1793
|
-
console.log(`
|
|
1794
|
-
📝 Creating commit...`);
|
|
1795
|
-
const i = await n.commit({
|
|
1796
|
-
fs: e.default,
|
|
1797
|
-
dir: r,
|
|
1798
|
-
message: `dev-push ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
1799
|
-
author: { name: "myop-cli", email: "cli@myop.dev" }
|
|
2114
|
+
m = await w({
|
|
2115
|
+
message: "Select components to start in dev mode:",
|
|
2116
|
+
choices: M
|
|
1800
2117
|
});
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
const A = h.isDirectory() ? 0 : h.size;
|
|
1807
|
-
b.write(A.toString(8).padStart(11, "0") + " ", 124, 12), b.write(Math.floor(h.mtime.getTime() / 1e3).toString(8).padStart(11, "0") + " ", 136, 12), b.write(" ", 148, 8), b.write(h.isDirectory() ? "5" : "0", 156, 1);
|
|
1808
|
-
let M = 0;
|
|
1809
|
-
for (let O = 0; O < 512; O++)
|
|
1810
|
-
M += b[O];
|
|
1811
|
-
if (b.write(M.toString(8).padStart(6, "0") + "\0 ", 148, 8), y.push(b), !h.isDirectory()) {
|
|
1812
|
-
const O = e.readFileSync(_);
|
|
1813
|
-
y.push(O);
|
|
1814
|
-
const z = 512 - O.length % 512;
|
|
1815
|
-
z < 512 && y.push(Buffer.alloc(z));
|
|
1816
|
-
}
|
|
1817
|
-
}, d = async (_, S) => {
|
|
1818
|
-
const u = e.readdirSync(_, { withFileTypes: !0 });
|
|
1819
|
-
for (const h of u) {
|
|
1820
|
-
const b = t.default.join(_, h.name);
|
|
1821
|
-
h.isDirectory() ? (await $(b, S), await d(b, S)) : await $(b, S);
|
|
1822
|
-
}
|
|
1823
|
-
};
|
|
1824
|
-
await d(m, r), y.push(Buffer.alloc(1024));
|
|
1825
|
-
const v = Buffer.concat(y);
|
|
1826
|
-
console.log(` Tar size: ${v.length} bytes`), console.log(`
|
|
1827
|
-
🗜️ Compressing with lzma...`);
|
|
1828
|
-
const { createRequire: x } = await import("module"), N = await x(import.meta.url)("lzma-native").compress(v, { preset: 9 });
|
|
1829
|
-
console.log(` Compressed size: ${N.length} bytes`), console.log(`
|
|
1830
|
-
📤 Output (base64):
|
|
1831
|
-
`);
|
|
1832
|
-
const F = N.toString("base64");
|
|
1833
|
-
console.log(F), console.log(`
|
|
1834
|
-
✅ Done! (${F.length} characters)`);
|
|
1835
|
-
} catch (p) {
|
|
1836
|
-
console.error("❌ Error:", p.message);
|
|
2118
|
+
} catch (u) {
|
|
2119
|
+
throw u.name === "ExitPromptError" && (console.log(`
|
|
2120
|
+
|
|
2121
|
+
👋 Goodbye!
|
|
2122
|
+
`), process.exit(0)), u;
|
|
1837
2123
|
}
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
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;
|
|
1841
2136
|
try {
|
|
1842
|
-
|
|
2137
|
+
s = await o({
|
|
1843
2138
|
message: "Component name:",
|
|
1844
|
-
default:
|
|
1845
|
-
}),
|
|
2139
|
+
default: i
|
|
2140
|
+
}), d = await e({
|
|
1846
2141
|
message: "Component type:",
|
|
1847
2142
|
choices: [
|
|
1848
2143
|
{ name: "📄 HTML", value: "html", description: "Plain HTML/JS/CSS component" },
|
|
@@ -1851,23 +2146,23 @@ Running sync...
|
|
|
1851
2146
|
{ name: "🅰️ Angular", value: "angular", disabled: "(coming soon)" }
|
|
1852
2147
|
]
|
|
1853
2148
|
});
|
|
1854
|
-
} catch (
|
|
1855
|
-
throw
|
|
2149
|
+
} catch (m) {
|
|
2150
|
+
throw m.name === "ExitPromptError" && (console.log(`
|
|
1856
2151
|
|
|
1857
2152
|
👋 Goodbye!
|
|
1858
|
-
`), process.exit(0)),
|
|
2153
|
+
`), process.exit(0)), m;
|
|
1859
2154
|
}
|
|
1860
|
-
const
|
|
1861
|
-
name:
|
|
1862
|
-
type:
|
|
2155
|
+
const w = {
|
|
2156
|
+
name: s,
|
|
2157
|
+
type: d,
|
|
1863
2158
|
author: "@myop-cli",
|
|
1864
2159
|
HMR: !0
|
|
1865
|
-
},
|
|
2160
|
+
}, M = h.program.getOptionValue("config") || "./myop.config.json";
|
|
1866
2161
|
try {
|
|
1867
|
-
|
|
1868
|
-
✅ Created ${
|
|
1869
|
-
const
|
|
1870
|
-
name:
|
|
2162
|
+
t.writeFileSync(M, JSON.stringify(w, null, 2)), console.log(`
|
|
2163
|
+
✅ Created ${M}`);
|
|
2164
|
+
const m = {
|
|
2165
|
+
name: s.toLowerCase().replace(/\s+/g, "-"),
|
|
1871
2166
|
version: "1.0.0",
|
|
1872
2167
|
type: "module",
|
|
1873
2168
|
scripts: {
|
|
@@ -1878,7 +2173,7 @@ Running sync...
|
|
|
1878
2173
|
esbuild: "^0.24.0"
|
|
1879
2174
|
}
|
|
1880
2175
|
};
|
|
1881
|
-
|
|
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';
|
|
1882
2177
|
import fs from 'fs';
|
|
1883
2178
|
import path from 'path';
|
|
1884
2179
|
|
|
@@ -1958,25 +2253,25 @@ fs.writeFileSync('dist/index.html', html);
|
|
|
1958
2253
|
console.log('✅ Built dist/index.html');
|
|
1959
2254
|
console.log(\` Bundled \${jsFiles.length} JS modules, \${cssFiles.length} CSS files\`);
|
|
1960
2255
|
`), console.log("✅ Created build.js");
|
|
1961
|
-
const
|
|
2256
|
+
const b = `<!DOCTYPE html>
|
|
1962
2257
|
<html lang="en">
|
|
1963
2258
|
<head>
|
|
1964
2259
|
<meta charset="UTF-8">
|
|
1965
2260
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1966
|
-
<title>${
|
|
2261
|
+
<title>${s}</title>
|
|
1967
2262
|
<link rel="stylesheet" href="./src/styles/index.css">
|
|
1968
2263
|
</head>
|
|
1969
2264
|
<body>
|
|
1970
2265
|
<div id="app">
|
|
1971
|
-
<h1>${
|
|
2266
|
+
<h1>${s}</h1>
|
|
1972
2267
|
<p>Your Myop component is ready!</p>
|
|
1973
2268
|
</div>
|
|
1974
2269
|
<script type="module" src="./src/index.js"><\/script>
|
|
1975
2270
|
</body>
|
|
1976
2271
|
</html>
|
|
1977
2272
|
`;
|
|
1978
|
-
|
|
1979
|
-
const
|
|
2273
|
+
t.writeFileSync("index.html", b), console.log("✅ Created index.html");
|
|
2274
|
+
const u = `// ${s} - Entry Point
|
|
1980
2275
|
import { init } from './modules/app.js';
|
|
1981
2276
|
import { setupMyopInterface } from './modules/myop.js';
|
|
1982
2277
|
|
|
@@ -1985,16 +2280,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
1985
2280
|
setupMyopInterface();
|
|
1986
2281
|
});
|
|
1987
2282
|
`;
|
|
1988
|
-
|
|
1989
|
-
const
|
|
2283
|
+
t.writeFileSync("src/index.js", u), console.log("✅ Created src/index.js");
|
|
2284
|
+
const v = `// ${s} - Main Application Logic
|
|
1990
2285
|
|
|
1991
2286
|
export function init() {
|
|
1992
|
-
console.log('${
|
|
2287
|
+
console.log('${s} loaded');
|
|
1993
2288
|
|
|
1994
2289
|
// Your component logic here
|
|
1995
2290
|
}
|
|
1996
2291
|
`;
|
|
1997
|
-
|
|
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
|
|
1998
2293
|
|
|
1999
2294
|
export function setupMyopInterface() {
|
|
2000
2295
|
// Called when host app sends data to this component
|
|
@@ -2010,12 +2305,12 @@ export function setupMyopInterface() {
|
|
|
2010
2305
|
};
|
|
2011
2306
|
}
|
|
2012
2307
|
`), console.log("✅ Created src/modules/myop.js");
|
|
2013
|
-
const
|
|
2308
|
+
const $ = `/* ${s} - Styles Entry Point */
|
|
2014
2309
|
/* Add your CSS imports here - they will be auto-bundled */
|
|
2015
2310
|
@import './main.css';
|
|
2016
2311
|
`;
|
|
2017
|
-
|
|
2018
|
-
const _ = `/* ${
|
|
2312
|
+
t.writeFileSync("src/styles/index.css", $), console.log("✅ Created src/styles/index.css");
|
|
2313
|
+
const _ = `/* ${s} - Main Styles */
|
|
2019
2314
|
|
|
2020
2315
|
* {
|
|
2021
2316
|
box-sizing: border-box;
|
|
@@ -2044,16 +2339,16 @@ p {
|
|
|
2044
2339
|
line-height: 1.5;
|
|
2045
2340
|
}
|
|
2046
2341
|
`;
|
|
2047
|
-
|
|
2342
|
+
t.writeFileSync("src/styles/main.css", _), console.log("✅ Created src/styles/main.css"), t.writeFileSync(".gitignore", `node_modules/
|
|
2048
2343
|
dist/
|
|
2049
2344
|
.temp-entry.js
|
|
2050
2345
|
.temp-styles.css
|
|
2051
2346
|
.DS_Store
|
|
2052
2347
|
`), console.log("✅ Created .gitignore");
|
|
2053
|
-
const
|
|
2348
|
+
const g = await import("./index-DuEoKctW.js").then((E) => E.i), P = process.cwd();
|
|
2054
2349
|
try {
|
|
2055
|
-
await
|
|
2056
|
-
const
|
|
2350
|
+
await g.init({ fs: t, dir: P });
|
|
2351
|
+
const E = [
|
|
2057
2352
|
"myop.config.json",
|
|
2058
2353
|
"package.json",
|
|
2059
2354
|
"build.js",
|
|
@@ -2065,60 +2360,64 @@ dist/
|
|
|
2065
2360
|
"src/styles/index.css",
|
|
2066
2361
|
"src/styles/main.css"
|
|
2067
2362
|
];
|
|
2068
|
-
for (const
|
|
2069
|
-
await
|
|
2070
|
-
await
|
|
2071
|
-
fs:
|
|
2072
|
-
dir:
|
|
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,
|
|
2073
2368
|
message: "init",
|
|
2074
2369
|
author: { name: "myop-cli", email: "cli@myop.dev" }
|
|
2075
2370
|
}), console.log("✅ Initialized git repository");
|
|
2076
|
-
} catch (
|
|
2077
|
-
console.log("⚠️ Failed to initialize git repository:",
|
|
2371
|
+
} catch (E) {
|
|
2372
|
+
console.log("⚠️ Failed to initialize git repository:", E.message);
|
|
2078
2373
|
}
|
|
2079
2374
|
console.log(`
|
|
2080
2375
|
📦 Next steps:`), console.log(" 1. npm install"), console.log(" 2. npm run build"), console.log(` 3. myop sync
|
|
2081
|
-
`),
|
|
2082
|
-
} catch (
|
|
2083
|
-
console.error(`Failed to initialize component: ${
|
|
2376
|
+
`), h.myopConfig = w, await q(!0);
|
|
2377
|
+
} catch (m) {
|
|
2378
|
+
console.error(`Failed to initialize component: ${m.message}`), process.exit(1);
|
|
2084
2379
|
}
|
|
2085
2380
|
};
|
|
2086
|
-
|
|
2087
|
-
if (
|
|
2088
|
-
|
|
2089
|
-
|
|
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 };
|
|
2090
2389
|
try {
|
|
2091
|
-
if (
|
|
2092
|
-
const
|
|
2093
|
-
|
|
2390
|
+
if (w.existsSync(M)) {
|
|
2391
|
+
const v = w.readFileSync(M, "utf-8"), x = JSON.parse(v);
|
|
2392
|
+
b = {
|
|
2094
2393
|
found: !0,
|
|
2095
|
-
path:
|
|
2096
|
-
name:
|
|
2097
|
-
componentId:
|
|
2098
|
-
organization:
|
|
2394
|
+
path: M,
|
|
2395
|
+
name: x.name || x.componentName || null,
|
|
2396
|
+
componentId: x.componentId || null,
|
|
2397
|
+
organization: x.organization || null
|
|
2099
2398
|
};
|
|
2100
2399
|
}
|
|
2101
|
-
} catch (
|
|
2102
|
-
|
|
2400
|
+
} catch (v) {
|
|
2401
|
+
b = { found: !1, error: v.message };
|
|
2103
2402
|
}
|
|
2104
|
-
const
|
|
2105
|
-
version:
|
|
2106
|
-
config:
|
|
2403
|
+
const u = {
|
|
2404
|
+
version: m,
|
|
2405
|
+
config: b,
|
|
2107
2406
|
auth: {
|
|
2108
|
-
loggedIn: !!(
|
|
2109
|
-
email: (
|
|
2407
|
+
loggedIn: !!(p != null && p.email),
|
|
2408
|
+
email: (p == null ? void 0 : p.email) || null
|
|
2110
2409
|
}
|
|
2111
2410
|
};
|
|
2112
|
-
console.log(JSON.stringify(
|
|
2411
|
+
console.log(JSON.stringify(u, null, 2)), process.exit(0);
|
|
2113
2412
|
}
|
|
2114
|
-
let n =
|
|
2413
|
+
let n = W({
|
|
2115
2414
|
text: "Loading Myop CLI...",
|
|
2116
2415
|
color: "green"
|
|
2117
2416
|
}).start();
|
|
2118
|
-
const
|
|
2119
|
-
await
|
|
2120
|
-
const
|
|
2121
|
-
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);
|
|
2122
2421
|
});
|
|
2123
|
-
|
|
2124
|
-
|
|
2422
|
+
h.program.parse(process.argv);
|
|
2423
|
+
h.program.opts();
|