@codeyam-editor/codeyam-editor 0.1.0-staging.398fa2d → 0.1.0-staging.888bf79
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 +11 -60
- package/npm/editor-dev.js +94 -64
- package/package.json +1 -1
package/npm/cli.js
CHANGED
|
@@ -1,65 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
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
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
4
|
+
* Development CLI for running the codeyam-editor against any project.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
12
|
-
*
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
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