clac v0.1.3
CLaC - Command, Line and Conquer, a Node JS Server CLI command interface.
NOTE: until this hit's v1.0.0 consider this unstable. Things break, things may change, but it's being worked on.
Largely inspired by Laravel's artisan utility, this tool allows you to manage your running node service via a command line interface. Recache your routes, do some platform-specific maintenance or execute any code you want within a running noder instance.
Install
npm install --save clac
After that, you may want to get the executable out in your project root to be easier accessible. npm puts it into node_modules/.bin/conquer
but that's a hassle to type.
ln -s node_modules/.bin/conquer
from your project root puts a symbolic link there, making it as easy as ./conquer
or node conquer
if you prefer that.
Another option would be to set it as a script in your package.json; so
{
...
"scripts": {
...
"conquer": "conquer"
}
...
}
would allow you to run it like npm run conquer --
.
Configuration
Clac needs a conquer.json in your project root to work. A minimal configuration could look like this:
{
"mode": "socket",
"path": "./conquer.sock"
}
which tells clac to run in socket mode, with the socket lying in your project root.
mode
can be either socket
or network
, with socket being the default. However, named pipes for windows are on the to-do and until then you might need to run it via network connection under windows.
If mode
is socket
, you need to provide the additional path
option to specify a path where the unix socket should be created. If mode
is network
you also need to provide the port
option to specify the port to use.
Setup
The module exports 2 functions: register
and start
.
register
takes a name, additional arguments and the callback to execute.
var conquer = require('clac');
conquer.register('foo', [
{
name: '--bar',
options: {
help: 'foobarbaz'
}
}
], function (args, out, end) {
});
The first argument is the name of the command which you cann call it later with. The second argument is the arguments definition for the command. It takes an array of objects, each needing a name
and a options
field. Those will be passed to argparse's addArgument
function, so for documentation on that you best look there.
The third parameter is the function to execute when the command is called. It get's the args parameter, as parsed by argparse
, a function out
which you can use to print text back to your call (a simple console.log would make the server print stuff, which would be awkard if it's running behind systemd or something the like) and an end function you should call when you are finished. Calling end will terminate the connection to the client.
start
will make clac listen on the medium specified by the config. Takes no args.
conquer.start();