Gruntfile.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. module.exports = function( grunt ) {
  2. "use strict";
  3. var
  4. // files
  5. coreFiles = [
  6. "jquery.ui.core.js",
  7. "jquery.ui.widget.js",
  8. "jquery.ui.mouse.js",
  9. "jquery.ui.draggable.js",
  10. "jquery.ui.droppable.js",
  11. "jquery.ui.resizable.js",
  12. "jquery.ui.selectable.js",
  13. "jquery.ui.sortable.js",
  14. "jquery.ui.effect.js"
  15. ],
  16. uiFiles = coreFiles.map(function( file ) {
  17. return "ui/" + file;
  18. }).concat( expandFiles( "ui/*.js" ).filter(function( file ) {
  19. return coreFiles.indexOf( file.substring(3) ) === -1;
  20. })),
  21. allI18nFiles = expandFiles( "ui/i18n/*.js" ),
  22. cssFiles = [
  23. "core",
  24. "accordion",
  25. "autocomplete",
  26. "button",
  27. "datepicker",
  28. "dialog",
  29. "menu",
  30. "progressbar",
  31. "resizable",
  32. "selectable",
  33. "slider",
  34. "spinner",
  35. "tabs",
  36. "tooltip",
  37. "theme"
  38. ].map(function( component ) {
  39. return "themes/base/jquery.ui." + component + ".css";
  40. }),
  41. // minified files
  42. minify = {
  43. options: {
  44. preserveComments: false
  45. },
  46. main: {
  47. options: {
  48. banner: createBanner( uiFiles )
  49. },
  50. files: {
  51. "dist/jquery-ui.min.js": "dist/jquery-ui.js"
  52. }
  53. },
  54. i18n: {
  55. options: {
  56. banner: createBanner( allI18nFiles )
  57. },
  58. files: {
  59. "dist/i18n/jquery-ui-i18n.min.js": "dist/i18n/jquery-ui-i18n.js"
  60. }
  61. }
  62. },
  63. minifyCSS = {
  64. options: {
  65. keepSpecialComments: 0
  66. },
  67. main: {
  68. options: {
  69. keepSpecialComments: "*"
  70. },
  71. src: "dist/jquery-ui.css",
  72. dest: "dist/jquery-ui.min.css"
  73. }
  74. },
  75. compareFiles = {
  76. all: [
  77. "dist/jquery-ui.js",
  78. "dist/jquery-ui.min.js"
  79. ]
  80. };
  81. function mapMinFile( file ) {
  82. return "dist/" + file.replace( /\.js$/, ".min.js" ).replace( /ui\//, "minified/" );
  83. }
  84. function expandFiles( files ) {
  85. return grunt.util._.pluck( grunt.file.expandMapping( files ), "src" ).map(function( values ) {
  86. return values[ 0 ];
  87. });
  88. }
  89. uiFiles.concat( allI18nFiles ).forEach(function( file ) {
  90. minify[ file ] = {
  91. options: {
  92. banner: createBanner()
  93. },
  94. files: {}
  95. };
  96. minify[ file ].files[ mapMinFile( file ) ] = file;
  97. });
  98. cssFiles.forEach(function( file ) {
  99. minifyCSS[ file ] = {
  100. options: {
  101. banner: createBanner()
  102. },
  103. src: file,
  104. dest: "dist/" + file.replace( /\.css$/, ".min.css" ).replace( /themes\/base\//, "themes/base/minified/" )
  105. };
  106. });
  107. uiFiles.forEach(function( file ) {
  108. // TODO this doesn't do anything until https://github.com/rwldrn/grunt-compare-size/issues/13
  109. compareFiles[ file ] = [ file, mapMinFile( file ) ];
  110. });
  111. // grunt plugins
  112. grunt.loadNpmTasks( "grunt-contrib-jshint" );
  113. grunt.loadNpmTasks( "grunt-contrib-uglify" );
  114. grunt.loadNpmTasks( "grunt-contrib-concat" );
  115. grunt.loadNpmTasks( "grunt-contrib-qunit" );
  116. grunt.loadNpmTasks( "grunt-contrib-csslint" );
  117. grunt.loadNpmTasks( "grunt-contrib-cssmin" );
  118. grunt.loadNpmTasks( "grunt-html" );
  119. grunt.loadNpmTasks( "grunt-compare-size" );
  120. grunt.loadNpmTasks( "grunt-git-authors" );
  121. // local testswarm and build tasks
  122. grunt.loadTasks( "build/tasks" );
  123. function stripDirectory( file ) {
  124. return file.replace( /.+\/(.+?)>?$/, "$1" );
  125. }
  126. function createBanner( files ) {
  127. // strip folders
  128. var fileNames = files && files.map( stripDirectory );
  129. return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
  130. "<%= grunt.template.today('isoDate') %>\n" +
  131. "<%= pkg.homepage ? '* ' + pkg.homepage + '\\n' : '' %>" +
  132. (files ? "* Includes: " + fileNames.join(", ") + "\n" : "")+
  133. "* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
  134. " Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n";
  135. }
  136. grunt.initConfig({
  137. pkg: grunt.file.readJSON("package.json"),
  138. files: {
  139. dist: "<%= pkg.name %>-<%= pkg.version %>"
  140. },
  141. compare_size: compareFiles,
  142. concat: {
  143. ui: {
  144. options: {
  145. banner: createBanner( uiFiles ),
  146. stripBanners: {
  147. block: true
  148. }
  149. },
  150. src: uiFiles,
  151. dest: "dist/jquery-ui.js"
  152. },
  153. i18n: {
  154. options: {
  155. banner: createBanner( allI18nFiles )
  156. },
  157. src: allI18nFiles,
  158. dest: "dist/i18n/jquery-ui-i18n.js"
  159. },
  160. css: {
  161. options: {
  162. banner: createBanner( cssFiles ),
  163. stripBanners: {
  164. block: true
  165. }
  166. },
  167. src: cssFiles,
  168. dest: "dist/jquery-ui.css"
  169. }
  170. },
  171. uglify: minify,
  172. cssmin: minifyCSS,
  173. htmllint: {
  174. // ignore files that contain invalid html, used only for ajax content testing
  175. all: grunt.file.expand( [ "demos/**/*.html", "tests/**/*.html" ] ).filter(function( file ) {
  176. return !/(?:ajax\/content\d\.html|tabs\/data\/test\.html|tests\/unit\/core\/core\.html)/.test( file );
  177. })
  178. },
  179. copy: {
  180. dist_units_images: {
  181. src: "themes/base/images/*",
  182. strip: /^themes\/base\//,
  183. dest: "dist/"
  184. }
  185. },
  186. qunit: {
  187. files: expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
  188. // disabling everything that doesn't (quite) work with PhantomJS for now
  189. // TODO except for all|index|test, try to include more as we go
  190. return !( /(all|index|test|dialog|dialog_deprecated|tooltip)\.html$/ ).test( file );
  191. })
  192. },
  193. jshint: {
  194. options: {
  195. jshintrc: true
  196. },
  197. all: [
  198. "ui/*.js",
  199. "Gruntfile.js",
  200. "build/**/*.js",
  201. "tests/unit/**/*.js"
  202. ]
  203. },
  204. csslint: {
  205. base_theme: {
  206. src: "themes/base/*.css",
  207. options: {
  208. csslintrc: ".csslintrc"
  209. }
  210. }
  211. }
  212. });
  213. grunt.registerTask( "default", [ "lint", "test" ] );
  214. grunt.registerTask( "lint", [ "asciilint", "jshint", "csslint", "htmllint" ] );
  215. grunt.registerTask( "test", [ "qunit" ] );
  216. grunt.registerTask( "sizer", [ "concat:ui", "uglify:main", "compare_size:all" ] );
  217. grunt.registerTask( "sizer_all", [ "concat:ui", "uglify", "compare_size" ] );
  218. // "copy:dist_units_images" is used by unit tests
  219. grunt.registerTask( "build", [ "concat", "uglify", "cssmin", "copy:dist_units_images" ] );
  220. };