Gruntfile.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. temp: ['<%= 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. 'app/panels/bettermap/leaflet/images/*'
  30. ],
  31. dest: '<%= tempDir %>'
  32. }
  33. },
  34. jshint: {
  35. // just lint the source dir
  36. source: {
  37. files: {
  38. src: ['Gruntfile.js', '<%= srcDir %>/app/**/*.js']
  39. }
  40. },
  41. options: {
  42. jshintrc: '.jshintrc'
  43. }
  44. },
  45. less: {
  46. dist:{
  47. options:{
  48. compress: true
  49. },
  50. expand: true,
  51. cwd:'<%= srcDir %>/vendor/bootstrap/less/',
  52. src: ['bootstrap.dark.less', 'bootstrap.light.less'],
  53. dest: '<%= tempDir %>/css/',
  54. },
  55. // Compile to src when not building
  56. src:{
  57. options: {
  58. paths: ["<%= srcDir %>/vendor/bootstrap/less"],
  59. yuicompress:true
  60. },
  61. files: {
  62. "<%= srcDir %>/css/bootstrap.dark.min.css": "<%= srcDir %>/vendor/bootstrap/less/bootstrap.dark.less",
  63. "<%= srcDir %>/css/bootstrap.light.min.css": "<%= srcDir %>/vendor/bootstrap/less/bootstrap.light.less"
  64. }
  65. }
  66. },
  67. cssmin: {
  68. dist: {
  69. expand: true,
  70. cwd: '<%= srcDir %>',
  71. src: [
  72. '**/*.css'
  73. ],
  74. dest: '<%= tempDir %>'
  75. }
  76. },
  77. htmlmin:{
  78. dist: {
  79. options:{
  80. removeComments: true,
  81. collapseWhitespace: true
  82. },
  83. expand: true,
  84. cwd: '<%= srcDir %>',
  85. src: [
  86. 'index.html',
  87. 'app/panels/**/*.html',
  88. 'app/partials/**/*.html'
  89. ],
  90. dest: '<%= tempDir %>'
  91. }
  92. },
  93. ngmin: {
  94. scripts: {
  95. expand:true,
  96. cwd:'<%= tempDir %>',
  97. src: [
  98. 'app/controllers/**/*.js',
  99. 'app/directives/**/*.js',
  100. 'app/services/**/*.js',
  101. 'app/filters/**/*.js',
  102. 'app/panels/**/*.js',
  103. 'app/app.js',
  104. 'vendor/angular/**/*.js',
  105. 'vendor/elasticjs/elastic-angular-client.js'
  106. ],
  107. dest: '<%= tempDir %>'
  108. }
  109. },
  110. requirejs: {
  111. compile_temp: {
  112. options: {
  113. appDir: '<%= tempDir %>',
  114. dir: '<%= destDir %>',
  115. mainConfigFile: '<%= tempDir %>/app/components/require.config.js',
  116. modules: [], // populated below
  117. optimize: 'none',
  118. optimizeCss: 'none',
  119. removeCombined: true,
  120. preserveLicenseComments: false,
  121. findNestedDependencies: true,
  122. normalizeDirDefines: "none",
  123. inlineText: true,
  124. skipPragmas: true,
  125. optimizeAllPluginResources: false,
  126. done: function (done, output) {
  127. var duplicates = require('rjs-build-analysis').duplicates(output);
  128. if (duplicates.length > 0) {
  129. grunt.log.subhead('Duplicates found in requirejs build:');
  130. grunt.log.warn(duplicates);
  131. done(new Error('r.js built duplicate modules, please check the excludes option.'));
  132. }
  133. done();
  134. }
  135. }
  136. }
  137. },
  138. uglify: {
  139. dest: {
  140. expand: true,
  141. src: ['**/*.js', '!config.js', '!app/dashboards/*.js'],
  142. dest: '<%= destDir %>',
  143. cwd: '<%= destDir %>',
  144. options: {
  145. quite: true,
  146. compress: true,
  147. preserveComments: false,
  148. banner: '<%= meta.banner %>'
  149. }
  150. }
  151. },
  152. 'git-describe': {
  153. me: {
  154. // Target-specific file lists and/or options go here.
  155. },
  156. },
  157. compress: {
  158. zip: {
  159. options: {
  160. archive: '<%= tempDir %>/<%= pkg.name %>-latest.zip'
  161. },
  162. files : [
  163. {
  164. expand: true,
  165. cwd: '<%= destDir %>',
  166. src: ['**/*'],
  167. dest: '<%= pkg.name %>-latest'
  168. },
  169. {
  170. expand: true,
  171. src: ['LICENSE.md','README.md'],
  172. dest: '<%= pkg.name %>-latest'
  173. }
  174. ]
  175. },
  176. tgz: {
  177. options: {
  178. archive: '<%= tempDir %>/<%= pkg.name %>-latest.tar.gz'
  179. },
  180. files : [
  181. {
  182. expand: true,
  183. cwd: '<%= destDir %>',
  184. src: ['**/*'],
  185. dest: '<%= pkg.name %>-latest'
  186. },
  187. {
  188. expand: true,
  189. src: ['LICENSE.md','README.md'],
  190. dest: '<%= pkg.name %>-latest'
  191. }
  192. ]
  193. }
  194. },
  195. s3: {
  196. dist: {
  197. bucket: 'download.elasticsearch.org',
  198. access: 'private',
  199. // debug: true, // uncommment to prevent actual upload
  200. upload: [
  201. {
  202. src: '<%= tempDir %>/<%= pkg.name %>-latest.zip',
  203. dest: 'kibana/kibana/<%= pkg.name %>-latest.zip',
  204. },
  205. {
  206. src: '<%= tempDir %>/<%= pkg.name %>-latest.tar.gz',
  207. dest: 'kibana/kibana/<%= pkg.name %>-latest.tar.gz',
  208. }
  209. ]
  210. }
  211. }
  212. };
  213. // setup the modules require will build
  214. var requireModules = config.requirejs.compile_temp.options.modules = [
  215. {
  216. // main/common module
  217. name: 'app',
  218. include: [
  219. 'css',
  220. 'kbn',
  221. 'text',
  222. 'jquery',
  223. 'angular',
  224. 'settings',
  225. 'bootstrap',
  226. 'modernizr',
  227. 'elasticjs',
  228. 'timepicker',
  229. 'datepicker',
  230. 'underscore',
  231. 'filters/all',
  232. 'jquery.flot',
  233. 'services/all',
  234. 'angular-strap',
  235. 'directives/all',
  236. 'jquery.flot.pie',
  237. 'angular-sanitize'
  238. ]
  239. }
  240. ];
  241. // create a module for each directory in src/app/panels/
  242. require('fs')
  243. .readdirSync(config.srcDir+'/app/panels')
  244. .forEach(function (panelName) {
  245. requireModules.push({
  246. name: 'panels/'+panelName+'/module',
  247. exclude: ['app']
  248. });
  249. });
  250. // exclude the literal config definition from all modules
  251. requireModules
  252. .forEach(function (module) {
  253. module.excludeShallow = module.excludeShallow || [];
  254. module.excludeShallow.push('config');
  255. });
  256. // Run jshint
  257. grunt.registerTask('default', ['jshint:source', 'less:src']);
  258. // Concat and Minify the src directory into dist
  259. grunt.registerTask('build', [
  260. 'jshint:source',
  261. 'clean:on_start',
  262. 'htmlmin',
  263. 'less:dist',
  264. 'cssmin',
  265. 'copy:everthing_left_in_src',
  266. 'ngmin',
  267. 'requirejs:compile_temp',
  268. 'clean:temp',
  269. 'build:write_revision',
  270. 'uglify:dest'
  271. ]);
  272. // run a string replacement on the require config, using the latest revision number as the cache buster
  273. grunt.registerTask('build:write_revision', function() {
  274. grunt.event.once('git-describe', function (desc) {
  275. grunt.config('string-replace.config', {
  276. src: '<%= destDir %>/app/components/require.config.js',
  277. dest: '<%= destDir %>/app/components/require.config.js',
  278. options: {
  279. replacements: [
  280. {
  281. pattern: /(?:^|\/\/)(.*)@REV@/,
  282. replacement: '$1'+desc.object
  283. }
  284. ]
  285. }
  286. });
  287. grunt.task.run('string-replace:config');
  288. });
  289. grunt.task.run('git-describe');
  290. });
  291. // build, then zip and upload to s3
  292. grunt.registerTask('distribute', [
  293. 'distribute:load_s3_config',
  294. 'build',
  295. 'compress:zip',
  296. 'compress:tgz',
  297. 's3:dist',
  298. 'clean:temp'
  299. ]);
  300. // collect the key and secret from the .aws-config.json file, finish configuring the s3 task
  301. grunt.registerTask('distribute:load_s3_config', function () {
  302. var config = grunt.file.readJSON('.aws-config.json');
  303. grunt.config('s3.options', {
  304. key: config.key,
  305. secret: config.secret
  306. });
  307. });
  308. // load plugins
  309. grunt.loadNpmTasks('grunt-s3');
  310. grunt.loadNpmTasks('grunt-ngmin');
  311. grunt.loadNpmTasks('grunt-contrib-copy');
  312. grunt.loadNpmTasks('grunt-contrib-less');
  313. grunt.loadNpmTasks('grunt-git-describe');
  314. grunt.loadNpmTasks('grunt-contrib-clean');
  315. grunt.loadNpmTasks('grunt-contrib-jshint');
  316. grunt.loadNpmTasks('grunt-contrib-cssmin');
  317. grunt.loadNpmTasks('grunt-contrib-uglify');
  318. grunt.loadNpmTasks('grunt-string-replace');
  319. grunt.loadNpmTasks('grunt-contrib-htmlmin');
  320. grunt.loadNpmTasks('grunt-contrib-requirejs');
  321. grunt.loadNpmTasks('grunt-contrib-compress');
  322. // pass the config to grunt
  323. grunt.initConfig(config);
  324. };