Gruntfile.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. module.exports = function(grunt) {
  15. // Load the include-all library in order to require all of our grunt
  16. // configurations and task registrations dynamically.
  17. var includeAll;
  18. try {
  19. includeAll = require('include-all');
  20. } catch (e0) {
  21. try {
  22. includeAll = require('sails/node_modules/include-all');
  23. }
  24. catch(e1) {
  25. console.error('Could not find `include-all` module.');
  26. console.error('Skipping grunt tasks...');
  27. console.error('To fix this, please run:');
  28. console.error('npm install include-all --save`');
  29. console.error();
  30. grunt.registerTask('default', []);
  31. return;
  32. }
  33. }
  34. /**
  35. * Loads Grunt configuration modules from the specified
  36. * relative path. These modules should export a function
  37. * that, when run, should either load/configure or register
  38. * a Grunt task.
  39. */
  40. function loadTasks(relPath) {
  41. return includeAll({
  42. dirname: require('path').resolve(__dirname, relPath),
  43. filter: /(.+)\.js$/
  44. }) || {};
  45. }
  46. /**
  47. * Invokes the function from a Grunt configuration module with
  48. * a single argument - the `grunt` object.
  49. */
  50. function invokeConfigFn(tasks) {
  51. for (var taskName in tasks) {
  52. if (tasks.hasOwnProperty(taskName)) {
  53. tasks[taskName](grunt);
  54. }
  55. }
  56. }
  57. // Load task functions
  58. var taskConfigurations = loadTasks('./tasks/config'),
  59. registerDefinitions = loadTasks('./tasks/register');
  60. // (ensure that a default task exists)
  61. if (!registerDefinitions.default) {
  62. registerDefinitions.default = function (grunt) { grunt.registerTask('default', []); };
  63. }
  64. // Run task functions to configure Grunt.
  65. invokeConfigFn(taskConfigurations);
  66. invokeConfigFn(registerDefinitions);
  67. };