Gruntfile.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.coverage = grunt.option('coverage');
  25. config.phjs = grunt.option('phjsToRelease');
  26. config.pkg.version = grunt.option('pkgVer') || config.pkg.version;
  27. console.log('Version', config.pkg.version);
  28. // load plugins
  29. require('load-grunt-tasks')(grunt);
  30. // load task definitions
  31. grunt.loadTasks('./scripts/grunt');
  32. // Utility function to load plugin settings into config
  33. function loadConfig(config,path) {
  34. require('glob').sync('*', {cwd: path}).forEach(function(option) {
  35. var key = option.replace(/\.js$/,'');
  36. // If key already exists, extend it. It is your responsibility to avoid naming collisions
  37. config[key] = config[key] || {};
  38. grunt.util._.extend(config[key], require(path + option)(config,grunt));
  39. });
  40. // technically not required
  41. return config;
  42. }
  43. // Merge that object with what with whatever we have here
  44. loadConfig(config,'./scripts/grunt/options/');
  45. // pass the config to grunt
  46. grunt.initConfig(config);
  47. };