|
| 1 | +/** |
| 2 | + * Gruntfile |
| 3 | + * |
| 4 | + * This Node script is executed when you run `grunt` or `sails lift`. |
| 5 | + * It's purpose is to load the Grunt tasks in your project's `tasks` |
| 6 | + * folder, and allow you to add and remove tasks as you see fit. |
| 7 | + * For more information on how this works, check out the `README.md` |
| 8 | + * file that was generated in your `tasks` folder. |
| 9 | + * |
| 10 | + * WARNING: |
| 11 | + * Unless you know what you're doing, you shouldn't change this file. |
| 12 | + * Check out the `tasks` directory instead. |
| 13 | + */ |
| 14 | + |
| 15 | +module.exports = function(grunt) { |
| 16 | + |
| 17 | + |
| 18 | + // Load the include-all library in order to require all of our grunt |
| 19 | + // configurations and task registrations dynamically. |
| 20 | + var includeAll; |
| 21 | + try { |
| 22 | + includeAll = require('include-all'); |
| 23 | + } catch (e0) { |
| 24 | + try { |
| 25 | + includeAll = require('sails/node_modules/include-all'); |
| 26 | + } |
| 27 | + catch(e1) { |
| 28 | + console.error('Could not find `include-all` module.'); |
| 29 | + console.error('Skipping grunt tasks...'); |
| 30 | + console.error('To fix this, please run:'); |
| 31 | + console.error('npm install include-all --save`'); |
| 32 | + console.error(); |
| 33 | + |
| 34 | + grunt.registerTask('default', []); |
| 35 | + return; |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + /** |
| 41 | + * Loads Grunt configuration modules from the specified |
| 42 | + * relative path. These modules should export a function |
| 43 | + * that, when run, should either load/configure or register |
| 44 | + * a Grunt task. |
| 45 | + */ |
| 46 | + function loadTasks(relPath) { |
| 47 | + return includeAll({ |
| 48 | + dirname: require('path').resolve(__dirname, relPath), |
| 49 | + filter: /(.+)\.js$/ |
| 50 | + }) || {}; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Invokes the function from a Grunt configuration module with |
| 55 | + * a single argument - the `grunt` object. |
| 56 | + */ |
| 57 | + function invokeConfigFn(tasks) { |
| 58 | + for (var taskName in tasks) { |
| 59 | + if (tasks.hasOwnProperty(taskName)) { |
| 60 | + tasks[taskName](grunt); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + // Load task functions |
| 69 | + var taskConfigurations = loadTasks('./tasks/config'), |
| 70 | + registerDefinitions = loadTasks('./tasks/register'); |
| 71 | + |
| 72 | + // (ensure that a default task exists) |
| 73 | + if (!registerDefinitions.default) { |
| 74 | + registerDefinitions.default = function (grunt) { grunt.registerTask('default', []); }; |
| 75 | + } |
| 76 | + |
| 77 | + // Run task functions to configure Grunt. |
| 78 | + invokeConfigFn(taskConfigurations); |
| 79 | + invokeConfigFn(registerDefinitions); |
| 80 | + |
| 81 | +}; |
0 commit comments