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

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

    Keywords

    none

    Install

    npm i common-bin-plus

    DownloadsWeekly Downloads

    3

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    11.8 kB

    Total Files

    6

    Last publish

    Collaborators

    • hubcarl
    • mansonchor.zzw
    • eggjs-admin
    • fengmk2
    • atian25
    • dead_horse
    • popomore
    • wanghx
    • hyj1991
    • thonatos
    • killagu
    • coolme200
    • xadillax
    • ngot