* 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)
| 242 | * (must have .codegraph/codegraph.db, not just .codegraph/lessons.db) |
| 243 | */ |
| 244 | function resolveProjectPath(pathArg?: string): string { |
| 245 | const absolutePath = path.resolve(pathArg || process.cwd()); |
| 246 | |
| 247 | // If exact path is initialized (has codegraph.db), use it |
| 248 | if (isInitialized(absolutePath)) { |
| 249 | return absolutePath; |
| 250 | } |
| 251 | |
| 252 | // Walk up to find nearest parent with CodeGraph initialized |
| 253 | // Note: findNearestCodeGraphRoot finds any .codegraph folder, but we need one with codegraph.db |
| 254 | let current = absolutePath; |
| 255 | const root = path.parse(current).root; |
| 256 | |
| 257 | while (current !== root) { |
| 258 | const parent = path.dirname(current); |
| 259 | if (parent === current) break; |
| 260 | current = parent; |
| 261 | |
| 262 | if (isInitialized(current)) { |
| 263 | return current; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // Not found - return original path (will fail later with helpful error) |
| 268 | return absolutePath; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Format a number with commas |
no test coverage detected