* 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)
| 198 | * (must have .codegraph/codegraph.db, not just .codegraph/lessons.db) |
| 199 | */ |
| 200 | function resolveProjectPath(pathArg?: string): string { |
| 201 | const absolutePath = path.resolve(pathArg || process.cwd()); |
| 202 | |
| 203 | // If exact path is initialized (has codegraph.db), use it |
| 204 | if (isInitialized(absolutePath)) { |
| 205 | return absolutePath; |
| 206 | } |
| 207 | |
| 208 | // Walk up to find nearest parent with CodeGraph initialized |
| 209 | // Note: findNearestCodeGraphRoot finds any .codegraph folder, but we need one with codegraph.db |
| 210 | let current = absolutePath; |
| 211 | const root = path.parse(current).root; |
| 212 | |
| 213 | while (current !== root) { |
| 214 | const parent = path.dirname(current); |
| 215 | if (parent === current) break; |
| 216 | current = parent; |
| 217 | |
| 218 | if (isInitialized(current)) { |
| 219 | return current; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | // Not found - return original path (will fail later with helpful error) |
| 224 | return absolutePath; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Format a number with commas |
no test coverage detected