DEV Community

Steven Hur
Steven Hur

Posted on

Multi-Format Outputs for Repo_Code_Packager

Hello, I'm back.
I'm here to talk about the new feature upgrade for my command-line tool, Repo_Code_Packager. Users can now get their code files in either human-readable Markdown or machine-readable JSON, all controlled by a new --style flag.

A single output format doesn't fit every need. While the original Markdown format is perfect for pasting into chat, a structured format like JSON is far more useful for scripting. Well made programs should be able to accommodate different kind of usage problems.

Repomix
This entire feature was directly inspired by my analysis of Repomix. I was impressed by how well Repomix handled its --style option, allowing users to choose between XML, Markdown, JSON, and plain text.

It made me realize that the true power of a utility tool comes from its flexibility. By offering different options, the tool becomes useful to variety users. It did take me awhile to find the related files and source codes from the project but I utilized Github web search feature and VScode search function to find the methods that I needed to complete this task.

What I Did Similarly to Repomix
The main aspect that I used from Repomix was the separating data collection from data presentation.

Previously, my script would gather a piece of information and immediately format it into a Markdown string. Now, it follows a two-step process:

  1. Collect Everything First: The script gathers all the data—Git info, directory structure, file contents, and summary—and stores it in a single, structured Python dictionary called report_data.
  2. Format: Only when all the data is successfully collected, the script decide how to present the data. It looks at the --style argument and passes the report_data dictionary to the user's choice of format.

This is very similar to how Repomix uses its RenderContext object to hold all the data before passing it to a template.

What I Did Differently?
The main difference lies in the implementation details. Repomix uses the Handlebars templating engine to render its Markdown and XML outputs.
Since my Code_Repo_Packager is in python, I decided to take an approach that does not use dependencies. I created format_markdown function and format_json for JSON style. The format_markdown function uses Python's f-strings to build the final report. For the JSON output, the format_json function leverages the built-in json library to serialize the collected data into a string.

It is fun to take a open source code and apply it into my own project. I always thought this action would be illegal to do so but as long as I stay keen with the license policy, I should do this more to improve my skill to develop.

Repo_Code_packager
Repomix

Top comments (0)