-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (37 loc) · 1.23 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
/**
* A simple recursive task loader for grunt
* Author: dak0rn <dak0rn.github.io>
*/
var path = require('path');
// Global stuff
var nd = 'node_modules';
var td = 'tasks';
var up = '..';
// Exposing
module.exports = function(grunt) {
// Recursive loader
var _load = function(taskname, directory, depth) {
if( 0 > depth ) {
grunt.log.error('Task '+taskname+' not found in parent directories with depth '+depth);
return;
}
var taskDir = path.join(directory, nd, taskname);
var target = path.join(taskDir, td);
if( grunt.file.exists(target) ) {
grunt.loadTasks(target);
return;
}
_load(taskname, path.resolve(directory,up), depth-1);
};
// This function is exposed to grunt but only if it does not exist already
if( 'undefined' === typeof grunt.recursivelyLoadTasks )
grunt.recursivelyLoadTasks = function(task, directory, depth) {
if( 'undefined' === typeof task ) {
grunt.log.error('No task to load given');
return;
}
depth || (depth = 10);
directory || (directory = __dirname);
_load(task,directory,depth);
};
};