cjs-runner
v1.5.1
Published
Simple task runner.
Downloads
1,693
Maintainers
Readme
Task runner
Set of methods to synchronize asynchronous operations.
Installation
npm install cjs-runner
Usage
Add to the scope:
var Runner = require('cjs-runner'),
runner = new Runner();
Create a simple sync task:
runner.task('lint', function () {
// some actions
});
Create a simple async task:
runner.task('build', function ( done ) {
someAsyncCall(function () {
// handle call result
done();
});
});
Create a task with serial subtasks:
runner.task('serve', runner.serial('lint', 'build'));
Create a task with parallel subtasks:
runner.task('build', runner.parallel('jade:build', 'sass:build'));
It's possible to use either anonymous or named functions as well:
runner.task('build', runner.parallel('jade:build', 'sass:build', function lessBuild ( done ) {
// function name "lessBuild" is used as task name
// otherwise <noname> is printed
done();
}));
Batch tasks creation:
Object.assign(runner.tasks,
{
taskName1: taskFunction1,
taskName2: taskFunction2
},
{
taskName3: taskFunction3,
taskName4: taskFunction4
}
);
Execute a task by name:
runner.run('lint');
Execute a task and handle the result:
runner.run('lint', function ( error ) {
if ( error ) {
console.log('the task has failed!');
}
});
Execute a task as a named or anonymous function:
runner.run(function ( done ) {
done();
});
Execute task series:
runner.run(runner.parallel('lint', 'build'));
Execute task chain:
// no result check
runner.start();
// hook on task completion
runner.start(function () {
console.log('finished');
});
// hook on task completion
runner.start(function ( error ) {
if ( error ) {
console.log('failed!');
}
});
Hook on task start/stop events:
runner.addListener('start', function ( event ) {
// {id: 'lint'}
console.log(event);
});
runner.addListener('finish', function ( event ) {
// {id: 'lint', time: 1}
console.log(event);
});
Contribution
If you have any problems or suggestions please open an issue according to the contribution rules.
License
cjs-runner
is released under the MIT License.