common-bin-plus
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

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();
  });
}):

/common-bin-plus/

    Package Sidebar

    Install

    npm i common-bin-plus

    Weekly Downloads

    11

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    12.1 kB

    Total Files

    6

    Last publish

    Collaborators

    • akitasummer
    • gxkl
    • gemwuu
    • eggjs-admin
    • fengmk2
    • atian25
    • dead_horse
    • wanghx
    • hyj1991
    • killagu
    • coolme200
    • mansonchor.zzw
    • hubcarl