DEV Community

Cover image for Automate your workflow using NodeJS CLI programs
Karan Sharma
Karan Sharma

Posted on

Automate your workflow using NodeJS CLI programs

Automating your workflow shifts the focus from doing the unnecessary and repetitive task to a more important thing and prevents us from procrastinating. As a JS developer, I always want something that prevents fiddling for things around BASH while writing my workflows and gives me confidence and control over the task in hand.

Steps for Writing a simple CLI program

In this, I will take one trivial task of opening the projects or run specific commands like running tests over them.

1) Always begin your scripts with
Start of Script
This is to specify that it is a node script and to be treated as CLI program.

2) Helpers for making it more easy and fun
This list includes
helper programs

3) Breakdown your requirements in form of JSON object
Writing your requirements in JSON makes it easy to extend and review changes later on.
Config

4) Writing the workflow
Don't over complicate things and just write simple reusable functions that can be used across all your CLI tools.

main flow

5) Making it installable and accessible from anywhere.
Make an entry in package.json of your project specifying the initial point of the script.

trick
and then running npm link in the directory will install it like any other CLI program in /usr/bin.
This little trick makes it accessible when used from anywhere like in the above example workflow can be invoked from CLI globally.

Alt Text

You can find the complete code for this tool at my github repo.

GitHub logo curiouskaran / projectOpener

Open a project that has alias listed in a json

Thanks for reading! Please let me know in the comments for any thoughts and improvements.

Top comments (0)