Progress on the CLI — Sept 23, 2020
So…this has been a week. First week back to classes and it’s quite overwhelming I have to say. However, we didn’t come here to hear me grovel. Lets get into what I’ve learnt and what I have tried with my CLI.
I won’t go through the entire process since I’m no professional and I’m afraid that I’ll provide bad information. However, in brief, the steps I did was:
1: make a directory with the name of your CLI and inside it run the good ol’ npm init
2: create a bin folder with an index.js inside with this “shebang” at the top: #!/usr/bin/env node
3:change the main value in your package.json into bin/index and add a bin key below license.
4: open the terminal and inside your project root enter node . which will run your index.js inside the terminal! Awesome!
5: To be able to use this CLI from anywhere on your machine (as I would like to for this project) enter in the terminal npm install -g to install your CLI globally! Even more Awesome!
Then you have a CLI ready to use whenever! I very, VERY, VERY, briefly went over the steps involved and you shouldn’t treat this as a tutorial, please look at the links above the list to see how to actually do it, especially the one by Okta which is the one I used.
After I got a CLI that actually works I set out and tried to make it colorful with this great node module called Chalk! It’s super simple to use and the documentation for it can all be found here! Then I added the capability to accept arguments for my CLI with another module called Yargs. This allowed me to have not only arguments but also a -help that comes built in. Once again, look at the Okta tutorial for further information.
As of now I’m attempting to figure out how to use fs.readFile() to get a file name the user would pass in as an argument and then colour said links! I know I’ll need to use a regex to grab the individual links from the file which I’ll have to do some hefty research because my knowledge in regex is very lacking. Then, it’s a matter of debugging, beautifying and publishing!
And that’s all for this progress report! Hope you enjoyed this and if you have any ideas or criticisms on what I can do or am doing, please leave a comment and I will respond as soon as I can.