( projectPath: string, serviceContainer: ServiceContainer )
| 271 | }); |
| 272 | |
| 273 | async function initializeProjectDirect( |
| 274 | projectPath: string, |
| 275 | serviceContainer: ServiceContainer |
| 276 | ): Promise<void> { |
| 277 | try { |
| 278 | let normalizedPath = projectPath.replace(/\/+$/, ""); |
| 279 | const validation = await validateProjectPath(normalizedPath); |
| 280 | if (!validation.valid || !validation.expandedPath) { |
| 281 | console.error( |
| 282 | `Invalid project path provided via --add-project: ${validation.error ?? "unknown error"}` |
| 283 | ); |
| 284 | return; |
| 285 | } |
| 286 | normalizedPath = validation.expandedPath; |
| 287 | |
| 288 | const projects = serviceContainer.projectService.list(); |
| 289 | const shouldSetLaunchProject = shouldExposeLaunchProject(projects); |
| 290 | const alreadyExists = Array.isArray(projects) |
| 291 | ? projects.some(([path]) => path === normalizedPath) |
| 292 | : false; |
| 293 | |
| 294 | if (alreadyExists) { |
| 295 | console.log(`Project already exists: ${normalizedPath}`); |
| 296 | if (shouldSetLaunchProject) { |
| 297 | launchProjectPath = normalizedPath; |
| 298 | } |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | console.log(`Creating project via --add-project: ${normalizedPath}`); |
| 303 | const result = await serviceContainer.projectService.create(normalizedPath); |
| 304 | if (result.success) { |
| 305 | console.log(`Project created at ${normalizedPath}`); |
| 306 | if (shouldSetLaunchProject) { |
| 307 | launchProjectPath = normalizedPath; |
| 308 | } |
| 309 | } else { |
| 310 | const errorMsg = |
| 311 | typeof result.error === "string" |
| 312 | ? result.error |
| 313 | : JSON.stringify(result.error ?? "unknown error"); |
| 314 | console.error(`Failed to create project at ${normalizedPath}: ${errorMsg}`); |
| 315 | } |
| 316 | } catch (error) { |
| 317 | console.error(`initializeProject failed for ${projectPath}:`, error); |
| 318 | } |
| 319 | } |
no test coverage detected