Gruntfile.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. zipSuffix: '',
  15. requirejs: {
  16. paths: { config: '../config.sample' },
  17. excludeConfig: true,
  18. }
  19. };
  20. if (config.mode === 'backend') {
  21. grunt.log.writeln('Setting backend build mode');
  22. config.modeOptions.zipSuffix = '-backend';
  23. config.modeOptions.requirejs.path = { config: 'components/config' };
  24. config.modeOptions.requirejs.excludeConfig = true;
  25. }
  26. // load plugins
  27. require('load-grunt-tasks')(grunt);
  28. // load task definitions
  29. grunt.loadTasks('tasks');
  30. // Utility function to load plugin settings into config
  31. function loadConfig(config,path) {
  32. require('glob').sync('*', {cwd: path}).forEach(function(option) {
  33. var key = option.replace(/\.js$/,'');
  34. // If key already exists, extend it. It is your responsibility to avoid naming collisions
  35. config[key] = config[key] || {};
  36. grunt.util._.extend(config[key], require(path + option)(config,grunt));
  37. });
  38. // technically not required
  39. return config;
  40. }
  41. // Merge that object with what with whatever we have here
  42. loadConfig(config,'./tasks/options/');
  43. // pass the config to grunt
  44. grunt.initConfig(config);
  45. };