1
- undertaker
2
- ==========
1
+ <p align =" center " >
2
+ <a href =" http://gulpjs.com " >
3
+ <img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
4
+ </a >
5
+ </p >
3
6
4
- [ ![ Build Status] ( https://travis-ci.org/gulpjs/undertaker.svg?branch=master )] ( https://travis-ci.org/gulpjs/undertaker )
7
+ # undertaker
8
+
9
+ [ ![ NPM version] [ npm-image ]] [ npm-url ] [ ![ Downloads] [ downloads-image ]] [ npm-url ] [ ![ Build Status] [ travis-image ]] [ travis-url ] [ ![ AppVeyor Build Status] [ appveyor-image ]] [ appveyor-url ] [ ![ Coveralls Status] [ coveralls-image ]] [ coveralls-url ] [ ![ Gitter chat] [ gitter-image ]] [ gitter-url ]
5
10
6
11
Task registry that allows composition through ` series ` /` parallel ` methods.
7
12
@@ -40,20 +45,19 @@ taker.task('all', taker.parallel('combined', 'task3'));
40
45
## API
41
46
42
47
__ Task functions can be completed in any of the ways supported by
43
- [ ` async-done ` ] ( https://github.com/phated/ async-done#completion-and-error- resolution) __
48
+ [ ` async-done ` ] [ async-resolution ] __
44
49
45
- ### ` new Undertaker([RegistryConstructor ]) `
50
+ ### ` new Undertaker([registryInstance ]) `
46
51
47
52
The constructor is used to create a new instance of ` Undertaker ` . Each instance of
48
53
` Undertaker ` gets its own instance of a registry. By default, the registry is an
49
- instance of [ ` undertaker-registry ` ] ( https://github.com/gulpjs/ undertaker-registry)
50
- but it can be any other registry that follows the [ Custom Registries API] ( # custom-registries) .
54
+ instance of [ ` undertaker-registry ` ] [ undertaker-registry ]
55
+ but it can be an instance of any other registry that follows the [ Custom Registries API] [ custom-registries ] .
51
56
52
- To use a custom registry, pass the custom registry's constructor function when
53
- instantiating a new ` Undertaker ` instance. This will use the custom constructor
54
- to create the registry for this instance.
57
+ To use a custom registry, pass a custom registry instance (` new CustomRegistry([options]) ` ) when
58
+ instantiating a new ` Undertaker ` instance. This will use the custom registry instance for that ` Undertaker ` instance.
55
59
56
- ### ` task([taskName,] fn) ` => [ Function ]
60
+ ### ` task([taskName,] fn) `
57
61
58
62
Both a ` getter ` and ` setter ` for tasks.
59
63
@@ -65,16 +69,13 @@ If a function (`fn`) and optionally a string (`taskName`) is given, it behaves a
65
69
a ` setter ` and will register the task by the ` taskName ` . If ` taskName ` is not
66
70
specified, the ` name ` or ` displayName ` property of the function is used as the ` taskName ` .
67
71
68
- __ Note: If you attempt to register the same function with different names, it will
69
- only be registered by the last name attempted.__
70
-
71
72
Will throw if:
72
73
73
- * ` taskName ` is missing or not a string when behaving as a ` getter ` or
74
- is missing and function is anonymous when behaving as a ` setter ` .
75
- * ` fn ` is missing or not a function when behaving as a ` setter ` .
74
+ * As a ` getter ` : ` taskName ` is missing or not a string.
75
+ * As a ` setter ` : ` taskName ` is missing and ` fn ` is anonymous .
76
+ * As a ` setter ` : ` fn ` is missing or not a function.
76
77
77
- ### ` series(taskName || fn...) ` => Function
78
+ ### ` series(taskName || fn...) `
78
79
79
80
Takes a variable amount of strings (` taskName ` ) and/or functions (` fn ` ) and
80
81
returns a function of the composed tasks or functions. Any ` taskNames ` are
@@ -84,7 +85,7 @@ When the returned function is executed, the tasks or functions will be executed
84
85
in series, each waiting for the prior to finish. If an error occurs, execution
85
86
will stop.
86
87
87
- ### ` parallel(taskName || fn...) ` => Function
88
+ ### ` parallel(taskName || fn...) `
88
89
89
90
Takes a variable amount of strings (` taskName ` ) and/or functions (` fn ` ) and
90
91
returns a function of the composed tasks or functions. Any ` taskNames ` are
@@ -102,21 +103,26 @@ the tasks from the current registry will be transferred to it and the current re
102
103
will be replaced with the new registry.
103
104
104
105
The ability to assign new registries will allow you to pre-define/share tasks or add
105
- custom functionality to your registries. See [ Custom Registries] ( # custom-registries)
106
+ custom functionality to your registries. See [ Custom Registries] [ custom-registries ]
106
107
for more information.
107
108
108
- ### ` tree([options]) ` => Object
109
+ ### ` tree([options]) `
109
110
110
- Optionally takes an object (` options ` ) and returns an object representing the
111
- tree of registered tasks. The object returned is [ ` archy ` ] ( https://www.npmjs.org/package/archy )
112
- compatible when assigned to the ` nodes ` key. Also, each node has a ` type `
113
- property that can be used to determine if the node is a ` task ` or ` function ` .
111
+ Optionally takes an ` options ` object and returns an object representing the
112
+ tree of registered tasks. The object returned is [ ` archy ` ] [ archy ]
113
+ compatible. Also, each node has a ` type ` property that can be used to determine if the node is a ` task ` or ` function ` .
114
114
115
115
#### ` options `
116
116
117
- * ` deep ` - if the whole tree should be returned (Default: ` false ` )
117
+ ##### ` options.deep `
118
+
119
+ Whether or not the whole tree should be returned.
118
120
119
- ### ` lastRun(task, [timeResolution]) ` => [ Timestamp]
121
+ Type: ` Boolean `
122
+
123
+ Default: ` false `
124
+
125
+ ### ` lastRun(task, [timeResolution]) `
120
126
121
127
Takes a string or function (` task ` ) and returns a timestamp of the last time the task
122
128
was run successfully. The time will be the time the task started.
@@ -127,20 +133,16 @@ If a task errors, the result of `lastRun` will be undefined because the task
127
133
should probably be re-run from scratch to get into a good state again.
128
134
129
135
The timestamp is always given in millisecond but the time resolution can be
130
- reduced ( rounded down) . The use case is to be able to compare a build time
136
+ rounded using the ` timeResolution ` parameter . The use case is to be able to compare a build time
131
137
to a file time attribute. On node v0.10 or with file system like HFS or FAT,
132
138
` fs.stat ` time attributes like ` mtime ` precision is one second.
133
139
134
140
Assuming ` undertakerInst.lastRun('someTask') ` returns ` 1426000001111 ` ,
135
141
` undertakerInst.lastRun('someTask', 1000) ` returns ` 1426000001000 ` .
136
142
137
- The default time resolution is ` 1000 ` on node v0.10, ` 0 ` on node 0.11+ and iojs.
143
+ The default time resolution is ` 1000 ` on node v0.10, ` 0 ` on node 0.11+ but
138
144
it can be overwritten using ` UNDERTAKER_TIME_RESOLUTION ` environment variable.
139
145
140
- __ Note: if you use a custom registry that modifies the function (such as ` .bind ` ),
141
- you will need to use the string for ` task ` instead of a function because we have no
142
- way of looking up the function that was altered.__
143
-
144
146
## Custom Registries
145
147
146
148
Custom registries are constructor functions allowing you to pre-define/share tasks
@@ -157,10 +159,9 @@ A registry's prototype should define:
157
159
You should not call these functions yourself; leave that to Undertaker, so it can
158
160
keep its metadata consistent.
159
161
160
- The easiest way to create a custom registry is to inherit from
161
- [ undertaker-registry] ( https://www.npmjs.com/package/undertaker-registry ) :
162
+ The easiest way to create a custom registry is to inherit from [ undertaker-registry] :
162
163
163
- ``` javascript
164
+ ``` js
164
165
var util = require (' util' );
165
166
166
167
var DefaultRegistry = require (' undertaker-registry' );
@@ -177,12 +178,12 @@ module.exports = MyRegistry;
177
178
### Sharing tasks
178
179
179
180
To share common tasks with all your projects, you can expose an ` init ` method on the registry
180
- prototype and it will receive the Undertaker instance as the only argument. You can then use
181
+ prototype and it will receive the ` Undertaker ` instance as the only argument. You can then use
181
182
` undertaker.task(name, fn) ` to register pre-defined tasks.
182
183
183
184
For example you might want to share a ` clean ` task:
184
185
185
- ``` javascript
186
+ ``` js
186
187
var fs = require (' fs' );
187
188
var util = require (' util' );
188
189
@@ -216,7 +217,7 @@ module.exports = CommonRegistry;
216
217
```
217
218
218
219
Then to use it in a project:
219
- ``` javascript
220
+ ``` js
220
221
var Undertaker = require (' undertaker' );
221
222
var CommonRegistry = require (' myorg-common-tasks' );
222
223
@@ -236,7 +237,7 @@ For example if you wanted all tasks to share some data, you can use a custom re
236
237
to bind them to that data. Be sure to return the altered task, as per the description
237
238
of registry methods above:
238
239
239
- ``` javascript
240
+ ``` js
240
241
var util = require (' util' );
241
242
242
243
var Undertaker = require (' undertaker' );
@@ -281,14 +282,42 @@ taker.task('default', taker.series('clean', 'build', 'serve', function(cb) {
281
282
282
283
### In the wild
283
284
284
- * [ undertaker-registry] ( https://github.com/gulpjs/undertaker-registry ) - Custom registries probably want to inherit from this.
285
- * [ undertaker-forward-reference] ( https://github.com/gulpjs/undertaker-forward-reference ) - Custom registry supporting forward referenced tasks (similar to gulp 3.x).
286
- * [ undertaker-task-metadata] ( https://github.com/gulpjs/undertaker-task-metadata ) - Proof-of-concept custom registry that attaches metadata to each task.
287
- * [ undertaker-common-tasks] ( https://github.com/gulpjs/undertaker-common-tasks ) - Proof-of-concept custom registry that pre-defines some tasks.
288
- * [ alchemist-gulp] ( https://github.com/webdesserts/alchemist-gulp ) - A default set of tasks for building alchemist plugins.
289
- * [ gulp-hub] ( https://github.com/frankwallis/gulp-hub/tree/registry-init ) - Custom registry to run tasks in multiple gulpfiles. (In a branch as of this writing)
290
- * [ gulp-pipeline] ( https://github.com/alienfast/gulp-pipeline ) - [ RailsRegistry] ( https://github.com/alienfast/gulp-pipeline/blob/master/src/ registry/railsRegistry.js ) is an ES2015 class that provides a gulp pipeline replacement for rails applications
285
+ * [ undertaker-registry] - Custom registries probably want to inherit from this.
286
+ * [ undertaker-forward-reference] - Custom registry supporting forward referenced tasks (similar to gulp 3.x).
287
+ * [ undertaker-task-metadata] - Proof-of-concept custom registry that attaches metadata to each task.
288
+ * [ undertaker-common-tasks] - Proof-of-concept custom registry that pre-defines some tasks.
289
+ * [ alchemist-gulp] - A default set of tasks for building alchemist plugins.
290
+ * [ gulp-hub] - Custom registry to run tasks in multiple gulpfiles. (In a branch as of this writing)
291
+ * [ gulp-pipeline] - [ RailsRegistry] [ rails- registry] is an ES2015 class that provides a gulp pipeline replacement for rails applications
291
292
292
293
## License
293
294
294
295
MIT
296
+
297
+ [ custom-registries ] : #custom-registries
298
+ [ async-resolution ] : https://github.com/phated/async-done#completion-and-error-resolution
299
+ [ archy ] : https://www.npmjs.org/package/archy
300
+ [ undertaker-registry ] : https://github.com/gulpjs/undertaker-registry
301
+ [ undertaker-forward-reference ] : https://github.com/gulpjs/undertaker-forward-reference
302
+ [ undertaker-task-metadata ] : https://github.com/gulpjs/undertaker-task-metadata
303
+ [ undertaker-common-tasks ] : https://github.com/gulpjs/undertaker-common-tasks
304
+ [ alchemist-gulp ] : https://github.com/webdesserts/alchemist-gulp
305
+ [ gulp-hub ] : https://github.com/frankwallis/gulp-hub/tree/registry-init
306
+ [ gulp-pipeline ] : https://github.com/alienfast/gulp-pipeline
307
+ [ rails-registry ] : https://github.com/alienfast/gulp-pipeline/blob/master/src/registry/railsRegistry.js
308
+
309
+ [ downloads-image ] : http://img.shields.io/npm/dm/undertaker.svg
310
+ [ npm-url ] : https://www.npmjs.com/package/undertaker
311
+ [ npm-image ] : http://img.shields.io/npm/v/undertaker.svg
312
+
313
+ [ travis-url ] : https://travis-ci.org/gulpjs/undertaker
314
+ [ travis-image ] : http://img.shields.io/travis/gulpjs/undertaker.svg?label=travis-ci
315
+
316
+ [ appveyor-url ] : https://ci.appveyor.com/project/gulpjs/undertaker
317
+ [ appveyor-image ] : https://img.shields.io/appveyor/ci/gulpjs/undertaker.svg?label=appveyor
318
+
319
+ [ coveralls-url ] : https://coveralls.io/r/gulpjs/undertaker
320
+ [ coveralls-image ] : http://img.shields.io/coveralls/gulpjs/undertaker/master.svg
321
+
322
+ [ gitter-url ] : https://gitter.im/gulpjs/gulp
323
+ [ gitter-image ] : https://badges.gitter.im/gulpjs/gulp.svg
0 commit comments