DEV Community

Mayank Kumar
Mayank Kumar

Posted on

Releasing dev-mate-cli on npm

This week, I successfully released my CLI tool, dev-mate-cli, to the public npm registry. It was a rewarding experience that involved learning and refining my project. Here’s a detailed account of how I did it, along with lessons I learned and tips for anyone looking to release their own package.

dev-mate-cli - npm

command line tool using LLMs for code documentation. Latest version: 1.0.3, last published: 3 hours ago. Start using dev-mate-cli in your project by running `npm i dev-mate-cli`. There are no other projects in the npm registry using dev-mate-cli.

favicon npmjs.com

Choosing a Release Tool and Registry

As my project was written in TypeScript and designed as a Node.js CLI tool, I chose npm for hosting my package. It’s the most popular package registry for JavaScript developers, and I was already familiar with using it to install dependencies. Publishing to npm made sense, as it would make my tool accessible to a broad audience.

You can create an account at npmjs.com. Once your account is ready, publishing a package involves using simple and well-documented commands.

Process for Releasing

  1. Preparing the Project for Release

    • I added a bin field in my package.json file to make my CLI executable. This field maps the CLI command (dev-mate-cli) to the script that should run when the command is invoked.
    • Ensured all needed dependencies, like dotenv, were correctly listed in the dependencies field of package.json rather than devDependencies. This is critical because devDependencies are not installed when users download the package.
  2. Testing Locally with npm link

    • Before publishing, I ran npm link to simulate how users would install and use the package globally. This helped me test the CLI commands and catch any errors.
  3. Building the Project

    • Since the project was written in TypeScript, I ensured my build script compiled the source code correctly. Running npm run build generated the necessary JavaScript files in a dist folder.
  4. Publishing the Package

    • After verifying everything worked locally, I logged into npm using npm login and published the package.
    • The --access public flag was required since I wanted my package to be publicly available.
       npm publish --access public
    

User Testing

For the testing phase, I asked a fellow developer to try out dev-mate-cli. The tool worked as intended, and she found it easy to use with the provided instructions. Her main suggestion was improving the README to make the setup process clearer. Specifically, she recommended placing critical setup steps (like environment variable configuration) at the top of the documentation, which I promptly implemented.

Lessons Learned

  • Managing Dependencies: One of the key issues I encountered was the dotenv module being listed as a devDependency. Since npm doesn’t include devDependencies in the published package, this caused a runtime error. This was a valuable reminder to double-check the dependencies section before publishing.
  • Streamlining Documentation: User testing with a developer revealed areas for improvement in my README. For instance, moving instructions for setting up environment variables (API_KEY and BASE_URL) to the installation section made it easier for users to get started.

Overall, publishing dev-mate-cli was a rewarding process, filled with valuable lessons. I hope this blog helps other developers navigate the npm publishing process more easily. If you’re building your own CLI tool, feel free to reach out with questions or suggestions!

Top comments (0)