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