Gruntfile.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* jshint node:true */
  2. 'use strict';
  3. module.exports = function (grunt) {
  4. var config = {
  5. pkg: grunt.file.readJSON('package.json'),
  6. baseDir: '.',
  7. srcDir: 'src',
  8. destDir: 'dist',
  9. tempDir: 'tmp',
  10. docsDir: 'docs/'
  11. };
  12. config.mode = grunt.option('mode') || 'standalone';
  13. config.modeOptions = {
  14. requirejs: {
  15. paths: { config: '../config.sample' },
  16. excludeConfig: true,
  17. }
  18. };
  19. if (config.mode === 'backend') {
  20. config.modeOptions.requirejs.path = { config: 'components/config' };
  21. config.modeOptions.requirejs.excludeConfig = true;
  22. }
  23. // load plugins
  24. require('load-grunt-tasks')(grunt);
  25. // load task definitions
  26. grunt.loadTasks('tasks');
  27. // Utility function to load plugin settings into config
  28. function loadConfig(config,path) {
  29. require('glob').sync('*', {cwd: path}).forEach(function(option) {
  30. var key = option.replace(/\.js$/,'');
  31. // If key already exists, extend it. It is your responsibility to avoid naming collisions
  32. config[key] = config[key] || {};
  33. grunt.util._.extend(config[key], require(path + option)(config,grunt));
  34. });
  35. // technically not required
  36. return config;
  37. }
  38. // Merge that object with what with whatever we have here
  39. loadConfig(config,'./tasks/options/');
  40. // pass the config to grunt
  41. grunt.initConfig(config);
  42. };