chore: document architecture gaps and add dev hot reload
- add npm dev:hot wrapper using cargo-watch and page reload polling - add mnote-web dev hot reload endpoint and coverage - record current architecture review and tracked bug findings across realtime, tree, editor, and AI runtimes Verification: - node scripts/task-dev-hot-plan-test.js - node --check scripts/dev-hot.js - cargo test -p mnote-web dev_hot -- --nocapture
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* dev:hot 启动入口。
|
||||
*
|
||||
* 目标:
|
||||
* - 不改动 desktop:hot 的默认行为。
|
||||
* - 使用 cargo-watch 自动重编译并重启 mnote-web。
|
||||
* - 通过 MNOTE_WEB_DEV_HOT_RELOAD 启用页面端轻量 reload 轮询。
|
||||
*/
|
||||
|
||||
const { spawn } = require("node:child_process");
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const rootDir = path.resolve(__dirname, "..");
|
||||
const desktopHotPath = path.join(rootDir, "scripts", "desktop-hot.js");
|
||||
|
||||
function cargoWatchCommand(env = process.env) {
|
||||
const extraArgs = String(env.MNOTE_WEB_DEV_HOT_CARGO_WATCH_ARGS || "").trim();
|
||||
const watchArgs = [
|
||||
"-w crates/mnote-web/src",
|
||||
"-w crates/mnote-web/Cargo.toml",
|
||||
"-w Cargo.toml",
|
||||
"-x \"run -p mnote-web --bin mnote-web\"",
|
||||
];
|
||||
if (extraArgs) watchArgs.unshift(extraArgs);
|
||||
return `cargo watch ${watchArgs.join(" ")}`;
|
||||
}
|
||||
|
||||
function buildDevHotEnv(baseEnv = process.env) {
|
||||
return {
|
||||
...baseEnv,
|
||||
MNOTE_WEB_DEV_HOT_RELOAD: "1",
|
||||
MNOTE_WEB_CMD: String(baseEnv.MNOTE_WEB_CMD || "").trim() || cargoWatchCommand(baseEnv),
|
||||
};
|
||||
}
|
||||
|
||||
function main() {
|
||||
if (!fs.existsSync(desktopHotPath)) {
|
||||
throw new Error(`缺少 desktop-hot 入口:${desktopHotPath}`);
|
||||
}
|
||||
|
||||
const child = spawn(process.execPath, [desktopHotPath], {
|
||||
cwd: rootDir,
|
||||
env: buildDevHotEnv(process.env),
|
||||
stdio: "inherit",
|
||||
});
|
||||
|
||||
child.on("exit", (code, signal) => {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
return;
|
||||
}
|
||||
process.exit(code ?? 0);
|
||||
});
|
||||
|
||||
child.on("error", (error) => {
|
||||
console.error(`[dev-hot] 启动失败:${error.message}`);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buildDevHotEnv,
|
||||
cargoWatchCommand,
|
||||
};
|
||||
Reference in New Issue
Block a user