Building CLI tool with Go to clean up node_modules

Building CLI tool with Go to clean up node_modules

Introduction
Migrating to a new computer can be a hard task, especially when you realize that a significant amount of disk space is consumed by node_modules directories. As a developer, I encountered this issue and decided to create a command-line tool (CLI) to manage and delete old node_modules directories. This post details the journey of building and publishing the dead_modules CLI tool using Go, Homebrew, and GitHub Actions.
Why a CLI Tool?
While migrating my computer, I noticed that node_modules directories were taking up a substantial amount of space. These directories, often left over from various projects, can accumulate quickly. A CLI tool to manage and delete these directories seemed like a perfect solution to reclaim disk space efficiently.
Setting Up the Project
First, I set up a new Go project. The CLI tool needed to search for node_modules directories and delete selected ones.
Writing the Go Code
Here is the initial code to create the dead_modules CLI tool:
Testing the CLI
After writing the code, I built and tested the CLI tool:
Creating a Homebrew Tap
To make the tool easily installable, I decided to publish it via Homebrew. I created a new GitHub repository for the Homebrew tap:
Writing the Homebrew Formula
Next, I wrote the formula for the dead_modules tool:
Automating Updates with GitHub Actions
To automate the process of updating the Homebrew formula, I set up GitHub Actions:
Setting Up GitHub Secrets
I added my GitHub Personal Access Token (PAT) as a secret in my GitHub repository settings, naming it GH_PAT.
Creating a Release
I created a new release on GitHub to trigger the GitHub Actions workflow and update the Homebrew tap formula:
  1. Go to the dead_modules repository on GitHub.
  2. Click on "Releases".
  3. Click "Draft a new release".
  4. Tag the release (e.g., `v1.0.2`).
  5. Publish the release.
Conclusion
By following this journey, I successfully created and published a CLI tool to manage and delete old node_modules directories. The tool is now easily installable via Homebrew, thanks to the automated workflow set up with GitHub Actions. This solution not only helped me clean up my computer but also provides a useful tool for other developers facing the same issue.
Installation
To install dead_modules, you can run:
Usage
Run the following command to use the tool: