-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulp-submodule.js
41 lines (33 loc) · 1.42 KB
/
gulp-submodule.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
//A makeshift module to setup mock submodules with gulp tasks that can depend on
//each other. Gulp tasks can't really pass data between them without sharing a global
//variable so the tasks are saved as functions that are simply re-executed.
function gulpExecutor(subTaskResolver, require, func) {
return function() {
var requires = require.map(subTaskResolver);
return func.apply({}, requires);
}
}
module.exports = function (gulp) {
const subTasks = {};
function resolveSubtaskRequire(name) {
return subTasks[name];
}
return function(submoduleLoader) {
const module = submoduleLoader(gulp);
const name = module.name;
const tasks = module.tasks;
for (var taskName in tasks) {
if (tasks.hasOwnProperty(taskName)) {
var fullyQualifiedTaskName = name + ":" + taskName;
var taskData = tasks[taskName];
subTasks[fullyQualifiedTaskName] = taskData.func;
var dependencies = !taskData.dependencies ? [] : taskData.dependencies.map(function(dependency) {
if (dependency.indexOf(':') < 0) return name + ":" + dependency;
return dependency;
});
gulp.task(fullyQualifiedTaskName, dependencies,
gulpExecutor(resolveSubtaskRequire, taskData.require || [], taskData.func));
}
}
};
};