(projectRoot: string)
| 446 | * Note: Only throws if codegraph.db already exists, not just if .codegraph/ exists. |
| 447 | */ |
| 448 | export function createDirectory(projectRoot: string): void { |
| 449 | const codegraphDir = getCodeGraphDir(projectRoot); |
| 450 | const dbPath = path.join(codegraphDir, 'codegraph.db'); |
| 451 | |
| 452 | // Only throw if CodeGraph is actually initialized (db exists) |
| 453 | // .codegraph/ folder alone is fine |
| 454 | if (fs.existsSync(dbPath)) { |
| 455 | throw new Error(`CodeGraph already initialized in ${projectRoot}`); |
| 456 | } |
| 457 | |
| 458 | // Create main directory (if it doesn't exist) |
| 459 | fs.mkdirSync(codegraphDir, { recursive: true }); |
| 460 | |
| 461 | // Write .gitignore inside .codegraph (create if absent, upgrade a stale |
| 462 | // pre-wildcard default left by an older version — issue #788). |
| 463 | ensureGitignore(path.join(codegraphDir, '.gitignore')); |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Remove the .codegraph directory |
no test coverage detected