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