Refered to the documentation Lets-build-a-cli-with-node-js which made it atleast 10 times easier to understand how I can build my own cli from scratch, this is a fairly simple one where the entered string gets translated to a language that has been mentioned in the command line besied the option provided(-l in this case). As someone who is exploring git, github and bash commands as well, this was a small project that honestly felt extremely fun to work on though it did take some tries to make it work. If youre using the latest versions of yark, chalk etc etc the above documentation's code might need some tweaks (mine did).
- Chalk : Adds colors and styles to the console output. chalk-package
- Yargs : Helps in building the command line interface. yargs-package
- Google Translate API : Allows your CLI to translate text directly in the terminal. google-translate-reference
- Figlet : Adds loading spinners while performing async tasks (e.g., fetching data). figlet-package
- Boxen : Draws boxes around text in the terminal. boxen-package
-
Fork this repository on GitHub.
-
Clone your fork to your local machine:
git clone <your-fork-url> cd <repo-name>
-
Install the required dependencies:
npm install
-
Link the CLI globally so you can use it anywhere:
npm install -g
This will register your CLI command system-wide.
-
Run the CLI:
<cli-command>
This will guide you on how to translate text or check the CLI version.
This means a previous version of the CLI is already linked. To fix:
npm uninstall -g <cli-command>
npm linkOr force overwrite:
npm link --forceThis happens when dependencies are missing. To fix:
npm installMake sure your global npm bin directory is in your system PATH.
On macOS/Linux:
echo $PATHOn Windows:
echo $env:PATH