Gruntfile.js 1.6 KB

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