@codeyam-editor/codeyam-editor 0.1.0-staging.36d3518 → 0.1.0-staging.398fa2d
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 +60 -11
- package/npm/editor-dev.js +90 -0
- package/package.json +1 -1
package/npm/cli.js
CHANGED
|
@@ -1,16 +1,65 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
*/
|
|
5
14
|
|
|
6
|
-
const
|
|
15
|
+
const path = require("path");
|
|
16
|
+
const fs = require("fs");
|
|
17
|
+
const { ensureServer, restartServer, waitForPort, ensureBinary, uiDistDir } = require("./utils");
|
|
18
|
+
const { open } = require("./open");
|
|
7
19
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
cwd: process.cwd(),
|
|
11
|
-
env: { ...process.env, CODEYAM_EDITOR_UI_DIR: uiDistDir() },
|
|
12
|
-
});
|
|
20
|
+
const SERVER_PORT = 14199;
|
|
21
|
+
const shouldRestart = process.argv.includes("--restart");
|
|
13
22
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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();
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Development launcher for running the codeyam-editor against any project.
|
|
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
|
|
10
|
+
*
|
|
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.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const { execSync } = require("child_process");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
const fs = require("fs");
|
|
18
|
+
const { ensureServer, restartServer, waitForPort, rootDir } = require("./utils");
|
|
19
|
+
const { open } = require("./open");
|
|
20
|
+
|
|
21
|
+
const SERVER_PORT = 14199;
|
|
22
|
+
const shouldRestart = process.argv.includes("--restart");
|
|
23
|
+
|
|
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;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
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
|
+
console.error("Building Rust binary...");
|
|
42
|
+
try {
|
|
43
|
+
execSync("cargo build", {
|
|
44
|
+
stdio: "inherit",
|
|
45
|
+
cwd: rootDir,
|
|
46
|
+
});
|
|
47
|
+
} catch {
|
|
48
|
+
console.error("Failed to build Rust binary. Continuing with existing build (if any)...");
|
|
49
|
+
}
|
|
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)...");
|
|
60
|
+
}
|
|
61
|
+
|
|
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.`);
|
|
74
|
+
}
|
|
75
|
+
|
|
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
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
main();
|
package/package.json
CHANGED