Gruntfile.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* jshint node:true */
  2. 'use strict';
  3. module.exports = function (grunt) {
  4. var config = {
  5. pkg: grunt.file.readJSON('package.json'),
  6. srcDir: 'src',
  7. destDir: 'dist',
  8. tempDir: 'tmp',
  9. meta: {
  10. banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
  11. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  12. '<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +
  13. ' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  14. ' Licensed <%= pkg.license %> */\n\n'
  15. },
  16. clean: {
  17. on_start: ['<%= destDir %>', '<%= tempDir %>'],
  18. after_require: ['<%= tempDir %>'],
  19. },
  20. copy: {
  21. everthing_left_in_src: {
  22. cwd: '<%= srcDir %>',
  23. expand: true,
  24. src: [
  25. '**/*.js',
  26. '**/*.json',
  27. 'font/**/*',
  28. 'img/**/*',
  29. 'panels/bettermap/leaflet/*.png'
  30. ],
  31. dest: '<%= tempDir %>'
  32. }//,
  33. // dist_to_temp: {
  34. // cwd: '<%= destDir %>',
  35. // expand: true,
  36. // src: '**/*',
  37. // dest: '<%= tempDir %>'
  38. // }
  39. },
  40. jshint: {
  41. // just lint the source dir
  42. source: {
  43. files: {
  44. src: ['Gruntfile.js', '<%= srcDir %>/app/**/*.js']
  45. }
  46. },
  47. options: {
  48. jshintrc: '.jshintrc'
  49. }
  50. },
  51. less: {
  52. dist:{
  53. options:{
  54. compress: true
  55. },
  56. expand: true,
  57. cwd:'<%= srcDir %>/vendor/bootstrap/less/',
  58. src: ['bootstrap.dark.less', 'bootstrap.light.less'],
  59. dest: '<%= tempDir %>/css/',
  60. }
  61. },
  62. cssmin: {
  63. dist: {
  64. expand: true,
  65. cwd: '<%= srcDir %>',
  66. src: [
  67. '**/*.css'
  68. ],
  69. dest: '<%= tempDir %>'
  70. }
  71. },
  72. htmlmin:{
  73. dist: {
  74. options:{
  75. removeComments: true,
  76. collapseWhitespace: true
  77. },
  78. expand: true,
  79. cwd: '<%= srcDir %>',
  80. src: [
  81. 'index.html',
  82. 'app/panels/**/*.html',
  83. 'app/partials/**/*.html'
  84. ],
  85. dest: '<%= tempDir %>'
  86. }
  87. },
  88. ngmin: {
  89. scripts: {
  90. expand:true,
  91. cwd:'<%= tempDir %>',
  92. src: [
  93. 'app/controllers/**/*.js',
  94. 'app/directives/**/*.js',
  95. 'app/services/**/*.js',
  96. 'app/filters/**/*.js',
  97. 'app/panels/**/*.js',
  98. 'app/app.js',
  99. 'vendor/angular/**/*.js',
  100. 'vendor/elasticjs/elastic-angular-client.js'
  101. ],
  102. dest: '<%= tempDir %>'
  103. }
  104. },
  105. requirejs: {
  106. compile_temp: {
  107. options: {
  108. appDir: '<%= tempDir %>',
  109. dir: '<%= destDir %>',
  110. modules: [], // populated below
  111. mainConfigFile: '<%= tempDir %>/app/components/require.config.js',
  112. keepBuildDir: true,
  113. optimize: 'uglify',
  114. optimizeCss: 'none',
  115. uglify: {
  116. max_line_length: 1000,
  117. // beautify: true, // uncomment for easier debugging
  118. indent_level: 2,
  119. },
  120. preserveLicenseComments: false,
  121. findNestedDependencies: true,
  122. normalizeDirDefines: "none",
  123. inlineText: true,
  124. skipPragmas: true,
  125. // stubModules: ["text"],
  126. optimizeAllPluginResources: false,
  127. removeCombined: true,
  128. fileExclusionRegExp: /^\./,
  129. logLevel: 0,
  130. skipSemiColonInsertion: true,
  131. done: function (done, output) {
  132. var duplicates = require('rjs-build-analysis').duplicates(output);
  133. if (duplicates.length > 0) {
  134. grunt.log.subhead('Duplicates found in requirejs build:');
  135. grunt.log.warn(duplicates);
  136. done(new Error('r.js built duplicate modules, please check the excludes option.'));
  137. }
  138. done();
  139. },
  140. config: {
  141. 'tmpl': {
  142. registerTemplate: function () {}
  143. }
  144. }
  145. }
  146. }
  147. }
  148. };
  149. var fs = require('fs');
  150. var requireModules = [
  151. {
  152. // main/common module
  153. name: 'app',
  154. include: [
  155. 'kbn',
  156. 'jquery',
  157. 'underscore',
  158. 'angular',
  159. 'bootstrap',
  160. 'modernizr',
  161. 'jquery',
  162. 'angular-sanitize',
  163. 'timepicker',
  164. 'datepicker',
  165. 'elasticjs',
  166. 'angular-strap',
  167. 'directives/all',
  168. 'filters/all',
  169. 'services/all',
  170. 'jquery.flot',
  171. 'jquery.flot.pie',
  172. 'text'
  173. ]
  174. }
  175. ];
  176. // create a module for each directory in src/app/panels/
  177. fs.readdirSync(config.srcDir+'/app/panels').forEach(function (panelName) {
  178. requireModules.push({
  179. name: 'panels/'+panelName+'/module',
  180. exclude: ['app']
  181. });
  182. });
  183. config.requirejs.compile_temp.options.modules = requireModules;
  184. // load plugins
  185. grunt.loadNpmTasks('grunt-ngmin');
  186. grunt.loadNpmTasks('grunt-contrib-copy');
  187. grunt.loadNpmTasks('grunt-contrib-less');
  188. grunt.loadNpmTasks('grunt-contrib-clean');
  189. grunt.loadNpmTasks('grunt-contrib-jshint');
  190. grunt.loadNpmTasks('grunt-contrib-cssmin');
  191. grunt.loadNpmTasks('grunt-contrib-uglify');
  192. grunt.loadNpmTasks('grunt-contrib-htmlmin');
  193. grunt.loadNpmTasks('grunt-contrib-requirejs');
  194. // Project configuration.
  195. grunt.initConfig(config);
  196. // Default task.
  197. grunt.registerTask('default', ['jshint:source','less']);
  198. grunt.registerTask('build', [
  199. 'jshint:source',
  200. 'clean:on_start',
  201. 'htmlmin',
  202. 'less',
  203. 'cssmin',
  204. 'copy:everthing_left_in_src',
  205. 'ngmin',
  206. 'requirejs:compile_temp',
  207. 'clean:after_require'
  208. ]);
  209. };