UNPKG

5.55 kBMarkdownView Raw
1# composer [![NPM version](https://badge.fury.io/js/composer.svg)](http://badge.fury.io/js/composer) [![Build Status](https://travis-ci.org/jonschlinkert/composer.svg)](https://travis-ci.org/jonschlinkert/composer)
2
3> API-first task runner with three methods: task, run and watch.
4
5## Install
6
7Install with [npm](https://www.npmjs.com/)
8
9```sh
10$ npm i composer --save
11```
12
13## Usage
14
15```js
16var Composer = require('composer');
17```
18
19## API
20
21### [Composer](index.js#L23)
22
23Composer constructor. Create a new Composer
24
25**Example**
26
27```js
28var composer = new Composer();
29```
30
31### [.task](index.js#L58)
32
33Register a new task with it's options and dependencies.
34
35Options:
36
37* `deps`: array of dependencies
38* `flow`: How this task will be executed with it's dependencies (`series`, `parallel`, `settleSeries`, `settleParallel`)
39
40**Params**
41
42* `name` **{String}**: Name of the task to register
43* `options` **{Object}**: Options to set dependencies or control flow.
44* `deps` **{String|Array|Function}**: Additional dependencies for this task.
45* `fn` **{Function}**: Final function is the task to register.
46* `returns` **{Object}**: Return `this` for chaining
47
48**Example**
49
50```js
51composer.task('site', ['styles'], function () {
52 return app.src('templates/pages/*.hbs')
53 .pipe(app.dest('_gh_pages'));
54});
55```
56
57### [.build](index.js#L112)
58
59Build a task or list of tasks.
60
61**Params**
62
63* `tasks` **{String|Array|Function}**: List of tasks by name, function, or array of names/functions.
64* `cb` **{Function}**: Callback function to be called when all tasks are finished building.
65
66**Example**
67
68```js
69composer.build('default', function (err, results) {
70 if (err) return console.error(err);
71 console.log(results);
72});
73```
74
75### [.series](index.js#L150)
76
77Compose task or list of tasks into a single function that runs the tasks in series.
78
79**Params**
80
81* `tasks` **{String|Array|Function}**: List of tasks by name, function, or array of names/functions.
82* `returns` **{Function}**: Composed function that may take a callback function.
83
84**Example**
85
86```js
87composer.task('foo', function (done) {
88 console.log('this is foo');
89 done();
90});
91
92var fn = composer.series('foo', function bar(done) {
93 console.log('this is bar');
94 done();
95});
96
97fn(function (err) {
98 if (err) return console.error(err);
99 console.log('done');
100});
101//=> this is foo
102//=> this is bar
103//=> done
104```
105
106### [.parallel](index.js#L182)
107
108Compose task or list of tasks into a single function that runs the tasks in parallel.
109
110**Params**
111
112* `tasks` **{String|Array|Function}**: List of tasks by name, function, or array of names/functions.
113* `returns` **{Function}**: Composed function that may take a callback function.
114
115**Example**
116
117```js
118composer.task('foo', function (done) {
119 setTimeout(function () {
120 console.log('this is foo');
121 done();
122 }, 500);
123});
124
125var fn = composer.parallel('foo', function bar(done) {
126 console.log('this is bar');
127 done();
128});
129
130fn(function (err) {
131 if (err) return console.error(err);
132 console.log('done');
133});
134//=> this is bar
135//=> this is foo
136//=> done
137```
138
139### [.watch](index.js#L201)
140
141Watch 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](https://github.com/paulmillr/chokidar) so the glob pattern may be anything that [chokidar.watch](https://github.com/paulmillr/chokidar#api) accepts.
142
143**Params**
144
145* `glob` **{String|Array}**: Filename, Directory name, or glob pattern to watch
146* `options` **{Object}**: Additional options to be passed to [chokidar](https://github.com/paulmillr/chokidar)
147* `tasks` **{String|Array|Function}**: Tasks that are passed to `.build` when files in the glob are changed.
148* `returns` **{Object}**: Returns an instance of `FSWatcher` from [chokidar](https://github.com/paulmillr/chokidar)
149
150**Example**
151
152```js
153var watcher = composer.watch('templates/pages/*.hbs', ['site']);
154```
155
156## Related projects
157
158* [assemble](https://www.npmjs.com/package/assemble): Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… [more](https://www.npmjs.com/package/assemble) | [homepage](http://assemble.io)
159* [generate](https://www.npmjs.com/package/generate): Project generator, for node.js. | [homepage](https://github.com/generate/generate)
160* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine.… [more](https://www.npmjs.com/package/templates) | [homepage](https://github.com/jonschlinkert/templates)
161* [update](https://www.npmjs.com/package/update): Update the year in all files in a project using glob patterns. | [homepage](https://github.com/jonschlinkert/update)
162* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://www.npmjs.com/package/verb) | [homepage](https://github.com/verbose/verb)
163
164## Running tests
165
166Install dev dependencies:
167
168```sh
169$ npm i -d && npm test
170```
171
172## Contributing
173
174Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/composer/issues/new).
175
176## Author
177
178**Jon Schlinkert**
179
180+ [github/jonschlinkert](https://github.com/jonschlinkert)
181+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
182
183## License
184
185Copyright © 2015 Jon Schlinkert
186Released under the MIT license.
187
188***
189
190_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 16, 2015._
\No newline at end of file