@codeyam-editor/codeyam-editor
Advanced tools
+11
-60
| #!/usr/bin/env node | ||
| /** | ||
| * Production launcher for the codeyam-editor. | ||
| * | ||
| * Run from a project directory after installing the npm package: | ||
| * cd ~/workspace/my-app | ||
| * codeyam-editor # start fresh | ||
| * codeyam-editor --restart # kill existing and restart | ||
| * | ||
| * The pre-built binary and UI are resolved from the package install location. | ||
| * process.cwd() is treated as the target project directory. | ||
| */ | ||
| const { spawn } = require("child_process"); | ||
| const { ensureBinary, uiDistDir } = require("./utils"); | ||
| const path = require("path"); | ||
| const fs = require("fs"); | ||
| const { ensureServer, restartServer, waitForPort, ensureBinary, uiDistDir } = require("./utils"); | ||
| const { open } = require("./open"); | ||
| const binary = ensureBinary(); | ||
| const SERVER_PORT = 14199; | ||
| const shouldRestart = process.argv.includes("--restart"); | ||
| const child = spawn(binary, process.argv.slice(2), { | ||
| stdio: "inherit", | ||
| cwd: process.cwd(), | ||
| env: { ...process.env, CODEYAM_EDITOR_UI_DIR: uiDistDir() }, | ||
| }); | ||
| /** Read the target project's .codeyam/editor.json to find the app port. */ | ||
| function readProjectPort() { | ||
| try { | ||
| const configPath = path.join(process.cwd(), ".codeyam", "editor.json"); | ||
| const config = JSON.parse(fs.readFileSync(configPath, "utf8")); | ||
| return config.port || 3000; | ||
| } catch { | ||
| return 3000; | ||
| } | ||
| } | ||
| async function main() { | ||
| const projectDir = process.cwd(); | ||
| console.error(`Project: ${projectDir}`); | ||
| // Start the Rust backend — binary from package, CWD = target project | ||
| const serverChild = shouldRestart | ||
| ? await restartServer(SERVER_PORT) | ||
| : await ensureServer(SERVER_PORT); | ||
| // Wait for the target project's dev server (port + 1 is the internal port) | ||
| const appPort = readProjectPort(); | ||
| const viteInternalPort = appPort + 1; | ||
| console.error(`Waiting for dev server on port ${viteInternalPort}...`); | ||
| const viteReady = await waitForPort(viteInternalPort, 15000, 300); | ||
| if (!viteReady) { | ||
| console.error(`Warning: Dev server not ready on port ${viteInternalPort}. Live Preview may not work initially.`); | ||
| } | ||
| const url = `http://localhost:${SERVER_PORT}`; | ||
| console.error(`Editor UI: ${url}`); | ||
| console.error(`Live Preview: http://localhost:${appPort}`); | ||
| open(url); | ||
| const keepAlive = setInterval(() => {}, 60_000); | ||
| process.on("SIGINT", () => { | ||
| clearInterval(keepAlive); | ||
| if (serverChild) serverChild.kill("SIGINT"); | ||
| process.exit(0); | ||
| }); | ||
| } | ||
| main(); | ||
| child.on("exit", (code) => { | ||
| process.exit(code ?? 1); | ||
| }); |
+93
-63
| #!/usr/bin/env node | ||
| /** | ||
| * Development launcher for running the codeyam-editor against any project. | ||
| * Development CLI for running the codeyam-editor against any project. | ||
| * | ||
| * Run from the target project directory: | ||
| * cd ~/workspace/my-app | ||
| * codeyam-editor-dev # start fresh | ||
| * codeyam-editor-dev --restart # kill existing and restart | ||
| * Two modes: | ||
| * | ||
| * Uses the locally-built binary and UI from the editor repo (resolved via | ||
| * __dirname), but treats process.cwd() as the target project directory. | ||
| * Launcher — no subcommand (or --restart): builds the Rust binary and UI | ||
| * from the editor repo, starts the server, waits for readiness, opens browser. | ||
| * codeyam-editor-dev | ||
| * codeyam-editor-dev --restart | ||
| * | ||
| * Passthrough — any subcommand (start, init, editor, ...): rebuilds the | ||
| * Rust binary, then forwards args to it. | ||
| * codeyam-editor-dev editor step 1 | ||
| * codeyam-editor-dev editor advance | ||
| */ | ||
| const { execSync } = require("child_process"); | ||
| const { execSync, spawn } = require("child_process"); | ||
| const path = require("path"); | ||
| const fs = require("fs"); | ||
| const { ensureServer, restartServer, waitForPort, rootDir } = require("./utils"); | ||
| const { ensureServer, restartServer, waitForPort, ensureBinary, uiDistDir, rootDir } = require("./utils"); | ||
| const { open } = require("./open"); | ||
| const SERVER_PORT = 14199; | ||
| const shouldRestart = process.argv.includes("--restart"); | ||
| // Tell the Rust binary to emit "codeyam-editor-dev" in all instructions, | ||
| // permissions, and installed files instead of "codeyam-editor". | ||
| process.env.CODEYAM_CLI = "codeyam-editor-dev"; | ||
| /** Read the target project's .codeyam/editor.json to find the app port. */ | ||
| function readProjectPort() { | ||
| try { | ||
| const configPath = path.join(process.cwd(), ".codeyam", "editor.json"); | ||
| const config = JSON.parse(fs.readFileSync(configPath, "utf8")); | ||
| return config.port || 3000; | ||
| } catch { | ||
| return 3000; | ||
| const args = process.argv.slice(2); | ||
| const KNOWN_SUBCOMMANDS = ["start", "init", "editor"]; | ||
| /** Check if the first non-flag argument is a known subcommand. */ | ||
| function hasSubcommand() { | ||
| for (const arg of args) { | ||
| if (arg.startsWith("-")) continue; | ||
| return KNOWN_SUBCOMMANDS.includes(arg); | ||
| } | ||
| return false; | ||
| } | ||
| async function main() { | ||
| const projectDir = process.cwd(); | ||
| console.error(`Editor repo: ${rootDir}`); | ||
| console.error(`Target project: ${projectDir}`); | ||
| // Build the Rust binary from the editor repo | ||
| /** Build the Rust binary from the editor repo. */ | ||
| function buildBinary() { | ||
| console.error("Building Rust binary..."); | ||
| try { | ||
| execSync("cargo build", { | ||
| stdio: "inherit", | ||
| cwd: rootDir, | ||
| }); | ||
| execSync("cargo build", { stdio: "inherit", cwd: rootDir }); | ||
| } catch { | ||
| console.error("Failed to build Rust binary. Continuing with existing build (if any)..."); | ||
| } | ||
| } | ||
| // Build the UI from the editor repo | ||
| console.error("Building UI..."); | ||
| try { | ||
| execSync("npx vite build", { | ||
| stdio: "inherit", | ||
| cwd: path.join(rootDir, "ui"), | ||
| }); | ||
| } catch { | ||
| console.error("Failed to build UI. Continuing with existing build (if any)..."); | ||
| // --- Passthrough mode: build binary, then forward to it --- | ||
| if (hasSubcommand()) { | ||
| buildBinary(); | ||
| const binary = ensureBinary(); | ||
| const child = spawn(binary, args, { | ||
| stdio: "inherit", | ||
| cwd: process.cwd(), | ||
| env: { ...process.env, CODEYAM_EDITOR_UI_DIR: uiDistDir() }, | ||
| }); | ||
| child.on("exit", (code) => { | ||
| process.exit(code ?? 1); | ||
| }); | ||
| } else { | ||
| // --- Launcher mode: build everything, start server, open browser --- | ||
| const SERVER_PORT = 14199; | ||
| const shouldRestart = args.includes("--restart"); | ||
| function readProjectPort() { | ||
| try { | ||
| const configPath = path.join(process.cwd(), ".codeyam", "editor.json"); | ||
| const config = JSON.parse(fs.readFileSync(configPath, "utf8")); | ||
| return config.port || 3000; | ||
| } catch { | ||
| return 3000; | ||
| } | ||
| } | ||
| // Start the Rust backend — binary from editor repo, CWD = target project | ||
| const serverChild = shouldRestart | ||
| ? await restartServer(SERVER_PORT) | ||
| : await ensureServer(SERVER_PORT); | ||
| async function main() { | ||
| const projectDir = process.cwd(); | ||
| console.error(`Editor repo: ${rootDir}`); | ||
| console.error(`Target project: ${projectDir}`); | ||
| // Wait for the target project's Vite dev server (port + 1 is the internal port) | ||
| const appPort = readProjectPort(); | ||
| const viteInternalPort = appPort + 1; | ||
| console.error(`Waiting for dev server on port ${viteInternalPort}...`); | ||
| const viteReady = await waitForPort(viteInternalPort, 15000, 300); | ||
| if (!viteReady) { | ||
| console.error(`Warning: Dev server not ready on port ${viteInternalPort}. Live Preview may not work initially.`); | ||
| buildBinary(); | ||
| // Build the UI from the editor repo | ||
| console.error("Building UI..."); | ||
| try { | ||
| execSync("npx vite build", { stdio: "inherit", cwd: path.join(rootDir, "ui") }); | ||
| } catch { | ||
| console.error("Failed to build UI. Continuing with existing build (if any)..."); | ||
| } | ||
| const serverChild = shouldRestart | ||
| ? await restartServer(SERVER_PORT) | ||
| : await ensureServer(SERVER_PORT); | ||
| const appPort = readProjectPort(); | ||
| const viteInternalPort = appPort + 1; | ||
| console.error(`Waiting for dev server on port ${viteInternalPort}...`); | ||
| const viteReady = await waitForPort(viteInternalPort, 15000, 300); | ||
| if (!viteReady) { | ||
| console.error(`Warning: Dev server not ready on port ${viteInternalPort}. Live Preview may not work initially.`); | ||
| } | ||
| const url = `http://localhost:${SERVER_PORT}`; | ||
| console.error(`Editor UI: ${url}`); | ||
| console.error(`Live Preview: http://localhost:${appPort}`); | ||
| console.error(`Project: ${projectDir}`); | ||
| open(url); | ||
| const keepAlive = setInterval(() => {}, 60_000); | ||
| process.on("SIGINT", () => { | ||
| clearInterval(keepAlive); | ||
| if (serverChild) serverChild.kill("SIGINT"); | ||
| process.exit(0); | ||
| }); | ||
| } | ||
| const url = `http://localhost:${SERVER_PORT}`; | ||
| console.error(`Editor UI: ${url}`); | ||
| console.error(`Live Preview: http://localhost:${appPort}`); | ||
| console.error(`Project: ${projectDir}`); | ||
| open(url); | ||
| const keepAlive = setInterval(() => {}, 60_000); | ||
| process.on("SIGINT", () => { | ||
| clearInterval(keepAlive); | ||
| if (serverChild) serverChild.kill("SIGINT"); | ||
| process.exit(0); | ||
| }); | ||
| main(); | ||
| } | ||
| main(); |
+1
-1
| { | ||
| "name": "@codeyam-editor/codeyam-editor", | ||
| "version": "0.1.0-staging.398fa2d", | ||
| "version": "0.1.0-staging.46bd02f", | ||
| "description": "Language-agnostic managed execution sandbox for scenario-driven development", | ||
@@ -5,0 +5,0 @@ "bin": { |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 3 instances
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 2 instances
28452
-2.7%882
-1.89%13
30%8
14.29%