Dependencies

  • chalk: colorize the output

  • clear: clears the terminal screen

  • clui: draws command line tables, gauges and spinners

  • figlet: creates ASCII art from text

  • inquirer - create interactive command line user interface

  • minimist - parses argument options

  • preferences - manage CLI application encrypted preferences

chalk

  • chalk.<style>[.<style>...](string, [string...])

    chalk.red.bold.underline(‘Hello’, ‘World’)

  • chalk`string {<style> <style>… string} string`

    chalk`There are { bold 5280 feet } in a mile `

clear

1
2
const clear = require('clear')
clear()

clui

Display

  • Gauge

  • PrograssBar

  • Sparklines

  • Spinners

on Terminal

figlet

Display ASCII font on Terminal

1
2
3
4
5
6
7
8
figlet.text('Boo', {
font: 'Ghost',
horizontalLayout: 'default',
verticalLayout: 'default'
}, function (err, data) {
if (err) return console.log(err)
return console.log(data)
})
1
2
3
4
5
figlet.textSync('Boo', {
font: 'Ghost',
horizontalLayout: 'default',
verticalLayout: 'default',
})

inquirer

A collection of common interactive command line user interface.

  • inquirer.prompt(questions) => promise

    • questions an Array containing Question Object(using the reactive interface, you can also pass a Rx.observable instance)

      • Question Object:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      // {
      // type: string, //['input', 'confirm', 'list', 'rawlist', 'expand', 'checkbox', 'password', 'editor']
      // name: string, // the name to use when storeing the answer in the answer hash
      // message: string|function, // The question to print, if defined as a function, the first parameter will be the current inquirer session answer
      // default: string|number|array|function, // default value to use
      // choices: array|function,
      // validate: function, // receive the user input and answers hash, should return true if the value is valid, and an error message(string) otherwise. If a false is returned, a default error message is provided.
      // filter: function, //
      // when: function|boolean, //
      // pageSize: number, //
      // }

      minimist

preferences

Make CLI globally available

Add a shebang line to the top of index.js

1
#!/usr/bin/env node

Then add a bin prototype to package.json.

1
2
3
"bin": {
"cli-init": "./index.js"
}