composer
![Build Status](https://img.shields.io/travis/jonschlinkert/composer.svg)
API-first task runner with three methods: task, run and watch.
Install
Install with npm:
$ npm i composer --save
Usage
var Composer = require('composer');
API
Register a new task with it's options and dependencies. To return the task object of an already registered task, pass the name of the task without any additional parameters.
Params
name
{String}: Name of the task to registeroptions
{Object}: Options to set dependencies or control flow.options.deps
{Object}: array of dependenciesoptions.flow
{Object}: How this task will be executed with it's dependencies (series
, parallel
, settleSeries
, settleParallel
)deps
{String|Array|Function}: Additional dependencies for this task.fn
{Function}: Final function is the task to register.returns
{Object}: Return the instance for chaining
Example
app.task('site', ['styles'], function() {
return app.src('templates/pages/*.hbs')
.pipe(app.dest('_gh_pages'));
});
var task = app.task('site');
Build a task or array of tasks.
Params
tasks
{String|Array|Function}: List of tasks by name, function, or array of names/functions. (Defaults to [default]
).cb
{Function}: Callback function to be called when all tasks are finished building.
Example
app.build('default', function(err, results) {
if (err) return console.error(err);
console.log(results);
});
Compose task or list of tasks into a single function that runs the tasks in series.
Params
tasks
{String|Array|Function}: List of tasks by name, function, or array of names/functions.returns
{Function}: Composed function that may take a callback function.
Example
app.task('foo', function(done) {
console.log('this is foo');
done();
});
var fn = app.series('foo', function bar(done) {
console.log('this is bar');
done();
});
fn(function(err) {
if (err) return console.error(err);
console.log('done');
});
Compose task or list of tasks into a single function that runs the tasks in parallel.
Params
tasks
{String|Array|Function}: List of tasks by name, function, or array of names/functions.returns
{Function}: Composed function that may take a callback function.
Example
app.task('foo', function(done) {
setTimeout(function() {
console.log('this is foo');
done();
}, 500);
});
var fn = app.parallel('foo', function bar(done) {
console.log('this is bar');
done();
});
fn(function(err) {
if (err) return console.error(err);
console.log('done');
});
Watch a file, directory, or glob pattern for changes and build a task or list of tasks when changes are made. Watch is powered by chokidar so arguments can be anything supported by chokidar.watch.
Params
glob
{String|Array}: Filename, Directory name, or glob pattern to watchoptions
{Object}: Additional options to be passed to chokidartasks
{String|Array|Function}: Tasks that are passed to .build
when files in the glob are changed.returns
{Object}: Returns an instance of FSWatcher
from chokidar
Example
var watcher = app.watch('templates/pages/*.hbs', ['site']);
Events
composer is an event emitter that may emit the following events:
starting
This event is emitted when a build
is starting.
The event emits 2 arguments, the current instance of composer as the app
and an object containing the build runtime information.
app.on('starting', function(app, build) {});
build
exposes a .date
object that has a .start
property containing the start time as a Date
object.build
exposes a .hr
object that has a .start
property containing the start time as an hrtime
array.
finished
This event is emitted when a build
has finished.
The event emits 2 arguments, the current instance of composer as the app
and an object containing the build runtime information.
app.on('finished', function(app, build) {});
build
exposes a .date
object that has .start
and .end
properties containing start and end times of the build as Date
objects.build
exposes a .hr
object that has .start
, .end
, .duration
, and .diff
properties containing timing information calculated using process.hrtime
error
This event is emitted when an error occurrs during a build
.
The event emits 1 argument as an Error
object containing additional information about the build and the task running when the error occurred.
app.on('error', function(err) {});
Additional properties:
app
: current composer instance running the buildbuild
: current build runtime informationtask
: current task instance running when the error occurredrun
: current task runtime information
task:starting
This event is emitted when a task is starting.
The event emits 2 arguments, the current instance of the task object and an object containing the task runtime information.
app.on('task:starting', function(task, run) {});
The run
parameter exposes:
.date
{Object}: has a .start
property containing the start time as a Date
object..hr
{Object}: has a .start
property containing the start time as an hrtime
array.
task:finished
This event is emitted when a task has finished.
The event emits 2 arguments, the current instance of the task object and an object containing the task runtime information.
app.on('task:finished', function(task, run) {});
The run
parameter exposes:
.date
{Object}: has a .date
object that has .start
and .end
properties containing start and end times of the task as Date
objects.run
{Object}: has an .hr
object that has .start
, .end
, .duration
, and .diff
properties containing timing information calculated using process.hrtime
task:error
This event is emitted when an error occurrs while running a task.
The event emits 1 argument as an Error
object containing additional information about the task running when the error occurred.
app.on('task:error', function(err) {});
Additional properties
task
: current task instance running when the error occurredrun
: current task runtime information
Related projects
- assemble: Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… more | homepage
- generate: Fast, composable, highly extendable project generator with a user-friendly and expressive API. | homepage
- templates: System for creating and managing template collections, and rendering templates with any node.js template engine.… more | homepage
- update: Easily keep anything in your project up-to-date by installing the updaters you want to use… more | homepage
- verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2016 Jon Schlinkert
Released under the MIT license.
This file was generated by verb on January 27, 2016.