diff --git a/apps/app/electron/main.js b/apps/app/electron/main.js index ff3a5118..7ad6df20 100644 --- a/apps/app/electron/main.js +++ b/apps/app/electron/main.js @@ -144,11 +144,25 @@ async function startServer() { ? path.join(process.resourcesPath, "server", "node_modules") : path.join(__dirname, "../../server/node_modules"); + // Set default workspace directory to user's Documents/Automaker + const defaultWorkspaceDir = path.join(app.getPath("documents"), "Automaker"); + + // Ensure workspace directory exists + if (!fs.existsSync(defaultWorkspaceDir)) { + try { + fs.mkdirSync(defaultWorkspaceDir, { recursive: true }); + console.log("[Electron] Created workspace directory:", defaultWorkspaceDir); + } catch (error) { + console.error("[Electron] Failed to create workspace directory:", error); + } + } + const env = { ...process.env, PORT: SERVER_PORT.toString(), DATA_DIR: app.getPath("userData"), NODE_PATH: serverNodeModules, + WORKSPACE_DIR: process.env.WORKSPACE_DIR || defaultWorkspaceDir, }; console.log("[Electron] Starting backend server..."); diff --git a/apps/app/src/components/new-project-modal.tsx b/apps/app/src/components/new-project-modal.tsx index fd1429de..2e54c8f4 100644 --- a/apps/app/src/components/new-project-modal.tsx +++ b/apps/app/src/components/new-project-modal.tsx @@ -198,7 +198,10 @@ export function NewProjectModal({ } }; - const projectPath = workspaceDir && projectName ? `${workspaceDir}/${projectName}` : ""; + // Use platform-specific path separator + const pathSep = typeof window !== 'undefined' && (window as any).electronAPI ? + (navigator.platform.indexOf('Win') !== -1 ? '\\' : '/') : '/'; + const projectPath = workspaceDir && projectName ? `${workspaceDir}${pathSep}${projectName}` : ""; return ( diff --git a/apps/server/src/routes/templates.ts b/apps/server/src/routes/templates.ts index a4f5504c..b3b62622 100644 --- a/apps/server/src/routes/templates.ts +++ b/apps/server/src/routes/templates.ts @@ -34,6 +34,8 @@ export function createTemplatesRoutes(): Router { return; } + console.log(`[Templates] Clone request - Repo: ${repoUrl}, Project: ${projectName}, Parent: ${parentDir}`); + // Validate repo URL is a valid GitHub URL const githubUrlPattern = /^https:\/\/github\.com\/[\w-]+\/[\w.-]+$/; if (!githubUrlPattern.test(repoUrl)) { @@ -79,12 +81,32 @@ export function createTemplatesRoutes(): Router { // Ensure parent directory exists try { - await fs.mkdir(parentDir, { recursive: true }); + // Check if parentDir is a root path (Windows: C:\, D:\, etc. or Unix: /) + const isWindowsRoot = /^[A-Za-z]:\\?$/.test(parentDir); + const isUnixRoot = parentDir === '/' || parentDir === ''; + const isRoot = isWindowsRoot || isUnixRoot; + + if (isRoot) { + // Root paths always exist, just verify access + console.log(`[Templates] Using root path: ${parentDir}`); + await fs.access(parentDir); + } else { + // Check if parent directory exists + const parentExists = await fs.access(parentDir).then(() => true).catch(() => false); + + if (!parentExists) { + console.log(`[Templates] Creating parent directory: ${parentDir}`); + await fs.mkdir(parentDir, { recursive: true }); + } else { + console.log(`[Templates] Parent directory exists: ${parentDir}`); + } + } } catch (error) { - console.error("[Templates] Failed to create parent directory:", error); + const errorMessage = error instanceof Error ? error.message : String(error); + console.error("[Templates] Failed to access parent directory:", parentDir, error); res.status(500).json({ success: false, - error: "Failed to create parent directory", + error: `Failed to access parent directory: ${errorMessage}`, }); return; }