Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
I was going through some React article and saw create-react-app command. That made me realise I never bothered checking how to create your own CLI tools like Vue-Cli, create-react-app. So I looked it up, and it is very easy to create a basic CLI tool for yourself.
You can create a minimal one with just one configuration in your package.json. But I wanted a basic tool, with input from the user as well as multiple custom commands. So I came across inquirer-js and commander-js to do just that.
We will create our magical command âCthulhuâ, and then we would âwakeâ him up.
Below is the Inquirer, that takes userâs input to pass to the command. Here Iâve created inquirer in a âpromptâ function, and the input prompts for the user are in âipâ array.
Once we know what questions we are going to ask the user via inquirer, we define our custom commands. Here we create command âwakeâ to wake up our Cthulhu.
Now the last and the most important steps:
Convert your own commands to shell commands
1. We add â#!/usr/bin/env nodeâ to the top of the js file where we defined our command using commander-js.2. Add the following line to our package.json file.
"bin": {"cthulhu" : "path to file in point 1"}
3. Run the following command to build the symlink:
yarn link / npm link
And thatâs it! Thatâs all is needed to create your own command that might just wake up Cthulhu. Go ahead, give it a try. Run your own command as below:
cthulhu wake 1200
Vue-CLI uses the same pattern here and defines the main vue command here.
I am open to learning and looking for constructive feedback. If you liked the article, do provide feedback!
P.S. Thanks to Ray Dalioâs Principles for providing background for my sticky notes. Next step is to learn to take better photos.
Learn to create custom CLI tool with Node and 5 sticky notes. was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.