A node script runner to allow easy management of large scripts
____ ___, __ _, ____, ____, ____, ___,(-(__`(-|_) (-| | (-| | (-| | (-|_, (-|_)____) _| \_, |__|_, _| |_, _| |_, _|__, _| \_,( ( ( ( ( (
Break down large scripts into manageable steps
First create some script steps in some folder
moduleexports = state options cb// TODO: setup environment;;
moduleexports = state options cb// TODO: start app servers;;
moduleexports = state options cb// TODO: do something;;
moduleexports = state options cb// TODO: kill servers;;
Then write the main script
var Runner = Runnerrunner = ;runner;
The sub-scripts (steps) are expected to provide a single export method with the following signatures (any of these is allowed):
state: is an object that is local to the runner object and it's passed to every step
options: is used to pass any parameter from the main script (see the startServers method above)
cb: is a callback method that must be called (potentially with an error). If called with an error all the steps following this one will be skipped and an error handler will be invoked if specified.
var Runner = Runnerrunner = ;
This method must be called first. It reads the scripts directory and creates methods on the runner based on the scripts found in the specified directory. Each file should be named with underscores and its corresponding method will be camel cased (e.g. do_stuff.js -> doStuff()).
where options is an object that can contain the following
dir: the scripts directory (this can be a string or an array)
onError: the name of the error handler that will be called in case of error
quiet: set to true to avoid printing the step name before each step executes
state: an object to set as the initial state
Will run the script. All methods will be run async and in the order called. On error (either unhandled or not) the specified error handler will be called, if any. This function can be passed a callback for further processing.
$ npm install srunner