Gruntfile.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. module.exports = function(grunt){
  2. 'use strict';
  3. // Force use of Unix newlines
  4. grunt.util.linefeed = '\n';
  5. // Project configuration.
  6. grunt.initConfig({
  7. //Metadata
  8. pkg: grunt.file.readJSON('package.json'),
  9. banner: [
  10. '/*!',
  11. ' * Datepicker for Bootstrap v<%= pkg.version %> (<%= pkg.homepage %>)',
  12. ' *',
  13. ' * Licensed under the Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0)',
  14. ' */'
  15. ].join('\n') + '\n',
  16. // Task configuration.
  17. clean: {
  18. dist: ['dist', '*-dist.zip']
  19. },
  20. jshint: {
  21. options: {
  22. jshintrc: 'js/.jshintrc'
  23. },
  24. main: {
  25. src: 'js/bootstrap-datepicker.js'
  26. },
  27. locales: {
  28. src: 'js/locales/*.js'
  29. },
  30. gruntfile: {
  31. options: {
  32. jshintrc: 'grunt/.jshintrc'
  33. },
  34. src: 'Gruntfile.js'
  35. }
  36. },
  37. jscs: {
  38. options: {
  39. config: 'js/.jscsrc'
  40. },
  41. main: {
  42. src: 'js/bootstrap-datepicker.js'
  43. },
  44. locales: {
  45. src: 'js/locales/*.js'
  46. },
  47. gruntfile: {
  48. src: 'Gruntfile.js'
  49. }
  50. },
  51. qunit: {
  52. main: 'tests/tests.html',
  53. timezone: 'tests/timezone.html',
  54. options: {
  55. console: false
  56. }
  57. },
  58. concat: {
  59. options: {
  60. stripBanners: true
  61. },
  62. main: {
  63. src: 'js/bootstrap-datepicker.js',
  64. dest: 'dist/js/<%= pkg.name %>.js'
  65. }
  66. },
  67. uglify: {
  68. options: {
  69. preserveComments: 'some'
  70. },
  71. main: {
  72. src: '<%= concat.main.dest %>',
  73. dest: 'dist/js/<%= pkg.name %>.min.js'
  74. },
  75. locales: {
  76. files: [{
  77. expand: true,
  78. cwd: 'js/locales/',
  79. src: '*.js',
  80. dest: 'dist/locales/',
  81. rename: function(dest, name){
  82. return dest + name.replace(/\.js$/, '.min.js');
  83. }
  84. }]
  85. }
  86. },
  87. less: {
  88. options: {
  89. sourceMap: true,
  90. outputSourceFiles: true
  91. },
  92. standalone_bs2: {
  93. options: {
  94. sourceMapURL: '<%= pkg.name %>.standalone.css.map'
  95. },
  96. src: 'build/build_standalone.less',
  97. dest: 'dist/css/<%= pkg.name %>.standalone.css'
  98. },
  99. standalone_bs3: {
  100. options: {
  101. sourceMapURL: '<%= pkg.name %>3.standalone.css.map'
  102. },
  103. src: 'build/build_standalone3.less',
  104. dest: 'dist/css/<%= pkg.name %>3.standalone.css'
  105. },
  106. main_bs2: {
  107. options: {
  108. sourceMapURL: '<%= pkg.name %>.css.map'
  109. },
  110. src: 'build/build.less',
  111. dest: 'dist/css/<%= pkg.name %>.css'
  112. },
  113. main_bs3: {
  114. options: {
  115. sourceMapURL: '<%= pkg.name %>3.css.map'
  116. },
  117. src: 'build/build3.less',
  118. dest: 'dist/css/<%= pkg.name %>3.css'
  119. }
  120. },
  121. usebanner: {
  122. options: {
  123. banner: '<%= banner %>'
  124. },
  125. css: 'dist/css/*.css',
  126. js: 'dist/js/**/*.js'
  127. },
  128. cssmin: {
  129. options: {
  130. compatibility: 'ie8',
  131. keepSpecialComments: '*',
  132. advanced: false
  133. },
  134. main: {
  135. files: {
  136. 'dist/css/<%= pkg.name %>.min.css': 'dist/css/<%= pkg.name %>.css',
  137. 'dist/css/<%= pkg.name %>3.min.css': 'dist/css/<%= pkg.name %>3.css'
  138. }
  139. },
  140. standalone: {
  141. files: {
  142. 'dist/css/<%= pkg.name %>.standalone.min.css': 'dist/css/<%= pkg.name %>.standalone.css',
  143. 'dist/css/<%= pkg.name %>3.standalone.min.css': 'dist/css/<%= pkg.name %>3.standalone.css'
  144. }
  145. }
  146. },
  147. csslint: {
  148. options: {
  149. csslintrc: 'less/.csslintrc'
  150. },
  151. dist: [
  152. 'dist/css/bootstrap-datepicker.css',
  153. 'dist/css/bootstrap-datepicker3.css',
  154. 'dist/css/bootstrap-datepicker.standalone.css',
  155. 'dist/css/bootstrap-datepicker3.standalone.css'
  156. ]
  157. },
  158. compress: {
  159. main: {
  160. options: {
  161. archive: '<%= pkg.name %>-<%= pkg.version %>-dist.zip',
  162. mode: 'zip',
  163. level: 9,
  164. pretty: true
  165. },
  166. files: [
  167. {
  168. expand: true,
  169. cwd: 'dist/',
  170. src: '**'
  171. }
  172. ]
  173. }
  174. },
  175. 'string-replace': {
  176. js: {
  177. files: [{
  178. src: 'js/bootstrap-datepicker.js',
  179. dest: 'js/bootstrap-datepicker.js'
  180. }],
  181. options: {
  182. replacements: [{
  183. pattern: /\$(\.fn\.datepicker\.version)\s=\s*("|\')[0-9\.a-z].*("|');/gi,
  184. replacement: "$.fn.datepicker.version = '" + grunt.option('newver') + "';"
  185. }]
  186. }
  187. },
  188. npm: {
  189. files: [{
  190. src: 'package.json',
  191. dest: 'package.json'
  192. }],
  193. options: {
  194. replacements: [{
  195. pattern: /\"version\":\s\"[0-9\.a-z].*",/gi,
  196. replacement: '"version": "' + grunt.option('newver') + '",'
  197. }]
  198. }
  199. }
  200. }
  201. });
  202. // These plugins provide necessary tasks.
  203. require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
  204. require('time-grunt')(grunt);
  205. // JS distribution task.
  206. grunt.registerTask('dist-js', ['concat', 'uglify:main', 'uglify:locales', 'usebanner:js']);
  207. // CSS distribution task.
  208. grunt.registerTask('less-compile', 'less');
  209. grunt.registerTask('dist-css', ['less-compile', 'cssmin:main', 'cssmin:standalone', 'usebanner:css']);
  210. // Full distribution task.
  211. grunt.registerTask('dist', ['clean:dist', 'dist-js', 'dist-css']);
  212. // Code check tasks.
  213. grunt.registerTask('lint-js', 'Lint all js files with jshint and jscs', ['jshint', 'jscs']);
  214. grunt.registerTask('lint-css', 'Lint all css files', ['dist-css', 'csslint:dist']);
  215. grunt.registerTask('qunit-all', 'Run qunit tests', ['qunit:main', 'qunit-timezone']);
  216. grunt.registerTask('test', 'Lint files and run unit tests', ['lint-js', /*'lint-css',*/ 'qunit-all']);
  217. // Version numbering task.
  218. // grunt bump-version --newver=X.Y.Z
  219. grunt.registerTask('bump-version', 'string-replace');
  220. // Docs task.
  221. grunt.registerTask('screenshots', 'Rebuilds automated docs screenshots', function(){
  222. var phantomjs = require('phantomjs-prebuilt').path;
  223. grunt.file.recurse('docs/_static/screenshots/', function(abspath){
  224. grunt.file.delete(abspath);
  225. });
  226. grunt.file.recurse('docs/_screenshots/', function(abspath, root, subdir, filename){
  227. if (!/.html$/.test(filename))
  228. return;
  229. subdir = subdir || '';
  230. var outdir = 'docs/_static/screenshots/' + subdir,
  231. outfile = outdir + filename.replace(/.html$/, '.png');
  232. if (!grunt.file.exists(outdir))
  233. grunt.file.mkdir(outdir);
  234. // NOTE: For 'zh-TW' and 'ja' locales install adobe-source-han-sans-jp-fonts (Arch Linux)
  235. grunt.util.spawn({
  236. cmd: phantomjs,
  237. args: ['docs/_screenshots/script/screenshot.js', abspath, outfile]
  238. });
  239. });
  240. });
  241. grunt.registerTask('qunit-timezone', 'Run timezone tests', function(){
  242. process.env.TZ = 'Europe/Moscow';
  243. grunt.task.run('qunit:timezone');
  244. });
  245. };