Taskery
Taskery is a lightweight taskrunner, with a focus on code over
configuration.
Installation
npm install taskery --save
Usage
To start using taskery, either create a new instance or use the
default provided by the module:
var taskery = require('taskery');
var Taskery = require('taskery').Taskery;
var taskery = new Taskery();
Tasks
A task is defined by a name
, its dependencies
and a callback
.
taskery.task('test', ['build'], function() {
});
dependencies
must be an array or undefined
and callback
must
be a function
or undefined
, but at least one of them must be
specified.
The dependencies
array may contain task names or arrays of task
names. Each object in the array is ran sequentially, while the
arrays will themselves be ran in parallel. For example:
task('foo', () => setTimeout(() => console.log('Ran foo'), 500));
task('bar', () => console.log('Ran bar'));
task('foobar', [['foo', 'bar']])
task('foo-bar', ['foo', 'bar'])
If running 'foobar', the expected output is 'Ran bar', then 'Ran foo',
while running 'foo-bar', the expected output is 'Ran foo',
then 'Ran bar'.
If a task defines a callback that expects zero arguments, taskery
assumes that when it returns, the task is done. If, however,
asynchronous code is used inside a task, you can specify an argument
that will receive a callback function:
taskery.task('asynctask', (done) => {
someAsyncFunction(done);
})
A task may also return a Readable
stream. If it does, the task
is "done" when the stream emits the 'end'
or 'error'
events.
Middlewares
A middleware in taskery is an object with keys mapping to functions
that will run on demand. Currently, there are two middleware keys
available:
describe(name, description) => void
log(level, message) => void
The describe middleware is called whenever you call .describe()
on a task, and the log
middleware is called when taskery wants
to log something.
For instance, if you are using commander,
you can do this to expose your described tasks:
var commander = require('commander');
var tasks = [];
taskery.use({
describe: (name, description) => {
program
.command(name)
.description(description)
.action(() => {
tasks.push(name);
})
}
})
More examples can be seen in
tests/index.spec.js