Gruntfile.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* jshint node:true */
  2. 'use strict';
  3. module.exports = function (grunt) {
  4. var config = {
  5. pkg: grunt.file.readJSON('package.json'),
  6. aws: grunt.file.readJSON('.aws-config.json'),
  7. srcDir: 'src',
  8. destDir: 'dist',
  9. tempDir: 'tmp',
  10. meta: {
  11. banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
  12. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  13. '<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +
  14. ' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  15. ' Licensed <%= pkg.license %> */\n\n'
  16. },
  17. clean: {
  18. on_start: ['<%= destDir %>', '<%= tempDir %>'],
  19. temp: ['<%= tempDir %>'],
  20. },
  21. copy: {
  22. everthing_left_in_src: {
  23. cwd: '<%= srcDir %>',
  24. expand: true,
  25. src: [
  26. '**/*.js',
  27. '**/*.json',
  28. 'font/**/*',
  29. 'img/**/*',
  30. 'panels/bettermap/leaflet/*.png'
  31. ],
  32. dest: '<%= tempDir %>'
  33. }
  34. },
  35. jshint: {
  36. // just lint the source dir
  37. source: {
  38. files: {
  39. src: ['Gruntfile.js', '<%= srcDir %>/app/**/*.js']
  40. }
  41. },
  42. options: {
  43. jshintrc: '.jshintrc'
  44. }
  45. },
  46. less: {
  47. dist:{
  48. options:{
  49. compress: true
  50. },
  51. expand: true,
  52. cwd:'<%= srcDir %>/vendor/bootstrap/less/',
  53. src: ['bootstrap.dark.less', 'bootstrap.light.less'],
  54. dest: '<%= tempDir %>/css/',
  55. },
  56. // Compile to src when not building
  57. src:{
  58. options: {
  59. paths: ["<%= srcDir %>/vendor/bootstrap/less"],
  60. yuicompress:true
  61. },
  62. files: {
  63. "<%= srcDir %>/css/bootstrap.dark.min.css": "<%= srcDir %>/vendor/bootstrap/less/bootstrap.dark.less",
  64. "<%= srcDir %>/css/bootstrap.light.min.css": "<%= srcDir %>/vendor/bootstrap/less/bootstrap.light.less"
  65. }
  66. }
  67. },
  68. cssmin: {
  69. dist: {
  70. expand: true,
  71. cwd: '<%= srcDir %>',
  72. src: [
  73. '**/*.css'
  74. ],
  75. dest: '<%= tempDir %>'
  76. }
  77. },
  78. htmlmin:{
  79. dist: {
  80. options:{
  81. removeComments: true,
  82. collapseWhitespace: true
  83. },
  84. expand: true,
  85. cwd: '<%= srcDir %>',
  86. src: [
  87. 'index.html',
  88. 'app/panels/**/*.html',
  89. 'app/partials/**/*.html'
  90. ],
  91. dest: '<%= tempDir %>'
  92. }
  93. },
  94. ngmin: {
  95. scripts: {
  96. expand:true,
  97. cwd:'<%= tempDir %>',
  98. src: [
  99. 'app/controllers/**/*.js',
  100. 'app/directives/**/*.js',
  101. 'app/services/**/*.js',
  102. 'app/filters/**/*.js',
  103. 'app/panels/**/*.js',
  104. 'app/app.js',
  105. 'vendor/angular/**/*.js',
  106. 'vendor/elasticjs/elastic-angular-client.js'
  107. ],
  108. dest: '<%= tempDir %>'
  109. }
  110. },
  111. requirejs: {
  112. compile_temp: {
  113. options: {
  114. appDir: '<%= tempDir %>',
  115. dir: '<%= destDir %>',
  116. mainConfigFile: '<%= tempDir %>/app/components/require.config.js',
  117. modules: [], // populated below
  118. optimize: 'none',
  119. optimizeCss: 'none',
  120. removeCombined: true,
  121. preserveLicenseComments: false,
  122. findNestedDependencies: true,
  123. normalizeDirDefines: "none",
  124. inlineText: true,
  125. skipPragmas: true,
  126. optimizeAllPluginResources: false,
  127. done: function (done, output) {
  128. var duplicates = require('rjs-build-analysis').duplicates(output);
  129. if (duplicates.length > 0) {
  130. grunt.log.subhead('Duplicates found in requirejs build:');
  131. grunt.log.warn(duplicates);
  132. done(new Error('r.js built duplicate modules, please check the excludes option.'));
  133. }
  134. done();
  135. }
  136. }
  137. }
  138. },
  139. uglify: {
  140. dest: {
  141. expand: true,
  142. src: ['**/*.js', '!config.js', '!app/dashboards/*.js'],
  143. dest: '<%= destDir %>',
  144. cwd: '<%= destDir %>',
  145. options: {
  146. quite: true,
  147. compress: true,
  148. preserveComments: false,
  149. banner: '<%= meta.banner %>'
  150. }
  151. }
  152. },
  153. 'git-describe': {
  154. me: {
  155. // Target-specific file lists and/or options go here.
  156. },
  157. },
  158. zip: {
  159. dist: {
  160. cwd: '<%= destDir %>',
  161. src: ['<%= destDir %>/**/*','LICENSE.md','README.md'],
  162. dest: '<%= tempDir %>/dist.zip'
  163. }
  164. },
  165. s3: {
  166. options: {
  167. key: '<%= aws.key %>',
  168. secret: '<%= aws.secret %>',
  169. bucket: 'download.elasticsearch.org',
  170. access: 'private'
  171. },
  172. dist: {
  173. upload: [
  174. {
  175. src: '<%= tempDir %>/dist.zip',
  176. dest: 'kibana/kibana/<%= pkg.name %>-latest.zip',
  177. }
  178. ]
  179. }
  180. }
  181. };
  182. var fs = require('fs');
  183. var requireModules = [
  184. {
  185. // main/common module
  186. name: 'app',
  187. include: [
  188. 'kbn',
  189. 'jquery',
  190. 'underscore',
  191. 'angular',
  192. 'bootstrap',
  193. 'modernizr',
  194. 'jquery',
  195. 'angular-sanitize',
  196. 'timepicker',
  197. 'datepicker',
  198. 'elasticjs',
  199. 'angular-strap',
  200. 'directives/all',
  201. 'filters/all',
  202. 'services/all',
  203. 'jquery.flot',
  204. 'jquery.flot.pie',
  205. 'text',
  206. 'settings'
  207. ]
  208. }
  209. ];
  210. // create a module for each directory in src/app/panels/
  211. fs.readdirSync(config.srcDir+'/app/panels').forEach(function (panelName) {
  212. requireModules.push({
  213. name: 'panels/'+panelName+'/module',
  214. exclude: ['app']
  215. });
  216. });
  217. // exclude the literal config definition from all modules
  218. requireModules.forEach(function (module) {
  219. module.excludeShallow = module.excludeShallow || [];
  220. module.excludeShallow.push('config');
  221. });
  222. config.requirejs.compile_temp.options.modules = requireModules;
  223. // load plugins
  224. grunt.loadNpmTasks('grunt-s3');
  225. grunt.loadNpmTasks('grunt-zip');
  226. grunt.loadNpmTasks('grunt-ngmin');
  227. grunt.loadNpmTasks('grunt-contrib-copy');
  228. grunt.loadNpmTasks('grunt-contrib-less');
  229. grunt.loadNpmTasks('grunt-git-describe');
  230. grunt.loadNpmTasks('grunt-contrib-clean');
  231. grunt.loadNpmTasks('grunt-contrib-jshint');
  232. grunt.loadNpmTasks('grunt-contrib-cssmin');
  233. grunt.loadNpmTasks('grunt-contrib-uglify');
  234. grunt.loadNpmTasks('grunt-string-replace');
  235. grunt.loadNpmTasks('grunt-contrib-htmlmin');
  236. grunt.loadNpmTasks('grunt-contrib-requirejs');
  237. // Project configuration.
  238. grunt.initConfig(config);
  239. // Default task.
  240. grunt.registerTask('default', ['jshint:source','less:src']);
  241. grunt.registerTask('build', [
  242. 'jshint:source',
  243. 'clean:on_start',
  244. 'htmlmin',
  245. 'less:dist',
  246. 'cssmin',
  247. 'copy:everthing_left_in_src',
  248. 'ngmin',
  249. 'requirejs:compile_temp',
  250. 'clean:temp',
  251. 'write_revision_to_dest', // runs git-describe and replace:config
  252. 'uglify:dest'
  253. ]);
  254. grunt.registerTask('distribute', [
  255. 'build',
  256. 'zip:dist',
  257. 's3:dist',
  258. 'clean:temp'
  259. ]);
  260. grunt.registerTask('write_revision_to_dest', function() {
  261. grunt.event.once('git-describe', function (desc) {
  262. grunt.config('string-replace.config', {
  263. src: '<%= destDir %>/app/components/require.config.js',
  264. dest: '<%= destDir %>/app/components/require.config.js',
  265. options: {
  266. replacements: [
  267. {
  268. pattern: /(?:^|\/\/)(.*)@REV@/,
  269. replacement: '$1'+desc.object
  270. }
  271. ]
  272. }
  273. });
  274. grunt.task.run('string-replace:config');
  275. });
  276. grunt.task.run('git-describe');
  277. });
  278. };