Gruntfile.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* jshint node:true */
  2. 'use strict';
  3. module.exports = function (grunt) {
  4. var os = require('os');
  5. var config = {
  6. pkg: grunt.file.readJSON('package.json'),
  7. baseDir: '.',
  8. srcDir: 'public',
  9. genDir: 'public_gen',
  10. destDir: 'dist',
  11. tempDir: 'tmp',
  12. platform: process.platform.replace('win32', 'windows'),
  13. };
  14. if (grunt.option('arch')) {
  15. config.arch = grunt.option('arch');
  16. } else {
  17. config.arch = os.arch();
  18. if (process.platform.match(/^win/)) {
  19. config.arch = process.env.hasOwnProperty('ProgramFiles(x86)') ? 'x64' : 'x86';
  20. }
  21. }
  22. config.phjs = grunt.option('phjsToRelease');
  23. config.pkg.version = grunt.option('pkgVer') || config.pkg.version;
  24. console.log('Version', config.pkg.version);
  25. // load plugins
  26. require('load-grunt-tasks')(grunt);
  27. // load task definitions
  28. grunt.loadTasks('tasks');
  29. // Utility function to load plugin settings into config
  30. function loadConfig(config,path) {
  31. require('glob').sync('*', {cwd: path}).forEach(function(option) {
  32. var key = option.replace(/\.js$/,'');
  33. // If key already exists, extend it. It is your responsibility to avoid naming collisions
  34. config[key] = config[key] || {};
  35. grunt.util._.extend(config[key], require(path + option)(config,grunt));
  36. });
  37. // technically not required
  38. return config;
  39. }
  40. // Merge that object with what with whatever we have here
  41. loadConfig(config,'./tasks/options/');
  42. // pass the config to grunt
  43. grunt.initConfig(config);
  44. };