Skip to content

Commit 3f843b8

Browse files
SyntaxRulesphated
authored andcommitted
Docs: Add gulp.registry API & examples
1 parent 2e4809b commit 3f843b8

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/API.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,59 @@ gulp.tree({ deep: true })
682682
*/
683683
```
684684

685+
### gulp.registry([registry])
686+
687+
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:
688+
689+
- [Sharing tasks](https://github.com/phated/undertaker#sharing-tasks)
690+
- [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.)
691+
- Handling other behavior that hooks into the registry lifecycle (see [gulp-hub](https://github.com/frankwallis/gulp-hub) for an example)
692+
693+
To build your own custom registry see the [undertaker documentation on custom registries](https://github.com/phated/undertaker#custom-registries).
694+
695+
#### registry
696+
697+
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.
698+
699+
#### Example
700+
701+
This example shows how to create and use a simple custom registry to add tasks.
702+
703+
```js
704+
//gulpfile.js
705+
var gulp = require('gulp');
706+
707+
var companyTasks = require('./myCompanyTasksRegistry.js');
708+
709+
gulp.registry(companyTasks);
710+
711+
gulp.task('one', gulp.parallel('someCompanyTask', function(done) {
712+
console.log('in task one');
713+
done();
714+
}));
715+
```
716+
717+
```js
718+
//myCompanyTasksRegistry.js
719+
var util = require('util');
720+
721+
var DefaultRegistry = require('undertaker-registry');
722+
723+
function MyCompanyTasksRegistry() {
724+
DefaultRegistry.call(this);
725+
726+
this.set('clean', function(done) {
727+
done();
728+
});
729+
this.set('someCompanyTask', function(done) {
730+
console.log('performing some company task.');
731+
done();
732+
});
733+
}
734+
util.inherits(MyCompanyTasksRegistry, DefaultRegistry);
735+
736+
module.exports = new MyCompanyTasksRegistry();
737+
```
685738

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

0 commit comments

Comments
 (0)