(projectRoot: string)
| 642 | * Note: Only throws if codegraph.db already exists, not just if .codegraph/ exists. |
| 643 | */ |
| 644 | export function createDirectory(projectRoot: string): void { |
| 645 | const codegraphDir = getCodeGraphDir(projectRoot); |
| 646 | const dbPath = path.join(codegraphDir, 'codegraph.db'); |
| 647 | |
| 648 | // Only throw if CodeGraph is actually initialized (db exists) |
| 649 | // .codegraph/ folder alone is fine |
| 650 | if (fs.existsSync(dbPath)) { |
| 651 | throw new Error(`CodeGraph already initialized in ${projectRoot}`); |
| 652 | } |
| 653 | |
| 654 | // Create main directory (if it doesn't exist) |
| 655 | fs.mkdirSync(codegraphDir, { recursive: true }); |
| 656 | |
| 657 | // Write .gitignore inside .codegraph (create if absent, upgrade a stale |
| 658 | // pre-wildcard default left by an older version — issue #788). |
| 659 | ensureGitignore(path.join(codegraphDir, '.gitignore')); |
| 660 | } |
| 661 | |
| 662 | /** |
| 663 | * Remove the .codegraph directory |
no test coverage detected