(cwd: string)
| 348 | const GITIGNORE_ENTRY = '.next-docs/' |
| 349 | |
| 350 | export function ensureGitignoreEntry(cwd: string): GitignoreStatus { |
| 351 | const gitignorePath = path.join(cwd, '.gitignore') |
| 352 | const entryRegex = /^\s*\.next-docs(?:\/.*)?$/ |
| 353 | |
| 354 | let content = '' |
| 355 | if (fs.existsSync(gitignorePath)) { |
| 356 | content = fs.readFileSync(gitignorePath, 'utf-8') |
| 357 | } |
| 358 | |
| 359 | const hasEntry = content.split(/\r?\n/).some((line) => entryRegex.test(line)) |
| 360 | |
| 361 | if (hasEntry) { |
| 362 | return { path: gitignorePath, updated: false, alreadyPresent: true } |
| 363 | } |
| 364 | |
| 365 | const needsNewline = content.length > 0 && !content.endsWith('\n') |
| 366 | const header = content.includes('# next-agents-md') |
| 367 | ? '' |
| 368 | : '# next-agents-md\n' |
| 369 | const newContent = |
| 370 | content + (needsNewline ? '\n' : '') + header + `${GITIGNORE_ENTRY}\n` |
| 371 | |
| 372 | fs.writeFileSync(gitignorePath, newContent, 'utf-8') |
| 373 | |
| 374 | return { path: gitignorePath, updated: true, alreadyPresent: false } |
| 375 | } |
| 376 | |
| 377 | type WorkspaceType = 'pnpm' | 'npm' | 'yarn' | 'nx' | 'lerna' | null |
| 378 |
no test coverage detected