-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
92 lines (80 loc) · 2.2 KB
/
Gruntfile.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Gruntfile
*
* WARNING:
* Unless you know what you're doing, you shouldn't change this file.
* Check out the `tasks` directory instead.
*/
module.exports = function(grunt) {
'use strict';
// Auto load grunt tasks
require('jit-grunt')(grunt, {
lint: 'node_modules/eslint/bin/eslint.js'
});
/**
* Loads Grunt configuration modules from the specified
* relative path. These modules should export a function
* that, when run, should either load/configure or register
* a Grunt task.
*
* @param {String} dir Directory to load
*/
function loadTasks(dir) {
/**
* Resolve any relative paths
*
* @type {String}
*/
dir = require('path').resolve(dir);
/**
* Interal collection of modules loaded
*
* @type {Object}
*/
var modules = {};
/**
* Get a list of items in a directory. This is synchronous since we're
* only doing this once on application load
*
* @type {Array}
*/
var list = require('fs').readdirSync(dir);
/**
* Setup the Regex to filter out *.js files
*
* @type {RegExp}
*/
var jsFile = /.*\.js/;
// Cycle through each item in the directory
list.forEach(function(module) {
//Check to see if with have a match and if we split it apartment
module = module.match(jsFile);
if (module) {
// If we find a match try to load and save it. Otherwise log an error
try {
modules[module[0]] = require(dir + '/' + module[0]);
} catch (err) {
console.error('Unable to load ' + dir + '/' + module[0], err);
}
}
});
return modules;
}
/**
* Invokes the function from a Grunt configuration module with
* a single argument - the `grunt` object.
*/
function invokeConfigFn(tasks) {
for (var taskName in tasks) {
if (tasks.hasOwnProperty(taskName)) {
tasks[taskName](grunt);
}
}
}
// Load task functions
var taskConfigurations = loadTasks('./tasks/config');
var registerDefinitions = loadTasks('./tasks/register');
// Run task functions to configure Grunt.
invokeConfigFn(taskConfigurations);
invokeConfigFn(registerDefinitions);
};