decocms
Version:
CLI for managing deco.chat apps & projects
64 lines ⢠2.68 kB
JavaScript
import { spawn } from "child_process";
import { getConfig, readWranglerConfig } from "../../lib/config.js";
import { ensureDevEnvironment } from "../../lib/wrangler.js";
import { link } from "./link.js";
import process from "node:process";
export async function devCommand(opts) {
try {
// 1. Ensure development environment is set up
console.log("š§ Setting up development environment...");
await ensureDevEnvironment(opts);
// 2. Get configuration
const _config = await getConfig().catch(() => ({
workspace: "default",
bindings: [],
local: false,
enable_workflows: true,
}));
const wranglerConfig = await readWranglerConfig();
const app = typeof wranglerConfig.name === "string" ? wranglerConfig.name : "my-app";
console.log(`š¦ Starting development server for '${app}'...`);
// 3. TODO: Check/setup MCP configuration when we port those utilities
// const latest = await hasMCPPreferences(config.workspace, app);
// if (!latest) {
// const mcpConfig = await promptIDESetup({
// workspace: config.workspace,
// app,
// });
// if (mcpConfig) {
// await writeIDEConfig(mcpConfig);
// }
// }
// 4. Start development server with tunnel integration
console.log("š Starting development server with tunnel...");
// Use link command with wrangler dev as subprocess
await link({
port: 8787,
onBeforeRegister: () => {
console.log("š Starting Wrangler development server...");
const wranglerProcess = spawn("npx", ["wrangler", "dev"], {
stdio: "inherit",
shell: true,
});
// Handle process termination
const cleanup = () => {
console.log("\nā¹ļø Stopping development server...");
wranglerProcess.kill("SIGINT");
process.exit(0);
};
process.on("SIGINT", cleanup);
process.on("SIGTERM", cleanup);
wranglerProcess.on("error", (error) => {
console.error("ā Failed to start Wrangler:", error.message);
process.exit(1);
});
return wranglerProcess;
},
});
}
catch (error) {
console.error("ā Development server failed:", error instanceof Error ? error.message : String(error));
process.exit(1);
}
}
//# sourceMappingURL=dev.js.map