/common-bin

Abstraction bin tool

Primary LanguageJavaScriptMIT LicenseMIT

common-bin

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

Abstraction bin tool.


Install

$ npm i common-bin --save-dev

Build a bin tool for your team

You maybe need a custom xxx-bin to implement more custom features.

Now you can implement a Program sub class, and Command sub class to do that.

Example: Add test for unittest runner

This example will show you how to add a new TestCommand and MyProgram to create a new my-bin tool.

const Program = require('common-bin').Program;

class MyProgram extends Program {
  constructor() {
    super();
    this.version = require('../package.json').version;

    this.addCommand('test', path.join(__dirname, 'test_command.js'));
  }
}

module.exports = MyProgram;
const Command = require('egg-bin').Command;

class TestCommand extends Command {
  * run(cwd, args) {
    console.log('run mocha test at %s with %j', cwd, args);
  }

  help() {
    return 'unit test';
  }
}

module.exports = TestCommand;
#!/usr/bin/env node

'use strict';

const run = require('egg-bin').run;

run(require('../lib/my_program'));

Run result

$ my-bin test

run mocha test at /foo/bar with []

License

MIT