Skip to content

Commit

Permalink
Docs: Add gulp.registry API & examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxRules authored and phated committed Dec 31, 2017
1 parent 2e4809b commit 3f843b8
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,59 @@ gulp.tree({ deep: true })
*/
```

### gulp.registry([registry])

Get or set the underlying task registry. Inherited from [undertaker]; see the undertaker documention on [registries](https://github.com/phated/undertaker#registryregistryinstance). Using this, you can change registries that enhance gulp in different ways. Utilizing a custom registry has at least three use cases:

- [Sharing tasks](https://github.com/phated/undertaker#sharing-tasks)
- [Sharing functionality](https://github.com/phated/undertaker#sharing-functionalities). (e.g. you could override the task prototype to add some additional logging, bind task metadata or include some config settings.)
- Handling other behavior that hooks into the registry lifecycle (see [gulp-hub](https://github.com/frankwallis/gulp-hub) for an example)

To build your own custom registry see the [undertaker documentation on custom registries](https://github.com/phated/undertaker#custom-registries).

#### registry

A registry instance or constructor. When passed in, the tasks from the current registry will be transferred to the new registry and then current registry will be replaced with the new registry.

#### Example

This example shows how to create and use a simple custom registry to add tasks.

```js
//gulpfile.js
var gulp = require('gulp');

var companyTasks = require('./myCompanyTasksRegistry.js');

gulp.registry(companyTasks);

gulp.task('one', gulp.parallel('someCompanyTask', function(done) {
console.log('in task one');
done();
}));
```

```js
//myCompanyTasksRegistry.js
var util = require('util');

var DefaultRegistry = require('undertaker-registry');

function MyCompanyTasksRegistry() {
DefaultRegistry.call(this);

this.set('clean', function(done) {
done();
});
this.set('someCompanyTask', function(done) {
console.log('performing some company task.');
done();
});
}
util.inherits(MyCompanyTasksRegistry, DefaultRegistry);

module.exports = new MyCompanyTasksRegistry();
```

[Function.name]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
[gaze]: https://github.com/shama/gaze
Expand Down

0 comments on commit 3f843b8

Please sign in to comment.