(projectRoot: string)
| 1018 | * Note: Only throws if codegraph.db already exists, not just if .codegraph/ exists. |
| 1019 | */ |
| 1020 | export function createDirectory(projectRoot: string): void { |
| 1021 | const codegraphDir = getCodeGraphDir(projectRoot); |
| 1022 | |
| 1023 | // Only throw if CodeGraph is actually initialized (db with a schema). |
| 1024 | // .codegraph/ folder alone — or a schema-less codegraph.db left by an |
| 1025 | // interrupted init (#1895) — is fine: initialize() adds the schema to it. |
| 1026 | if (isInitialized(projectRoot)) { |
| 1027 | throw new Error(`CodeGraph already initialized in ${projectRoot}`); |
| 1028 | } |
| 1029 | |
| 1030 | // Create main directory (if it doesn't exist) |
| 1031 | fs.mkdirSync(codegraphDir, { recursive: true }); |
| 1032 | |
| 1033 | // Write .gitignore inside .codegraph (create if absent, upgrade a stale |
| 1034 | // pre-wildcard default left by an older version — issue #788). |
| 1035 | ensureGitignore(path.join(codegraphDir, '.gitignore')); |
| 1036 | } |
| 1037 | |
| 1038 | /** |
| 1039 | * Remove the .codegraph directory |
no test coverage detected