DEV Community

DenisC
DenisC

Posted on

Read and Learn from Open Source Projects

This week, I am taking a look at Repomix, a larger project similar to my project, to find some features that I can also implement in my project. There are both a web version and CLI version of Repomix, I will focus on the codes for CLI to find the features to be worked on.

Finding the feature

The first step is to find the feature that I want to add in my project. The best place to find the features is README.md, which basically summarizes everything about the project. In the README.md, I found the Command Line Options Section that shows all the features in the tool. At first, I found options such as --no-files and -o, --output <file>, which are the features I already have in my project. Then, I found the --remove-empty-lines option, which removes blank lines from all files when writing file contents. This could be a useful feature to reduce the file size and no. of lines in the output file, such that it does not exceed the size/line limit for AI analysis.

Reading the codes through AI

Now that I am interested in the --remove-empty-lines option, I have to check relevant codes to get an insight of how to implement the feature. The first step I did was to use the web version of Repomix itself to pack its own Git repo, and upload the xml file to AI to understand its basic structure. That's what Repomix is for, right? Then, I asked AI to find relevant files for the --remove-empty-lines option, it did find the checking for the emptyLinesRemoved flag in outputGenerate.ts and outputStyleDecorate.ts in src/core/output, but it didn't find the logic of how the empty lines are actually removed.

Reading the codes manually

Using AI tool was a good starting point to help narrow down the scope that I looked for. Now I can use my knowledge as a programmer to pinpoint the codes that I need - the logic of how the empty lines are actually removed. From outputGenerate.ts, I first checked the variables, and found the file contents should be stored in the processedFiles variable. I then looked into the imported modules, and found the ProcessedFile from src/core/file/ directory, so I started checking the files in file/ directory to find the logic for empty line removal. After a while, I found the removeEmptyLines function in the BaseManipulator class in fileManipulate.ts, which was exactly the logic that handles empty line removal! At this point, I've got enough reference for implementing the new feature, and may start prototyping in my own repo.

Top comments (0)