Abstraction bin tool.
$ npm i common-bin --save-dev
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.
This example will show you how to add a new TestCommand
and MyProgram
to create a new my-bin
tool.
- Full demo: my-bin
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'));
$ my-bin test
run mocha test at /foo/bar with []