This project is a simple CLI using a lot of great tools.
It uses ESM for packaging.
It's inspired from this article https://www.twilio.com/blog/how-to-build-a-cli-with-node-js, but not limited to.
- esm : nodejs module management
- arg : for commmand line arguments processing
- chalk : for ANSI colorization of the command line
- inquirer : modules that promps the user
- marked : Markedown compilation lib
- marked-terminal : displays Markedown (marked) to the terminal
Install dependencies
npm install
Install the CLI as an executable in you npm local installation
npm link
You can use the CLI with options and arguments like so :
$ cli-project Javascript -g
Your options were {
skipPrompts: false,
help: false,
git: true,
template: 'Javascript',
runInstall: false
}
Processing...
You can also be prompted if no options are provided
$ cli-project
? Please choose which project template to use (Use arrow keys)
❯ JavaScript
TypeScript
? Initialize git repository (false)
Your options were {
skipPrompts: false,
help: false,
git: false,
template: 'JavaScript',
runInstall: false
}
Processing...
The help content is written with Markdown from HELP.md
$ cli-project -h
# CLI written with NodeJs
## Sub Title
This is a super CLI
### How to use it ?
1. one
2. two
3. three
This is a sample
### TODO
What's missing ?
* [X]: option 1
-
src/cli.js
: is reponsible for the CLI management which are controls on options and arguments -
src/main.js
: where resides your logic. It receives the JSON object with validated options -
src/help.js
: helper function tha handle the display of HELP.md -
bin/cli-project
: the project use ESM, this is the main project/module declaration file