-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (49 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
var gulp = require('gulp');
var taskFactory = function(fn, metadata) {
var taskWrapper = function(done) {
var args = metadata.slice(0);
args.unshift(done);
return gulp.task(fn).apply(this, args);
}
taskWrapper.displayName = fn;
return taskWrapper;
}
var wrapTasks = function(tasksObj, metadata) {
for (var key in tasksObj) {
var el = tasksObj[key];
switch (typeof el) {
case "string":
tasksObj[key] = taskFactory(el, metadata)
break;
case "object":
tasksObj[key] = wrapTasks(el, metadata);
break;
}
}
return tasksObj;
}
var series = function() {
var params = Array.prototype.slice.call(arguments);
var metadata = params.shift();
params = wrapTasks(params, metadata);
return gulp.series.apply(this, params);
}
var parallel = function() {
var params = Array.prototype.slice.call(arguments);
var metadata = params.shift();
params = wrapTasks(params, metadata);
return gulp.parallel.apply(this, params);
}
/**
* Wraps all passed tasks in order to inject metadata in each task.
* Usage:
* gulpTaskMetadata.series(['my',metadata'], 'task1', task2', ['task3','task4']).
* gulpTaskMetadata.parallel(['my',metadata'], 'task1', task2', ['task3','task4']).
* The object ['my','metadata'] will now be injected in all the tasks provided to wrapSeries (in this case 'task1' until 'task4')
* The provided metadata will be injected after the default 'done' callback and can be used as follows: task1(done, metadata) { ... }
*/
module.exports = {
series: series,
parallel: parallel
};