common-bin-plus

advanced common-bin for cli usage

Usage no npm install needed!

<script type="module">
  import commonBinPlus from 'https://cdn.skypack.dev/common-bin-plus';
</script>

README

common-bin-plus

advanced common-bin for cli usage

NPM version build status Test coverage David deps Known Vulnerabilities NPM download

Installation

npm i common-bin-plus --save

Write your own cli

see common-bin for more details.

Feature

Logger

https://github.com/unjs/consola

this.logger.info('hello info level');
this.logger.warn('hello warn level');
this.logger.error(new Error('hello error level'));
this.logger.debug('hello debug level');

debug log is disabled by default, you could enable it by:

  • command line argv: --verbose
  • process env: DEBUG=* or DEBUG=${cliName}
  • programmatically: logger.level = 'DEBUG'

Prompt

const answers = await this.prompt([
  {
    type: 'input',
    name: 'name',
    message: 'What is your name:',
  }, {
    type: 'list',
    name: 'type',
    message: 'Choose a boilerplate:',
    choices: [ 'empty', 'simple', 'plugin', 'framework' ],
  },
], {});

this.logger.info(answers);

Unit Testing

Use coffee :

const coffee = require('coffee');

describe('test/index.test.js', () => {
  it('should work', () => {
    return coffee.fork('/path/to/cli')
      // .debug()
      .waitForPrompt()
      .write('tz\n')
      .writeKey('DOWN', 'ENTER')
      .write('this is a desc\n')
      .expect('stdout', /{ name: 'tz', type: 'simple' }/)
      .expect('stdout', /{ description: 'this is a desc' }/)
      .expect('code', 0)
      .end();
  });
}):