(data: ClaudeMdIndexData)
| 248 | } |
| 249 | |
| 250 | export function generateClaudeMdIndex(data: ClaudeMdIndexData): string { |
| 251 | const { docsPath, sections, outputFile } = data |
| 252 | |
| 253 | const parts: string[] = [] |
| 254 | |
| 255 | parts.push('[Next.js Docs Index]') |
| 256 | parts.push(`root: ${docsPath}`) |
| 257 | parts.push( |
| 258 | 'STOP. What you remember about Next.js is WRONG for this project. Always search docs and read before any task.' |
| 259 | ) |
| 260 | const targetFile = outputFile || 'CLAUDE.md' |
| 261 | parts.push( |
| 262 | `If docs missing, run this command first: npx @next/codemod agents-md --output ${targetFile}` |
| 263 | ) |
| 264 | |
| 265 | const allFiles = collectAllFilesFromSections(sections) |
| 266 | const grouped = groupByDirectory(allFiles) |
| 267 | |
| 268 | for (const [dir, files] of grouped) { |
| 269 | parts.push(`${dir}:{${files.join(',')}}`) |
| 270 | } |
| 271 | |
| 272 | return parts.join('|') |
| 273 | } |
| 274 | |
| 275 | function collectAllFilesFromSections(sections: DocSection[]): string[] { |
| 276 | const files: string[] = [] |
no test coverage detected