Janus CLI
Janus CLI is a Toolbelt framework that provides a simple plugin system to allow you to build plugins for your build process.
It is important to note that Janus CLI is not in itself an executable but a tool to help you build your own. NPM have a great blog post that explains how to build an executable using NPM.
Existing plugins
- Task Runner Plugin
- As it sounds, the task runner will synchronously run tasks from a YAML file in the current repo. Useful for pre-release tasks.
- Release Plugin
- This plugin handles semantic versioning, auto changelings and github releases.
Usage
Writing your executable file
Our company Janus executable is open over at thebeansgroup/tbg-januscli and acts as a template for rolling out your own.
This example shows how you can use the above plugins using ES6
:
;;; janus;janus; janusstart;
or using common.js
modules:
var janus = default;var release = default;var tasks = default; janus;janus; janusstart;
Once you’ve built your executable — and assuming you have named it janus
— then you can run the tasks like any CLI.
$ my-repo> janus -h Usage: janus [options] [command] Commands: release [level_override] Create a release of current app tasks Run tasks in project Options: -h, —help output usage information -V, —version output the version number -v, —verbose Verbose mode for debugging
Writing plugins
A plugin is just an extension of the main plugin class. Within your plugin you need only do three things:
- Set CLI commands
- Set CLI options
- Add listeners and handlers for commands.
The following is a simple example of a plugin taken from the Janus Plugin Example repo.
; /** * Example plugin definition */ { superjanus; thisfoo = 'bar'; } /** * name() set plugin name * */ { return 'example'; } /** * Event handlers * */ { thisjanus thisjanus } /** * CLI options for plugin to * respond to. * */ { return 'example' // command line option name 'Run example command' // Command line description thisname // event name 'example2' // command line option name 'Run example 2 command' // command line description 'example2' // event name } /** * CLI options for plugin to * respond to. * * This is a decorator for https://github.com/tj/commander.js/#option-parsing * */ { return '-f, --foo <value>' // command line flags 'Set Foo' // command line description 'bar' // default value { // Callback (this differs to commander.js) thisfoo = value; } } /** * Example command * */ { thisjanus; thisjanus; } /** * Example 2 command * */ { thisjanus; thisjanus; } ;
This plugin can then be consumed by your toolbelt:
;; janus; janusstart;
Example output:
[master][~/src/janustest] ./bin/index.js -h Usage: index [options] [command] Commands: example Run example command example2 Run example 2 command Options: -h, --help output usage information -V, --version output the version number -v, --verbose Verbose mode for debugging -f, --foo <value> Set Foo [master][~/src/janustest] ./bin/index.js example✓ Success: Example: Example command startedℹ Info: Example: Foo = bar [master][~/src/janustest] ./bin/index.js example2✓ Success: Example: Example 2 command startedℹ Info: Example: Foo = bar [master][~/src/janustest] ./bin/index.js example2 --foo buzz✓ Success: Example: Example 2 command startedℹ Info: Example: Foo = buzz