MCPcopy
hub / github.com/vercel/next.js / ensureGitignoreEntry

Function ensureGitignoreEntry

packages/next-codemod/lib/agents-md.ts:350–375  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

348const GITIGNORE_ENTRY = '.next-docs/'
349
350export 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
377type WorkspaceType = 'pnpm' | 'npm' | 'yarn' | 'nx' | 'lerna' | null
378

Callers 1

runAgentsMdFunction · 0.90

Calls 7

readFileSyncMethod · 0.80
someMethod · 0.80
splitMethod · 0.80
includesMethod · 0.80
testMethod · 0.65
joinMethod · 0.45
endsWithMethod · 0.45

Tested by

no test coverage detected