Gruntfile.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*global module, require*/
  2. (function setUp(module, require) {
  3. 'use strict';
  4. var banner = ['/*!',
  5. ' * Angular Tooltips v<%= pkg.version %>',
  6. ' *',
  7. ' * Released under the MIT license',
  8. ' * www.opensource.org/licenses/MIT',
  9. ' *',
  10. ' * Brought to you by 720kb.net',
  11. ' *',
  12. ' * <%= grunt.template.today("yyyy-mm-dd") %>',
  13. ' */\n\n'].join('\n')
  14. , modRewrite = require('connect-modrewrite');
  15. module.exports = function doGrunt(grunt) {
  16. grunt.initConfig({
  17. 'pkg': grunt.file.readJSON('package.json'),
  18. 'confs': {
  19. 'dist': 'dist',
  20. 'config': 'config',
  21. 'css': 'src/css',
  22. 'js': 'src/js',
  23. 'serverPort': 8000
  24. },
  25. 'csslint': {
  26. 'options': {
  27. 'csslintrc': '<%= confs.config %>/csslintrc.json'
  28. },
  29. 'strict': {
  30. 'src': [
  31. '<%= confs.css %>/**/*.css'
  32. ]
  33. }
  34. },
  35. 'eslint': {
  36. 'options': {
  37. 'config': '<%= confs.config %>/eslint.json'
  38. },
  39. 'target': [
  40. 'Gruntfile.js',
  41. '<%= confs.js %>/**/*.js'
  42. ]
  43. },
  44. 'uglify': {
  45. 'options': {
  46. 'sourceMap': true,
  47. 'sourceMapName': '<%= confs.dist %>/angular-tooltips.sourcemap.map',
  48. 'preserveComments': false,
  49. 'report': 'gzip',
  50. 'banner': banner
  51. },
  52. 'minifyTarget': {
  53. 'files': {
  54. '<%= confs.dist %>/angular-tooltips.min.js': [
  55. '<%= confs.js %>/angular-tooltips.js'
  56. ]
  57. }
  58. }
  59. },
  60. 'cssmin': {
  61. 'options': {
  62. 'report': 'gzip',
  63. 'banner': banner
  64. },
  65. 'minifyTarget': {
  66. 'files': {
  67. '<%= confs.dist %>/angular-tooltips.min.css': [
  68. '<%= confs.css %>/angular-tooltips.css'
  69. ]
  70. }
  71. }
  72. },
  73. 'connect': {
  74. 'server': {
  75. 'options': {
  76. 'port': '<%= confs.serverPort %>',
  77. 'base': '.',
  78. 'keepalive': true,
  79. 'middleware': function manageMiddlewares(connect, options) {
  80. var middlewares = []
  81. , directory = options.directory || options.base[options.base.length - 1];
  82. // enable Angular's HTML5 mode
  83. middlewares.push(modRewrite(['!\\.html|\\.js|\\.svg|\\.css|\\.png|\\.gif$ /index.html [L]']));
  84. if (!Array.isArray(options.base)) {
  85. options.base = [options.base];
  86. }
  87. options.base.forEach(function forEachOption(base) {
  88. // Serve static files.
  89. middlewares.push(connect.static(base));
  90. });
  91. // Make directory browse-able.
  92. middlewares.push(connect.directory(directory));
  93. return middlewares;
  94. }
  95. }
  96. }
  97. },
  98. 'watch': {
  99. 'dev': {
  100. 'files': [
  101. 'Gruntfile.js',
  102. '<%= confs.css %>/**/*.css',
  103. '<%= confs.js %>/**/*.js'
  104. ],
  105. 'tasks': [
  106. 'csslint',
  107. 'eslint'
  108. ],
  109. 'options': {
  110. 'spawn': false
  111. }
  112. }
  113. },
  114. 'concurrent': {
  115. 'dev': {
  116. 'tasks': [
  117. 'connect:server',
  118. 'watch:dev'
  119. ],
  120. 'options': {
  121. 'limit': '<%= concurrent.dev.tasks.length %>',
  122. 'logConcurrentOutput': true
  123. }
  124. }
  125. }
  126. });
  127. grunt.loadNpmTasks('grunt-contrib-csslint');
  128. grunt.loadNpmTasks('grunt-eslint');
  129. grunt.loadNpmTasks('grunt-contrib-uglify');
  130. grunt.loadNpmTasks('grunt-contrib-cssmin');
  131. grunt.loadNpmTasks('grunt-concurrent');
  132. grunt.loadNpmTasks('grunt-contrib-connect');
  133. grunt.loadNpmTasks('grunt-contrib-watch');
  134. grunt.registerTask('default', [
  135. 'csslint',
  136. 'eslint',
  137. 'concurrent:dev'
  138. ]);
  139. grunt.registerTask('prod', [
  140. 'csslint',
  141. 'eslint',
  142. 'cssmin',
  143. 'uglify'
  144. ]);
  145. };
  146. }(module, require));