* Write `.codegraph/.gitignore` if it's absent, or upgrade a stale * CodeGraph-generated default in place; a user-customized file is left alone. * Best-effort — returns `false` only if a needed write failed.
(gitignorePath: string)
| 621 | * Best-effort — returns `false` only if a needed write failed. |
| 622 | */ |
| 623 | function ensureGitignore(gitignorePath: string): boolean { |
| 624 | let existing: string | null; |
| 625 | try { |
| 626 | existing = fs.readFileSync(gitignorePath, 'utf-8'); |
| 627 | } catch { |
| 628 | existing = null; // absent (ENOENT) or unreadable — (re)create below |
| 629 | } |
| 630 | // Current default or a user-authored file: nothing to do. |
| 631 | if (existing !== null && !isStaleDefaultGitignore(existing)) return true; |
| 632 | try { |
| 633 | fs.writeFileSync(gitignorePath, GITIGNORE_CONTENT, 'utf-8'); |
| 634 | return true; |
| 635 | } catch { |
| 636 | return false; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Create the .codegraph directory structure |
no test coverage detected