yamadashy / repomix

📦 Repomix (formerly Repopack) is a powerful tool that packs your entire repository into a single, AI-friendly file. Perfect for when you need to feed your codebase to Large Language Models (LLMs) or other AI tools like Claude, ChatGPT, and Gemini.
MIT License
4.36k stars 202 forks source link

Refactor: Centralize renderContext & style generation logic for output styles #125

Closed iNerdStack closed 1 month ago

iNerdStack commented 1 month ago

The renderContext was repeated in all three style generation files including the logic to generate

/src/core/output/outputStyles/plainStyle.ts /src/core/output/outputStyles/xmlStyle.ts /src/core/output/outputStyles/markdownStyle.ts

export const generateMarkdownStyle = (outputGeneratorContext: OutputGeneratorContext) => {
  const template = Handlebars.compile(markdownTemplate);

  const renderContext = {
    generationHeader: generateHeader(outputGeneratorContext.generationDate),
    summaryPurpose: generateSummaryPurpose(),
    summaryFileFormat: generateSummaryFileFormat(),
    summaryUsageGuidelines: generateSummaryUsageGuidelines(
      outputGeneratorContext.config,
      outputGeneratorContext.instruction,
    ),
    summaryNotes: generateSummaryNotes(outputGeneratorContext.config),
    summaryAdditionalInfo: generateSummaryAdditionalInfo(),
    headerText: outputGeneratorContext.config.output.headerText,
    instruction: outputGeneratorContext.instruction,
    treeString: outputGeneratorContext.treeString,
    processedFiles: outputGeneratorContext.processedFiles,
  };

  return `${template(renderContext).trim()}\n`;
};

Proposed Solution

Move the common logic in these files into a shared utility file. This will make it easier to maintain as you add new styles and also add new parameters for renderContext in the future

yamadashy commented 1 month ago

Hi, @iNerdStack ! Thanks for bringing this to my attention!

You're absolutely right! Now that you mention it, it does make sense. It seems like a good approach to place a method for creating the renderContext in outputGenerate, and then pass this renderContext to each generate method. Taking it a step further, we could even consider having xmlStyle.ts and others just return the template, and then do the actual rendering in outputGenerate.

iNerdStack commented 1 month ago

Exactly, that's what I was thinking too. Can you assign me to this, and I can make a proposed PR or you can work that out?

yamadashy commented 1 month ago

@iNerdStack If you have the time, I’d really appreciate it! Thank you, I’ll go ahead and assign this to you.

yamadashy commented 1 month ago

Thank you for addressing this issue. If there are no further concerns, I'll go ahead and close this.

yamadashy commented 1 month ago

I realized that caching the compiled templates could lead to further optimization, so I've created a PR for this.

iNerdStack commented 1 month ago

That's good, Its all good now. Thank you for accepting my changes

yamadashy commented 1 month ago

I really appreciate your work on this. I'll go ahead and close this issue now.

Please don't hesitate to reach out if you have any more ideas or suggestions in the future!