@codeyam-editor/codeyam-editor 0.1.0-staging.36d3518 → 0.1.0-staging.46bd02f

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.
Files changed (2) hide show
  1. package/npm/editor-dev.js +120 -0
  2. package/package.json +1 -1
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Development CLI for running the codeyam-editor against any project.
5
+ *
6
+ * Two modes:
7
+ *
8
+ * Launcher — no subcommand (or --restart): builds the Rust binary and UI
9
+ * from the editor repo, starts the server, waits for readiness, opens browser.
10
+ * codeyam-editor-dev
11
+ * codeyam-editor-dev --restart
12
+ *
13
+ * Passthrough — any subcommand (start, init, editor, ...): rebuilds the
14
+ * Rust binary, then forwards args to it.
15
+ * codeyam-editor-dev editor step 1
16
+ * codeyam-editor-dev editor advance
17
+ */
18
+
19
+ const { execSync, spawn } = require("child_process");
20
+ const path = require("path");
21
+ const fs = require("fs");
22
+ const { ensureServer, restartServer, waitForPort, ensureBinary, uiDistDir, rootDir } = require("./utils");
23
+ const { open } = require("./open");
24
+
25
+ // Tell the Rust binary to emit "codeyam-editor-dev" in all instructions,
26
+ // permissions, and installed files instead of "codeyam-editor".
27
+ process.env.CODEYAM_CLI = "codeyam-editor-dev";
28
+
29
+ const args = process.argv.slice(2);
30
+ const KNOWN_SUBCOMMANDS = ["start", "init", "editor"];
31
+
32
+ /** Check if the first non-flag argument is a known subcommand. */
33
+ function hasSubcommand() {
34
+ for (const arg of args) {
35
+ if (arg.startsWith("-")) continue;
36
+ return KNOWN_SUBCOMMANDS.includes(arg);
37
+ }
38
+ return false;
39
+ }
40
+
41
+ /** Build the Rust binary from the editor repo. */
42
+ function buildBinary() {
43
+ console.error("Building Rust binary...");
44
+ try {
45
+ execSync("cargo build", { stdio: "inherit", cwd: rootDir });
46
+ } catch {
47
+ console.error("Failed to build Rust binary. Continuing with existing build (if any)...");
48
+ }
49
+ }
50
+
51
+ // --- Passthrough mode: build binary, then forward to it ---
52
+ if (hasSubcommand()) {
53
+ buildBinary();
54
+ const binary = ensureBinary();
55
+ const child = spawn(binary, args, {
56
+ stdio: "inherit",
57
+ cwd: process.cwd(),
58
+ env: { ...process.env, CODEYAM_EDITOR_UI_DIR: uiDistDir() },
59
+ });
60
+ child.on("exit", (code) => {
61
+ process.exit(code ?? 1);
62
+ });
63
+ } else {
64
+ // --- Launcher mode: build everything, start server, open browser ---
65
+ const SERVER_PORT = 14199;
66
+ const shouldRestart = args.includes("--restart");
67
+
68
+ function readProjectPort() {
69
+ try {
70
+ const configPath = path.join(process.cwd(), ".codeyam", "editor.json");
71
+ const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
72
+ return config.port || 3000;
73
+ } catch {
74
+ return 3000;
75
+ }
76
+ }
77
+
78
+ async function main() {
79
+ const projectDir = process.cwd();
80
+ console.error(`Editor repo: ${rootDir}`);
81
+ console.error(`Target project: ${projectDir}`);
82
+
83
+ buildBinary();
84
+
85
+ // Build the UI from the editor repo
86
+ console.error("Building UI...");
87
+ try {
88
+ execSync("npx vite build", { stdio: "inherit", cwd: path.join(rootDir, "ui") });
89
+ } catch {
90
+ console.error("Failed to build UI. Continuing with existing build (if any)...");
91
+ }
92
+
93
+ const serverChild = shouldRestart
94
+ ? await restartServer(SERVER_PORT)
95
+ : await ensureServer(SERVER_PORT);
96
+
97
+ const appPort = readProjectPort();
98
+ const viteInternalPort = appPort + 1;
99
+ console.error(`Waiting for dev server on port ${viteInternalPort}...`);
100
+ const viteReady = await waitForPort(viteInternalPort, 15000, 300);
101
+ if (!viteReady) {
102
+ console.error(`Warning: Dev server not ready on port ${viteInternalPort}. Live Preview may not work initially.`);
103
+ }
104
+
105
+ const url = `http://localhost:${SERVER_PORT}`;
106
+ console.error(`Editor UI: ${url}`);
107
+ console.error(`Live Preview: http://localhost:${appPort}`);
108
+ console.error(`Project: ${projectDir}`);
109
+ open(url);
110
+ const keepAlive = setInterval(() => {}, 60_000);
111
+
112
+ process.on("SIGINT", () => {
113
+ clearInterval(keepAlive);
114
+ if (serverChild) serverChild.kill("SIGINT");
115
+ process.exit(0);
116
+ });
117
+ }
118
+
119
+ main();
120
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeyam-editor/codeyam-editor",
3
- "version": "0.1.0-staging.36d3518",
3
+ "version": "0.1.0-staging.46bd02f",
4
4
  "description": "Language-agnostic managed execution sandbox for scenario-driven development",
5
5
  "bin": {
6
6
  "codeyam-editor": "./npm/cli.js"