@@ -25,30 +25,30 @@ gulp.registry(registry);
25
25
26
26
### new UndertakerRegistry([ options] )
27
27
28
- Constructor for the default registry. Inherit from this constructor to build custom registries.
28
+ Constructor for the default registry. Inherit from this constructor to build custom registries.
29
29
30
30
### init(taker)
31
31
32
- No-op method that receives the undertaker instance. Useful to set pre-defined tasks using the
33
- ` undertaker.task(taskName, fn) ` method. Custom registries can override this method when inheriting
32
+ No-op method that receives the undertaker instance. Useful to set pre-defined tasks using the
33
+ ` undertaker.task(taskName, fn) ` method. Custom registries can override this method when inheriting
34
34
from this default registry.
35
35
36
36
### get(taskName) => Function
37
37
38
- Returns the task with that name or undefined if no task is registered with that name. Useful for custom
39
- task storage. Custom registries can override this method when inheriting from this default registry.
38
+ Returns the task with that name or undefined if no task is registered with that name. Useful for custom
39
+ task storage. Custom registries can override this method when inheriting from this default registry.
40
40
41
41
### set(taskName, fn) => [ Function]
42
42
43
- Adds a task to the registry. If ` set ` modifies a task, it should return the new task so Undertaker can
44
- properly maintain metadata for the task. Useful for adding custom behavior to every task as it is
45
- registered in the system. Custom registries can override this method when inheriting from this default
43
+ Adds a task to the registry. If ` set ` modifies a task, it should return the new task so Undertaker can
44
+ properly maintain metadata for the task. Useful for adding custom behavior to every task as it is
45
+ registered in the system. Custom registries can override this method when inheriting from this default
46
46
registry.
47
47
48
48
### tasks() => Object
49
49
50
- Returns an object listing all tasks in the registry. Necessary to override if the ` get ` method is overridden
51
- for custom task storage. Custom registries can override this when when inheriting from this default
50
+ Returns an object listing all tasks in the registry. Necessary to override if the ` get ` method is overridden
51
+ for custom task storage. Custom registries can override this when when inheriting from this default
52
52
registry.
53
53
54
54
## Custom Registries
@@ -60,7 +60,7 @@ A registry's prototype should define:
60
60
61
61
- ` init(taker) ` : receives the undertaker instance to set pre-defined tasks using the ` task(taskName, fn) ` method.
62
62
- ` get(taskName) ` : returns the task with that name
63
- or ` undefined ` if no task is registered with that name.
63
+ or ` undefined ` if no task is registered with that name.
64
64
- ` set(taskName, fn) ` : add task to the registry. If ` set ` modifies a task, it should return the new task.
65
65
- ` tasks() ` : returns an object listing all tasks in the registry.
66
66
@@ -75,7 +75,7 @@ var util = require('util');
75
75
76
76
var DefaultRegistry = require (' undertaker-registry' );
77
77
78
- function MyRegistry (){
78
+ function MyRegistry () {
79
79
DefaultRegistry .call (this );
80
80
}
81
81
@@ -99,7 +99,7 @@ var util = require('util');
99
99
var DefaultRegistry = require (' undertaker-registry' );
100
100
var del = require (' del' );
101
101
102
- function CommonRegistry (opts ){
102
+ function CommonRegistry (opts ) {
103
103
DefaultRegistry .call (this );
104
104
105
105
opts = opts || {};
@@ -109,40 +109,46 @@ function CommonRegistry(opts){
109
109
110
110
util .inherits (CommonRegistry, DefaultRegistry);
111
111
112
- CommonRegistry .prototype .init = function (takerInst ){
112
+ CommonRegistry .prototype .init = function (takerInst ) {
113
113
var buildDir = this .buildDir ;
114
114
var exists = fs .existsSync (buildDir);
115
115
116
- if (exists){
117
- throw new Error (' Cannot initialize common tasks. ' + buildDir + ' directory exists.' );
116
+ if (exists) {
117
+ throw new Error (
118
+ ' Cannot initialize common tasks. ' + buildDir + ' directory exists.'
119
+ );
118
120
}
119
121
120
- takerInst .task (' clean' , function () {
122
+ takerInst .task (' clean' , function () {
121
123
return del ([buildDir]);
122
124
});
123
- }
125
+ };
124
126
125
127
module .exports = CommonRegistry;
126
128
```
127
129
128
130
Then to use it in a project:
131
+
129
132
``` javascript
130
133
var Undertaker = require (' undertaker' );
131
134
var CommonRegistry = require (' myorg-common-tasks' );
132
135
133
136
var taker = new Undertaker (CommonRegistry ({ buildDir: ' /dist' }));
134
137
135
- taker .task (' build' , taker .series (' clean' , function build (cb ) {
136
- // do things
137
- cb ();
138
- }));
138
+ taker .task (
139
+ ' build' ,
140
+ taker .series (' clean' , function build (cb ) {
141
+ // do things
142
+ cb ();
143
+ })
144
+ );
139
145
```
140
146
141
147
### Sharing Functionalities
142
148
143
149
By controlling how tasks are added to the registry, you can decorate them.
144
150
145
- For example if you wanted all tasks to share some data, you can use a custom registry
151
+ For example if you wanted all tasks to share some data, you can use a custom registry
146
152
to bind them to that data. Be sure to return the altered task, as per the description
147
153
of registry methods above:
148
154
@@ -156,7 +162,7 @@ var DefaultRegistry = require('undertaker-registry');
156
162
var BuildRegistry = require (' ./build.js' );
157
163
var ServeRegistry = require (' ./serve.js' );
158
164
159
- function ConfigRegistry (config ){
165
+ function ConfigRegistry (config ) {
160
166
DefaultRegistry .call (this );
161
167
this .config = config;
162
168
}
@@ -165,7 +171,7 @@ util.inherits(ConfigRegistry, DefaultRegistry);
165
171
166
172
ConfigRegistry .prototype .set = function set (name , fn ) {
167
173
// The `DefaultRegistry` uses `this._tasks` for storage.
168
- var task = this ._tasks [name] = fn .bind (this .config );
174
+ var task = ( this ._tasks [name] = fn .bind (this .config ) );
169
175
return task;
170
176
};
171
177
@@ -176,24 +182,28 @@ taker.registry(new ServeRegistry());
176
182
177
183
// `taker.registry` will reset each task in the registry with
178
184
// `ConfigRegistry.prototype.set` which will bind them to the config object.
179
- taker .registry (new ConfigRegistry ({
180
- src: ' ./src' ,
181
- build: ' ./build' ,
182
- bindTo: ' 0.0.0.0:8888'
183
- }));
184
-
185
- taker .task (' default' , taker .series (' clean' , ' build' , ' serve' , function (cb ) {
186
- console .log (' Server bind to ' + this .bindTo );
187
- console .log (' Serving' + this .build );
188
- cb ();
189
- }));
185
+ taker .registry (
186
+ new ConfigRegistry ({
187
+ src: ' ./src' ,
188
+ build: ' ./build' ,
189
+ bindTo: ' 0.0.0.0:8888' ,
190
+ })
191
+ );
192
+
193
+ taker .task (
194
+ ' default' ,
195
+ taker .series (' clean' , ' build' , ' serve' , function (cb ) {
196
+ console .log (' Server bind to ' + this .bindTo );
197
+ console .log (' Serving' + this .build );
198
+ cb ();
199
+ })
200
+ );
190
201
```
191
202
192
203
## License
193
204
194
205
MIT
195
206
196
-
197
207
<!-- prettier-ignore-start -->
198
208
[ downloads-image ] : https://img.shields.io/npm/dm/undertaker-registry.svg?style=flat-square
199
209
[ npm-url ] : https://npmjs.org/package/undertaker-registry
0 commit comments