repomix
Version:
A tool to pack repository contents to single file for AI consumption
70 lines (55 loc) • 2.04 kB
JavaScript
import Handlebars from 'handlebars';
import { generateTreeStringWithLineCounts } from '../file/fileTreeGenerate.js';
import { registerHandlebarsHelpers } from '../output/outputStyleUtils.js';
registerHandlebarsHelpers();
export const generateSummarySection = (context, statisticsSection) => {
const template = Handlebars.compile(`{{{generationHeader}}}
This is a reference codebase organized into multiple files for AI consumption.
It is designed to be easily searchable using grep and other text-based tools.
This skill contains the following reference files:
| File | Contents |
|------|----------|
| \`project-structure.md\` | Directory tree with line counts per file |
| \`files.md\` | All file contents (search with \`## File: <path>\`) |
| \`tech-stacks.md\` | Languages, frameworks, and dependencies per package (search with \`## Tech Stack: <path>\`) |
| \`summary.md\` | This file - purpose and format explanation |
## Usage Guidelines
{{{summaryUsageGuidelines}}}
{{{summaryNotes}}}
{{
{{{statisticsSection}}}
{{/if}}
`);
return template({ ...context, statisticsSection }).trim();
};
export const generateStructureSection = (context) => {
if (!context.directoryStructureEnabled) {
return '';
}
const filePaths = context.processedFiles.map((f) => f.path);
const treeStringWithLineCounts = generateTreeStringWithLineCounts(filePaths, context.fileLineCounts);
const template = Handlebars.compile(`
\`\`\`
{{{treeString}}}
\`\`\`
`);
return template({ treeString: treeStringWithLineCounts }).trim();
};
export const generateFilesSection = (context) => {
if (!context.filesEnabled) {
return '';
}
const template = Handlebars.compile(`
{{
{{{../markdownCodeBlockDelimiter}}}{{{getFileExtension this.path}}}
{{{this.content}}}
{{{../markdownCodeBlockDelimiter}}}
{{/each}}
`);
return template(context).trim();
};