|
| 1 | +<!-- front-matter |
| 2 | +id: api-registry |
| 3 | +title: registry() |
| 4 | +hide_title: true |
| 5 | +sidebar_label: registry() |
| 6 | +--> |
| 7 | + |
| 8 | +# `gulp.registry([registry])` |
| 9 | + |
| 10 | +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: |
| 11 | + |
| 12 | +- [Sharing tasks](https://github.com/phated/undertaker#sharing-tasks) |
| 13 | +- [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.) |
| 14 | +- Handling other behavior that hooks into the registry lifecycle (see [gulp-hub](https://github.com/frankwallis/gulp-hub) for an example) |
| 15 | + |
| 16 | +To build your own custom registry see the [undertaker documentation on custom registries](https://github.com/phated/undertaker#custom-registries). |
| 17 | + |
| 18 | +## registry |
| 19 | + |
| 20 | +A registry instance. 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. |
| 21 | + |
| 22 | +## Example |
| 23 | + |
| 24 | +This example shows how to create and use a simple custom registry to add tasks. |
| 25 | + |
| 26 | +```js |
| 27 | +//gulpfile.js |
| 28 | +var gulp = require('gulp'); |
| 29 | + |
| 30 | +var companyTasks = require('./myCompanyTasksRegistry.js'); |
| 31 | + |
| 32 | +gulp.registry(companyTasks); |
| 33 | + |
| 34 | +gulp.task('one', gulp.parallel('someCompanyTask', function(done) { |
| 35 | + console.log('in task one'); |
| 36 | + done(); |
| 37 | +})); |
| 38 | +``` |
| 39 | + |
| 40 | +```js |
| 41 | +//myCompanyTasksRegistry.js |
| 42 | +var util = require('util'); |
| 43 | + |
| 44 | +var DefaultRegistry = require('undertaker-registry'); |
| 45 | + |
| 46 | +function MyCompanyTasksRegistry() { |
| 47 | + DefaultRegistry.call(this); |
| 48 | +} |
| 49 | +util.inherits(MyCompanyTasksRegistry, DefaultRegistry); |
| 50 | + |
| 51 | +MyCompanyTasksRegistry.prototype.init = function(gulp) { |
| 52 | + gulp.task('clean', function(done) { |
| 53 | + done(); |
| 54 | + }); |
| 55 | + gulp.task('someCompanyTask', function(done) { |
| 56 | + console.log('performing some company task.'); |
| 57 | + done(); |
| 58 | + }); |
| 59 | +}; |
| 60 | + |
| 61 | +module.exports = new MyCompanyTasksRegistry(); |
| 62 | +``` |
| 63 | + |
| 64 | +[undertaker]: https://github.com/gulpjs/undertaker |
0 commit comments