@rainbow-robotics/muscat-plugin-kit 0.1.2-dev.7 → 0.1.2-dev.8

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.
@@ -10,6 +10,7 @@ import { runDev } from "../src/dev.mjs";
10
10
  import { runUpdate } from "../src/update.mjs";
11
11
  import { runSdk } from "../src/sdk.mjs";
12
12
  import { runType } from "../src/type.mjs";
13
+ import { runPreview } from "../src/preview.mjs";
13
14
 
14
15
  const [, , cmd, ...args] = process.argv;
15
16
 
@@ -25,6 +26,7 @@ Commands:
25
26
  dev Run dev:ui and dev:back together
26
27
  dev:ui Preview the plugin in a mini-Muscat (preview-host)
27
28
  dev:back Run the plugin back end (python: watchfiles reload / ros2: Docker)
29
+ preview Preview against a real Muscat server (prompts for robot IP)
28
30
  update Update @rainbow-robotics/muscat-plugin-kit and @rainbow-robotics/plugin-ui
29
31
  sdk <list|update [version]> Manage the python rainbow-rb-sdk version
30
32
 
@@ -47,6 +49,8 @@ async function main() {
47
49
  return await runDevUi(args);
48
50
  case "dev:back":
49
51
  return await runDevBack(args);
52
+ case "preview":
53
+ return await runPreview(args);
50
54
  case "update":
51
55
  return await runUpdate(args);
52
56
  case "sdk":
package/cli/src/devUi.mjs CHANGED
@@ -81,4 +81,4 @@ export async function runDevUi(args = []) {
81
81
  child.on("exit", (code) => process.exit(code ?? 0));
82
82
  }
83
83
 
84
- export { findPluginRoot };
84
+ export { findPluginRoot, findPreviewHostRoot };
@@ -0,0 +1,91 @@
1
+ // muscat-pk preview — build the plugin and open preview-host connected to a
2
+ // real Muscat server (robot or local). No local Socket.IO server is started.
3
+ import { createInterface } from "node:readline";
4
+ import { spawn } from "node:child_process";
5
+ import { existsSync } from "node:fs";
6
+ import { resolve } from "node:path";
7
+ import { buildPlugin } from "./build.mjs";
8
+ import { findPreviewHostRoot } from "./devUi.mjs";
9
+ import { checkKitUpdate, log, parseArgs } from "./util.mjs";
10
+
11
+ function prompt(question, defaultValue) {
12
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
13
+ return new Promise((res) => {
14
+ rl.question(question, (answer) => {
15
+ rl.close();
16
+ res(answer.trim() || defaultValue);
17
+ });
18
+ });
19
+ }
20
+
21
+ export async function runPreview(args = []) {
22
+ const opts = parseArgs(args, { booleans: ["help"] });
23
+
24
+ if (opts.help) {
25
+ console.log(
26
+ [
27
+ "",
28
+ "Usage: muscat-pk preview [options]",
29
+ "",
30
+ " 빌드된 플러그인을 실제 Muscat 서버에 연결해 미리봅니다.",
31
+ " Socket.IO 서버를 직접 띄우지 않습니다.",
32
+ "",
33
+ "Options:",
34
+ " --host <ip> Muscat 서버 IP 또는 hostname (default: localhost)",
35
+ " --port <n> preview-host 로컬 포트 (default: 4180)",
36
+ " --ws-port <n> Muscat Socket.IO 포트 (default: 10000)",
37
+ "",
38
+ ].join("\n"),
39
+ );
40
+ return;
41
+ }
42
+
43
+ await checkKitUpdate();
44
+
45
+ // ── 로봇 IP 결정 ────────────────────────────────────────────────────────────
46
+ let robotHost = opts.host ?? "";
47
+ if (!robotHost) {
48
+ robotHost = await prompt(
49
+ "Muscat 서버 IP 또는 hostname [localhost]: ",
50
+ "localhost",
51
+ );
52
+ }
53
+ const wsPort = opts["ws-port"] ?? "10000";
54
+ const socketUrl = `ws://${robotHost}:${wsPort}`;
55
+
56
+ const previewPort = opts.port ?? "4180";
57
+
58
+ log.step(`Muscat 서버: ${socketUrl}`);
59
+
60
+ // ── 플러그인 빌드 ────────────────────────────────────────────────────────────
61
+ const { distDir } = await buildPlugin();
62
+
63
+ // ── preview-host 실행 ────────────────────────────────────────────────────────
64
+ const previewRoot = findPreviewHostRoot();
65
+ const serveEntry = resolve(previewRoot, "serve.mjs");
66
+
67
+ if (!existsSync(resolve(previewRoot, "dist", "index.html"))) {
68
+ log.step("preview-host 번들 빌드 중 (최초 1회)…");
69
+ await new Promise((res, rej) => {
70
+ const p = spawn(process.execPath, [resolve(previewRoot, "build.mjs")], {
71
+ stdio: "inherit",
72
+ });
73
+ p.on("exit", (c) => (c === 0 ? res() : rej(new Error("preview-host build failed"))));
74
+ });
75
+ }
76
+
77
+ log.step(`preview-host 시작 → http://localhost:${previewPort}`);
78
+ log.step(`Socket.IO URL: ${socketUrl}`);
79
+
80
+ const child = spawn(
81
+ process.execPath,
82
+ [
83
+ serveEntry,
84
+ "--plugin", distDir,
85
+ "--port", String(previewPort),
86
+ "--socket-url", socketUrl,
87
+ ],
88
+ { stdio: "inherit" },
89
+ );
90
+ child.on("exit", (code) => process.exit(code ?? 0));
91
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainbow-robotics/muscat-plugin-kit",
3
- "version": "0.1.2-dev.7",
3
+ "version": "0.1.2-dev.8",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=20"
@@ -31,7 +31,7 @@
31
31
  "@types/react-dom": "^19.0.4"
32
32
  },
33
33
  "dependencies": {
34
- "@rainbow-robotics/preview-host": "0.1.2-dev.7",
34
+ "@rainbow-robotics/preview-host": "0.1.2-dev.8",
35
35
  "esbuild": "^0.25.0"
36
36
  },
37
37
  "optionalDependencies": {