DEV Community

Cynthia Fotso
Cynthia Fotso

Posted on

Releasing My First Open-Source CLI Tool: Lessons from Publishing Repository-Context-Packager

As a developer, releasing your first open-source project is an exciting milestone. It transforms code from a personal project into something others can use, install, and contribute to. I'll walk you through my experience for the Repository-Context-Packager release, a command-line tool that packages Git repository context for sharing with Large Language Models (LLMs). I'll cover the tools I chose, the release process, what I learned, the changes made, and how users can now install and use the tool.

Choosing the Release Tool and Package Registry

For this project, I chose npm as both the release tool and the package registry. npm (Node Package Manager) is the default package manager for Node.js projects and hosts the largest JavaScript/TypeScript package registry at npmjs.com. Since my tool is built with Node.js and uses Commander.js for CLI functionality, npm was a natural fit as it handles packaging, versioning, and distribution seamlessly.

  • Why npm? It's free for public packages, widely used in the JavaScript ecosystem, and integrates directly with Node.js. An alternative like GitHub Packages was considered, but npm made it ideal for ease of use.

The Release Process

Releasing a package on npm involves several steps, starting from preparing your code to publishing. Here's a detailed breakdown of what I did:

  1. Prepare the Package:
    -Ensured the project was in a Git repository (Repository-Context-Packager) with all changes committed. I ran git status to check for uncommitted files.
    -Updated package.json to include essential fields: name (unique and available), version (starting at 1.0.0), description, files (to include only necessary files), and dependencies.

  2. Test Locally:
    -Ran the tool locally using repo-packager . or node ./bin/cli.js . to ensure it worked.
    -Executed tests with npm test to verify functionality making sure nothing was broken.
    -Linked the package globally for testing: npm link (optional, for development).

  3. Git Tagging and Version Bumping:
    -To create tags manually, I used git tag to list existing tags, git tag -a v0.9.0 -m "Release version 0.9.0" to create an annotated tag with a message, and also git push --tags to push all tags to the remote repository.
    -Used npm version patch to increment the version from 0.9.0 to 1.0.0, and created a Git commit. This required a clean working directory, so I committed changes first.
    -I then pushed the new commit to GitHub with the command git push origin main. This ensured the remote repository reflected the release.

  4. Publish:
    -Logged in to npm with the command npm login
    -Published the package using the command npm publish. This uploaded the package to the registry, making it publicly available.
    -Verified it was published by checking npmjs.com or running npm view repo-context-packager.

What I Learned and Challenges Faced

This was my first npm release, and it was a steep but rewarding learning curve.

  • Getting Stuck: Initially, npm version failed because my Git working directory wasn't clean (uncommitted changes). I learned to always commit before versioning. Another little issue was forgetting to update the README for end-users, which I fixed after noticing.
  • I had some aha moments as well. I realized how crucial a unique package name is; npm rejects duplicates, which I didn't know. My release was first rejected when I tried to publish with the name repository-context-packager in package.json confirming the name already existed; it only worked after I used the unique package name repo-context-packager. Also, the bin field in package.json is what makes a CLI tool executable globally after install, which was a game-changer for usability.

Open-source releasing isn't just coding but it's about documentation, versioning, and user experience. I gained confidence in npm's ecosystem and the importance of semantic versioning (patch, minor, major). It also highlighted the value of testing in a clean environment to catch issues early.

Alterations to Code, Files, and Build

I mostly focused on packaging and documentation as the project was already well-structured, so no refactoring was needed.
No change was made to the code's functionality. I updated package.json for the unique name, version, and metadata, updated README.md with installation instructions, usage examples making it user-friendly. Also, no major build changes; the project uses Jest for testing and has a simple npm test script. I ensured files in package.json included only essentials (bin, src, LICENSE, README.md) to keep the package lightweight.

User Testing Session

I conducted a user testing session with a fellow developer (a classmate in another course) to simulate real-world usage as this usually reveals blind spots.
I watched him go through the README.md file and he succeeded in installing the tool globally. He tried to run it but it didn't work as he was not in a Git repository. He opened one and going through the listed examples, he could have it work.
On my end, I also tried to run it on another computer and it worked as I expected.
The testing session was valuable and it reinforced my thinking that documentation is as important as code, and iterative testing prevents post-release issues.

How Users Install and Use the Project Now

Now that Repository-Context-Packager is released, users can install and use it easily via npm following the below steps:

⦁ Installation
Run this command in your terminal:
npm install -g repo-context-packager
This installs the repo-packager command globally, requiring Node.js 18+ and Git.

⦁ Usage
Navigate to any Git repository and run:
repo-packager .
This generates repo-context.txt with project context. You have more options below:
Save to a custom file: repo-packager . --output my-context.txt
Filter files: repo-packager . --include "*.js"
For help: repo-packager --help

Conclusion

Releasing Repository-Context-Packager was a fantastic introduction to open-source publishing. Choosing npm simplified the process, but it taught me the importance of preparation, documentation, and user feedback. If you're releasing your first project, start small, test thoroughly, and iterate based on real users. I'm excited to see how the community uses this for free to contribute or report issues on GitHub!

Top comments (0)