* Resolve project path from argument or current directory * Walks up parent directories to find nearest initialized CodeGraph project * (must have .codegraph/codegraph.db, not just .codegraph/lessons.db)
(pathArg?: string)
| 266 | * (must have .codegraph/codegraph.db, not just .codegraph/lessons.db) |
| 267 | */ |
| 268 | function resolveProjectPath(pathArg?: string): string { |
| 269 | const absolutePath = path.resolve(pathArg || process.cwd()); |
| 270 | |
| 271 | // If exact path is initialized (has codegraph.db), use it |
| 272 | if (isInitialized(absolutePath)) { |
| 273 | return absolutePath; |
| 274 | } |
| 275 | |
| 276 | // Walk up to find nearest parent with CodeGraph initialized |
| 277 | // Note: findNearestCodeGraphRoot finds any .codegraph folder, but we need one with codegraph.db |
| 278 | let current = absolutePath; |
| 279 | const root = path.parse(current).root; |
| 280 | |
| 281 | while (current !== root) { |
| 282 | const parent = path.dirname(current); |
| 283 | if (parent === current) break; |
| 284 | current = parent; |
| 285 | |
| 286 | if (isInitialized(current)) { |
| 287 | return current; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | // Not found - return original path (will fail later with helpful error) |
| 292 | return absolutePath; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Format a number with commas |
no test coverage detected