-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d72b6b
commit 0cb58d8
Showing
1 changed file
with
48 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,53 @@ | ||
module.exports = function(grunt) { | ||
|
||
|
||
// Load the include-all library in order to require all of our grunt | ||
// configurations and task registrations dynamically. | ||
var includeAll; | ||
|
||
try { | ||
includeAll = require('include-all'); | ||
// Load the include-all library in order to require all of our grunt | ||
// configurations and task registrations dynamically. | ||
var includeAll; | ||
|
||
try { | ||
includeAll = require('include-all'); | ||
} | ||
catch (e0) { | ||
console.error('Could not find `include-all` module.'); | ||
console.error('Skipping grunt tasks...'); | ||
console.error('To fix this, please run:'); | ||
console.error('npm install include-all --save-dev'); | ||
console.error(); | ||
} | ||
|
||
/** | ||
* 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} relPath | ||
* @return {function} | ||
*/ | ||
function loadTasks(relPath) { | ||
return includeAll({ | ||
dirname: require('path').resolve(__dirname, relPath), | ||
filter: /(.+)\.js$/ | ||
}) || {}; | ||
} | ||
|
||
/** | ||
* Invokes the function from a Grunt configuration module with | ||
* a single argument - the `grunt` object. | ||
* @param {Object} tasks | ||
* @return {void} | ||
*/ | ||
function invokeConfigFn(tasks) { | ||
for (var taskName in tasks) { | ||
if (tasks.hasOwnProperty(taskName)) { | ||
tasks[taskName](grunt); | ||
} | ||
} | ||
catch (e0) { | ||
console.error('Could not find `include-all` module.'); | ||
console.error('Skipping grunt tasks...'); | ||
console.error('To fix this, please run:'); | ||
console.error('npm install include-all --save-dev'); | ||
console.error(); | ||
} | ||
|
||
/** | ||
* 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. | ||
*/ | ||
function loadTasks(relPath) { | ||
return includeAll({ | ||
dirname: require('path').resolve(__dirname, relPath), | ||
filter: /(.+)\.js$/ | ||
}) || {}; | ||
} | ||
|
||
/** | ||
* 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'), | ||
registerDefinitions = loadTasks('./tasks/register'); | ||
} | ||
|
||
// Run task functions to configure Grunt. | ||
invokeConfigFn(taskConfigurations); | ||
invokeConfigFn(registerDefinitions); | ||
// Load task functions | ||
var taskConfigurations = loadTasks('./tasks/config'); | ||
var registerDefinitions = loadTasks('./tasks/register'); | ||
|
||
// Run task functions to configure Grunt. | ||
invokeConfigFn(taskConfigurations); | ||
invokeConfigFn(registerDefinitions); | ||
}; |