@codeyam-editor/codeyam-editor 0.1.0-staging.398fa2d → 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.
package/npm/cli.js CHANGED
@@ -1,65 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- /**
4
- * Production launcher for the codeyam-editor.
5
- *
6
- * Run from a project directory after installing the npm package:
7
- * cd ~/workspace/my-app
8
- * codeyam-editor # start fresh
9
- * codeyam-editor --restart # kill existing and restart
10
- *
11
- * The pre-built binary and UI are resolved from the package install location.
12
- * process.cwd() is treated as the target project directory.
13
- */
3
+ const { spawn } = require("child_process");
4
+ const { ensureBinary, uiDistDir } = require("./utils");
14
5
 
15
- const path = require("path");
16
- const fs = require("fs");
17
- const { ensureServer, restartServer, waitForPort, ensureBinary, uiDistDir } = require("./utils");
18
- const { open } = require("./open");
6
+ const binary = ensureBinary();
19
7
 
20
- const SERVER_PORT = 14199;
21
- const shouldRestart = process.argv.includes("--restart");
8
+ const child = spawn(binary, process.argv.slice(2), {
9
+ stdio: "inherit",
10
+ cwd: process.cwd(),
11
+ env: { ...process.env, CODEYAM_EDITOR_UI_DIR: uiDistDir() },
12
+ });
22
13
 
23
- /** Read the target project's .codeyam/editor.json to find the app port. */
24
- function readProjectPort() {
25
- try {
26
- const configPath = path.join(process.cwd(), ".codeyam", "editor.json");
27
- const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
28
- return config.port || 3000;
29
- } catch {
30
- return 3000;
31
- }
32
- }
33
-
34
- async function main() {
35
- const projectDir = process.cwd();
36
- console.error(`Project: ${projectDir}`);
37
-
38
- // Start the Rust backend — binary from package, CWD = target project
39
- const serverChild = shouldRestart
40
- ? await restartServer(SERVER_PORT)
41
- : await ensureServer(SERVER_PORT);
42
-
43
- // Wait for the target project's dev server (port + 1 is the internal port)
44
- const appPort = readProjectPort();
45
- const viteInternalPort = appPort + 1;
46
- console.error(`Waiting for dev server on port ${viteInternalPort}...`);
47
- const viteReady = await waitForPort(viteInternalPort, 15000, 300);
48
- if (!viteReady) {
49
- console.error(`Warning: Dev server not ready on port ${viteInternalPort}. Live Preview may not work initially.`);
50
- }
51
-
52
- const url = `http://localhost:${SERVER_PORT}`;
53
- console.error(`Editor UI: ${url}`);
54
- console.error(`Live Preview: http://localhost:${appPort}`);
55
- open(url);
56
- const keepAlive = setInterval(() => {}, 60_000);
57
-
58
- process.on("SIGINT", () => {
59
- clearInterval(keepAlive);
60
- if (serverChild) serverChild.kill("SIGINT");
61
- process.exit(0);
62
- });
63
- }
64
-
65
- main();
14
+ child.on("exit", (code) => {
15
+ process.exit(code ?? 1);
16
+ });
package/npm/editor-dev.js CHANGED
@@ -1,90 +1,120 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * Development launcher for running the codeyam-editor against any project.
4
+ * Development CLI for running the codeyam-editor against any project.
5
5
  *
6
- * Run from the target project directory:
7
- * cd ~/workspace/my-app
8
- * codeyam-editor-dev # start fresh
9
- * codeyam-editor-dev --restart # kill existing and restart
6
+ * Two modes:
10
7
  *
11
- * Uses the locally-built binary and UI from the editor repo (resolved via
12
- * __dirname), but treats process.cwd() as the target project directory.
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
13
17
  */
14
18
 
15
- const { execSync } = require("child_process");
19
+ const { execSync, spawn } = require("child_process");
16
20
  const path = require("path");
17
21
  const fs = require("fs");
18
- const { ensureServer, restartServer, waitForPort, rootDir } = require("./utils");
22
+ const { ensureServer, restartServer, waitForPort, ensureBinary, uiDistDir, rootDir } = require("./utils");
19
23
  const { open } = require("./open");
20
24
 
21
- const SERVER_PORT = 14199;
22
- const shouldRestart = process.argv.includes("--restart");
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";
23
28
 
24
- /** Read the target project's .codeyam/editor.json to find the app port. */
25
- function readProjectPort() {
26
- try {
27
- const configPath = path.join(process.cwd(), ".codeyam", "editor.json");
28
- const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
29
- return config.port || 3000;
30
- } catch {
31
- return 3000;
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);
32
37
  }
38
+ return false;
33
39
  }
34
40
 
35
- async function main() {
36
- const projectDir = process.cwd();
37
- console.error(`Editor repo: ${rootDir}`);
38
- console.error(`Target project: ${projectDir}`);
39
-
40
- // Build the Rust binary from the editor repo
41
+ /** Build the Rust binary from the editor repo. */
42
+ function buildBinary() {
41
43
  console.error("Building Rust binary...");
42
44
  try {
43
- execSync("cargo build", {
44
- stdio: "inherit",
45
- cwd: rootDir,
46
- });
45
+ execSync("cargo build", { stdio: "inherit", cwd: rootDir });
47
46
  } catch {
48
47
  console.error("Failed to build Rust binary. Continuing with existing build (if any)...");
49
48
  }
49
+ }
50
50
 
51
- // Build the UI from the editor repo
52
- console.error("Building UI...");
53
- try {
54
- execSync("npx vite build", {
55
- stdio: "inherit",
56
- cwd: path.join(rootDir, "ui"),
57
- });
58
- } catch {
59
- console.error("Failed to build UI. Continuing with existing build (if any)...");
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
+ }
60
76
  }
61
77
 
62
- // Start the Rust backend — binary from editor repo, CWD = target project
63
- const serverChild = shouldRestart
64
- ? await restartServer(SERVER_PORT)
65
- : await ensureServer(SERVER_PORT);
66
-
67
- // Wait for the target project's Vite dev server (port + 1 is the internal port)
68
- const appPort = readProjectPort();
69
- const viteInternalPort = appPort + 1;
70
- console.error(`Waiting for dev server on port ${viteInternalPort}...`);
71
- const viteReady = await waitForPort(viteInternalPort, 15000, 300);
72
- if (!viteReady) {
73
- console.error(`Warning: Dev server not ready on port ${viteInternalPort}. Live Preview may not work initially.`);
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
+ });
74
117
  }
75
118
 
76
- const url = `http://localhost:${SERVER_PORT}`;
77
- console.error(`Editor UI: ${url}`);
78
- console.error(`Live Preview: http://localhost:${appPort}`);
79
- console.error(`Project: ${projectDir}`);
80
- open(url);
81
- const keepAlive = setInterval(() => {}, 60_000);
82
-
83
- process.on("SIGINT", () => {
84
- clearInterval(keepAlive);
85
- if (serverChild) serverChild.kill("SIGINT");
86
- process.exit(0);
87
- });
119
+ main();
88
120
  }
89
-
90
- main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeyam-editor/codeyam-editor",
3
- "version": "0.1.0-staging.398fa2d",
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"