Gruntfile.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. module.exports = function (grunt) {
  2. 'use strict';
  3. grunt.initConfig({
  4. pkg: grunt.file.readJSON('package.json'),
  5. uglify: {
  6. target: {
  7. files: {
  8. 'build/js/bootstrap-datetimepicker.min.js': 'src/js/bootstrap-datetimepicker.js'
  9. }
  10. },
  11. options: {
  12. mangle: true,
  13. compress: {
  14. dead_code: false // jshint ignore:line
  15. },
  16. output: {
  17. ascii_only: true // jshint ignore:line
  18. },
  19. report: 'min',
  20. preserveComments: function(node, comment) {
  21. // preserve comments that start with a bang
  22. return /^!/.test( comment.value );
  23. }
  24. }
  25. },
  26. jshint: {
  27. all: [
  28. 'Gruntfile.js', 'src/js/*.js', 'test/*.js'
  29. ],
  30. options: {
  31. 'browser': true,
  32. 'node': true,
  33. 'jquery': true,
  34. 'boss': false,
  35. 'curly': true,
  36. 'debug': false,
  37. 'devel': false,
  38. 'eqeqeq': true,
  39. 'bitwise': true,
  40. 'eqnull': true,
  41. 'evil': false,
  42. 'forin': true,
  43. 'immed': false,
  44. 'laxbreak': false,
  45. 'newcap': true,
  46. 'noarg': true,
  47. 'noempty': false,
  48. 'nonew': false,
  49. 'onevar': true,
  50. 'plusplus': false,
  51. 'regexp': false,
  52. 'undef': true,
  53. 'sub': true,
  54. 'strict': true,
  55. 'unused': true,
  56. 'white': true,
  57. 'es3': true,
  58. 'camelcase': true,
  59. 'quotmark': 'single',
  60. 'globals': {
  61. 'define': false,
  62. 'moment': false,
  63. // Jasmine
  64. 'jasmine': false,
  65. 'describe': false,
  66. 'xdescribe': false,
  67. 'expect': false,
  68. 'it': false,
  69. 'xit': false,
  70. 'spyOn': false,
  71. 'beforeEach': false,
  72. 'afterEach': false
  73. }
  74. }
  75. },
  76. jscs: {
  77. all: [
  78. 'Gruntfile.js', 'src/js/*.js', 'test/*.js'
  79. ],
  80. options: {
  81. config: '.jscs.json'
  82. }
  83. },
  84. less: {
  85. production: {
  86. options: {
  87. cleancss: true,
  88. compress: true,
  89. paths: 'node_modules'
  90. },
  91. files: {
  92. 'build/css/bootstrap-datetimepicker.min.css': 'src/less/bootstrap-datetimepicker-build.less'
  93. }
  94. },
  95. development: {
  96. options: {
  97. paths: 'node_modules'
  98. },
  99. files: {
  100. 'build/css/bootstrap-datetimepicker.css': 'src/less/bootstrap-datetimepicker-build.less'
  101. }
  102. }
  103. },
  104. env: {
  105. paris: {
  106. TZ: 'Europe/Paris' // sets env for phantomJS https://github.com/ariya/phantomjs/issues/10379#issuecomment-36058589
  107. }
  108. },
  109. connect: {
  110. server: {
  111. options: {
  112. port: 8099
  113. }
  114. }
  115. },
  116. jasmine: {
  117. customTemplate: {
  118. src: 'src/js/*.js',
  119. options: {
  120. specs: 'test/*Spec.js',
  121. helpers: 'test/*Helper.js',
  122. host: 'http://127.0.0.1:8099',
  123. styles: [
  124. 'node_modules/bootstrap/dist/css/bootstrap.min.css',
  125. 'build/css/bootstrap-datetimepicker.min.css'
  126. ],
  127. vendor: [
  128. 'node_modules/jquery/dist/jquery.min.js',
  129. 'node_modules/moment/min/moment-with-locales.min.js',
  130. 'node_modules/moment-timezone/moment-timezone.js',
  131. 'node_modules/bootstrap/dist/js/bootstrap.min.js'
  132. ],
  133. display: 'none',
  134. summary: 'true'
  135. }
  136. }
  137. },
  138. nugetpack: {
  139. less: {
  140. src: 'src/nuget/Bootstrap.v3.Datetimepicker.nuspec',
  141. dest: 'build/nuget',
  142. options: {
  143. version: '<%= pkg.version %>'
  144. }
  145. },
  146. css: {
  147. src: 'src/nuget/Bootstrap.v3.Datetimepicker.CSS.nuspec',
  148. dest: 'build/nuget',
  149. options: {
  150. version: '<%= pkg.version %>'
  151. }
  152. }
  153. }
  154. });
  155. grunt.loadTasks('tasks');
  156. grunt.loadNpmTasks('grunt-env');
  157. grunt.loadNpmTasks('grunt-contrib-connect');
  158. grunt.loadNpmTasks('grunt-contrib-jasmine');
  159. grunt.loadNpmTasks('grunt-nuget');
  160. require('load-grunt-tasks')(grunt);
  161. grunt.registerTask('default', ['jshint', 'jscs', 'less', 'env:paris', 'connect', 'jasmine']);
  162. grunt.registerTask('build:travis', [
  163. // code style
  164. 'jshint',
  165. // build
  166. 'uglify', 'less',
  167. // tests
  168. 'env:paris', 'connect', 'jasmine'
  169. ]);
  170. // Task to be run when building
  171. grunt.registerTask('build', ['jshint', 'jscs', 'uglify', 'less']);
  172. grunt.registerTask('test', ['jshint', 'jscs', 'uglify', 'less', 'env:paris', 'connect', 'jasmine']);
  173. grunt.registerTask('docs', 'Generate docs', function () {
  174. grunt.util.spawn({
  175. cmd: 'mkdocs',
  176. args: ['build', '--clean']
  177. });
  178. });
  179. grunt.registerTask('release', function (version) {
  180. if (!version || version.split('.').length !== 3) {
  181. grunt.fail.fatal('malformed version. Use grunt release:1.2.3');
  182. }
  183. grunt.task.run([
  184. 'bump_version:' + version,
  185. 'build:travis',
  186. 'docs',
  187. 'nugetpack'
  188. ]);
  189. });
  190. };