mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-10 09:50:08 +02:00
Split codebase (#455)
This commit is contained in:
@@ -40,13 +40,19 @@ if (fs.existsSync(envLocalPath)) {
|
||||
|
||||
console.log("Detected new worktree - configuring ports in .env.local");
|
||||
|
||||
// Find the highest ports in use across all worktrees
|
||||
// Main worktree (first in list) is assumed to use default ports 1420/64343
|
||||
const CLIENT_PORT_BASE = 1420;
|
||||
const PROXY_PORT_BASE = 2420; // Keep proxy +1000 from client to avoid cross-app conflicts
|
||||
|
||||
// Find the highest worktree index and MCP port in use across all worktrees.
|
||||
// Main worktree (first in list) is assumed to use index 0:
|
||||
// client=1420, proxy=2420, mcp=64343.
|
||||
let maxMcpPort = 64343;
|
||||
let maxDevPort = 1420;
|
||||
let maxWorktreeIndex = 0;
|
||||
|
||||
try {
|
||||
const worktreeList = execSync("git worktree list --porcelain", { encoding: "utf8" });
|
||||
const worktreeList = execSync("git worktree list --porcelain", {
|
||||
encoding: "utf8",
|
||||
});
|
||||
const worktreePaths = worktreeList
|
||||
.split("\n")
|
||||
.filter((line) => line.startsWith("worktree "))
|
||||
@@ -68,24 +74,37 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
const devMatch = content.match(/^YAAK_DEV_PORT=(\d+)/m);
|
||||
if (devMatch) {
|
||||
const port = parseInt(devMatch[1], 10);
|
||||
if (port > maxDevPort) {
|
||||
maxDevPort = port;
|
||||
const clientDevMatch = content.match(/^(?:YAAK_CLIENT_DEV_PORT|YAAK_DEV_PORT)=(\d+)/m);
|
||||
if (clientDevMatch) {
|
||||
const port = parseInt(clientDevMatch[1], 10);
|
||||
const index = port - CLIENT_PORT_BASE;
|
||||
if (index > maxWorktreeIndex) {
|
||||
maxWorktreeIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
const proxyDevMatch = content.match(/^YAAK_PROXY_DEV_PORT=(\d+)/m);
|
||||
if (proxyDevMatch) {
|
||||
const port = parseInt(proxyDevMatch[1], 10);
|
||||
const index = port - PROXY_PORT_BASE;
|
||||
if (index > maxWorktreeIndex) {
|
||||
maxWorktreeIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Increment to get the next available port
|
||||
maxDevPort++;
|
||||
// Increment MCP to get the next available port
|
||||
maxMcpPort++;
|
||||
} catch (err) {
|
||||
console.error("Warning: Could not check other worktrees for port conflicts:", err.message);
|
||||
// Continue with default ports
|
||||
}
|
||||
|
||||
const nextWorktreeIndex = maxWorktreeIndex + 1;
|
||||
const nextClientDevPort = CLIENT_PORT_BASE + nextWorktreeIndex;
|
||||
const nextProxyDevPort = PROXY_PORT_BASE + nextWorktreeIndex;
|
||||
|
||||
// Get worktree name from current directory
|
||||
const worktreeName = path.basename(process.cwd());
|
||||
|
||||
@@ -93,8 +112,11 @@ const worktreeName = path.basename(process.cwd());
|
||||
const envContent = `# Auto-generated by git post-checkout hook
|
||||
# This file configures ports for this worktree to avoid conflicts
|
||||
|
||||
# Vite dev server port (main worktree uses 1420)
|
||||
YAAK_DEV_PORT=${maxDevPort}
|
||||
# Vite dev server port for the client app (main worktree uses ${CLIENT_PORT_BASE})
|
||||
YAAK_CLIENT_DEV_PORT=${nextClientDevPort}
|
||||
|
||||
# Vite dev server port for the proxy app (main worktree uses ${PROXY_PORT_BASE})
|
||||
YAAK_PROXY_DEV_PORT=${nextProxyDevPort}
|
||||
|
||||
# MCP Server port (main worktree uses 64343)
|
||||
YAAK_PLUGIN_MCP_SERVER_PORT=${maxMcpPort}
|
||||
@@ -102,30 +124,58 @@ YAAK_PLUGIN_MCP_SERVER_PORT=${maxMcpPort}
|
||||
|
||||
fs.writeFileSync(envLocalPath, envContent, "utf8");
|
||||
console.log(
|
||||
`Created .env.local with YAAK_DEV_PORT=${maxDevPort} and YAAK_PLUGIN_MCP_SERVER_PORT=${maxMcpPort}`,
|
||||
`Created .env.local with YAAK_CLIENT_DEV_PORT=${nextClientDevPort}, YAAK_PROXY_DEV_PORT=${nextProxyDevPort}, and YAAK_PLUGIN_MCP_SERVER_PORT=${maxMcpPort}`,
|
||||
);
|
||||
|
||||
// Create tauri.worktree.conf.json with unique app identifier for complete isolation
|
||||
// This gives each worktree its own app data directory, avoiding the need for DB path prefixes
|
||||
const tauriWorktreeConfig = {
|
||||
const clientTauriWorktreeConfig = {
|
||||
identifier: `app.yaak.desktop.dev.${worktreeName}`,
|
||||
productName: `Daak (${worktreeName})`,
|
||||
};
|
||||
|
||||
const tauriConfigPath = path.join(
|
||||
const clientTauriConfigPath = path.join(
|
||||
process.cwd(),
|
||||
"crates-tauri",
|
||||
"yaak-app",
|
||||
"yaak-app-client",
|
||||
"tauri.worktree.conf.json",
|
||||
);
|
||||
fs.writeFileSync(tauriConfigPath, JSON.stringify(tauriWorktreeConfig, null, 2) + "\n", "utf8");
|
||||
console.log(`Created tauri.worktree.conf.json with identifier: ${tauriWorktreeConfig.identifier}`);
|
||||
fs.writeFileSync(
|
||||
clientTauriConfigPath,
|
||||
JSON.stringify(clientTauriWorktreeConfig, null, 2) + "\n",
|
||||
"utf8",
|
||||
);
|
||||
console.log(
|
||||
`Created client tauri.worktree.conf.json with identifier: ${clientTauriWorktreeConfig.identifier}`,
|
||||
);
|
||||
|
||||
const proxyTauriWorktreeConfig = {
|
||||
identifier: `app.yaak.proxy.dev.${worktreeName}`,
|
||||
productName: `Yaak Proxy (${worktreeName})`,
|
||||
};
|
||||
|
||||
const proxyTauriConfigPath = path.join(
|
||||
process.cwd(),
|
||||
"crates-tauri",
|
||||
"yaak-app-proxy",
|
||||
"tauri.worktree.conf.json",
|
||||
);
|
||||
fs.writeFileSync(
|
||||
proxyTauriConfigPath,
|
||||
JSON.stringify(proxyTauriWorktreeConfig, null, 2) + "\n",
|
||||
"utf8",
|
||||
);
|
||||
console.log(
|
||||
`Created proxy tauri.worktree.conf.json with identifier: ${proxyTauriWorktreeConfig.identifier}`,
|
||||
);
|
||||
|
||||
// Copy gitignored editor config folders from main worktree (.zed, .vscode, .claude, etc.)
|
||||
// This ensures your editor settings, tasks, and configurations are available in the new worktree
|
||||
// without needing to manually copy them or commit them to git.
|
||||
try {
|
||||
const worktreeList = execSync("git worktree list --porcelain", { encoding: "utf8" });
|
||||
const worktreeList = execSync("git worktree list --porcelain", {
|
||||
encoding: "utf8",
|
||||
});
|
||||
const mainWorktreePath = worktreeList
|
||||
.split("\n")
|
||||
.find((line) => line.startsWith("worktree "))
|
||||
|
||||
Reference in New Issue
Block a user