grunt.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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( grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
  19. return coreFiles.indexOf( file.substring(3) ) === -1;
  20. })),
  21. allI18nFiles = grunt.file.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. "dist/jquery-ui.min.js": [ "<banner:meta.bannerAll>", "dist/jquery-ui.js" ],
  44. "dist/i18n/jquery-ui-i18n.min.js": [ "<banner:meta.bannerI18n>", "dist/i18n/jquery-ui-i18n.js" ]
  45. },
  46. minifyCSS = {
  47. "dist/jquery-ui.min.css": "dist/jquery-ui.css"
  48. },
  49. compareFiles = {
  50. all: [
  51. "dist/jquery-ui.js",
  52. "dist/jquery-ui.min.js"
  53. ]
  54. };
  55. function mapMinFile( file ) {
  56. return "dist/" + file.replace( /\.js$/, ".min.js" ).replace( /ui\//, "minified/" );
  57. }
  58. uiFiles.concat( allI18nFiles ).forEach(function( file ) {
  59. minify[ mapMinFile( file ) ] = [ "<banner>", file ];
  60. });
  61. cssFiles.forEach(function( file ) {
  62. minifyCSS[ "dist/" + file.replace( /\.css$/, ".min.css" ).replace( /themes\/base\//, "themes/base/minified/" ) ] = [ "<banner>", "<strip_all_banners:" + file + ">" ];
  63. });
  64. uiFiles.forEach(function( file ) {
  65. compareFiles[ file ] = [ file, mapMinFile( file ) ];
  66. });
  67. // grunt plugins
  68. grunt.loadNpmTasks( "grunt-css" );
  69. grunt.loadNpmTasks( "grunt-html" );
  70. grunt.loadNpmTasks( "grunt-compare-size" );
  71. grunt.loadNpmTasks( "grunt-junit" );
  72. grunt.loadNpmTasks( "grunt-git-authors" );
  73. // local testswarm and build tasks
  74. grunt.loadTasks( "build/tasks" );
  75. grunt.registerHelper( "strip_all_banners", function( filepath ) {
  76. return grunt.file.read( filepath ).replace( /^\s*\/\*[\s\S]*?\*\/\s*/g, "" );
  77. });
  78. function stripBanner( files ) {
  79. return files.map(function( file ) {
  80. return "<strip_all_banners:" + file + ">";
  81. });
  82. }
  83. function stripDirectory( file ) {
  84. // TODO: we're receiving the directive, so we need to strip the trailing >
  85. // we should be receving a clean path without the directive
  86. return file.replace( /.+\/(.+?)>?$/, "$1" );
  87. }
  88. // allow access from banner template
  89. global.stripDirectory = stripDirectory;
  90. function createBanner( files ) {
  91. // strip folders
  92. var fileNames = files && files.map( stripDirectory );
  93. return "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
  94. "<%= grunt.template.today('isoDate') %>\n" +
  95. "<%= pkg.homepage ? '* ' + pkg.homepage + '\n' : '' %>" +
  96. "* Includes: " + (files ? fileNames.join(", ") : "<%= stripDirectory(grunt.task.current.file.src[1]) %>") + "\n" +
  97. "* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
  98. " Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */";
  99. }
  100. grunt.initConfig({
  101. pkg: "<json:package.json>",
  102. files: {
  103. dist: "<%= pkg.name %>-<%= pkg.version %>",
  104. cdn: "<%= pkg.name %>-<%= pkg.version %>-cdn",
  105. themes: "<%= pkg.name %>-themes-<%= pkg.version %>"
  106. },
  107. meta: {
  108. banner: createBanner(),
  109. bannerAll: createBanner( uiFiles ),
  110. bannerI18n: createBanner( allI18nFiles ),
  111. bannerCSS: createBanner( cssFiles )
  112. },
  113. compare_size: compareFiles,
  114. concat: {
  115. ui: {
  116. src: [ "<banner:meta.bannerAll>", stripBanner( uiFiles ) ],
  117. dest: "dist/jquery-ui.js"
  118. },
  119. i18n: {
  120. src: [ "<banner:meta.bannerI18n>", allI18nFiles ],
  121. dest: "dist/i18n/jquery-ui-i18n.js"
  122. },
  123. css: {
  124. src: [ "<banner:meta.bannerCSS>", stripBanner( cssFiles ) ],
  125. dest: "dist/jquery-ui.css"
  126. }
  127. },
  128. min: minify,
  129. cssmin: minifyCSS,
  130. htmllint: {
  131. // ignore files that contain invalid html, used only for ajax content testing
  132. all: grunt.file.expand( [ "demos/**/*.html", "tests/**/*.html" ] ).filter(function( file ) {
  133. return !/(?:ajax\/content\d\.html|tabs\/data\/test\.html|tests\/unit\/core\/core\.html)/.test( file );
  134. })
  135. },
  136. copy: {
  137. dist: {
  138. src: [
  139. "AUTHORS.txt",
  140. "jquery-*.js",
  141. "MIT-LICENSE.txt",
  142. "README.md",
  143. "grunt.js",
  144. "package.json",
  145. "*.jquery.json",
  146. "ui/**/*",
  147. "ui/.jshintrc",
  148. "demos/**/*",
  149. "themes/**/*",
  150. "external/**/*",
  151. "tests/**/*"
  152. ],
  153. renames: {
  154. "dist/jquery-ui.js": "ui/jquery-ui.js",
  155. "dist/jquery-ui.min.js": "ui/minified/jquery-ui.min.js",
  156. "dist/i18n/jquery-ui-i18n.js": "ui/i18n/jquery-ui-i18n.js",
  157. "dist/i18n/jquery-ui-i18n.min.js": "ui/minified/i18n/jquery-ui-i18n.min.js",
  158. "dist/jquery-ui.css": "themes/base/jquery-ui.css",
  159. "dist/jquery-ui.min.css": "themes/base/minified/jquery-ui.min.css"
  160. },
  161. dest: "dist/<%= files.dist %>"
  162. },
  163. dist_min: {
  164. src: "dist/minified/**/*",
  165. strip: /^dist/,
  166. dest: "dist/<%= files.dist %>/ui"
  167. },
  168. dist_css_min: {
  169. src: "dist/themes/base/minified/*.css",
  170. strip: /^dist/,
  171. dest: "dist/<%= files.dist %>"
  172. },
  173. dist_units_images: {
  174. src: "themes/base/images/*",
  175. strip: /^themes\/base\//,
  176. dest: "dist/"
  177. },
  178. dist_min_images: {
  179. src: "themes/base/images/*",
  180. strip: /^themes\/base\//,
  181. dest: "dist/<%= files.dist %>/themes/base/minified"
  182. },
  183. cdn: {
  184. src: [
  185. "AUTHORS.txt",
  186. "MIT-LICENSE.txt",
  187. "ui/*.js",
  188. "package.json"
  189. ],
  190. renames: {
  191. "dist/jquery-ui.js": "jquery-ui.js",
  192. "dist/jquery-ui.min.js": "jquery-ui.min.js",
  193. "dist/i18n/jquery-ui-i18n.js": "i18n/jquery-ui-i18n.js",
  194. "dist/i18n/jquery-ui-i18n.min.js": "i18n/jquery-ui-i18n.min.js",
  195. "dist/jquery-ui.css": "themes/base/jquery-ui.css",
  196. "dist/jquery-ui.min.css": "themes/base/minified/jquery-ui.min.css"
  197. },
  198. dest: "dist/<%= files.cdn %>"
  199. },
  200. cdn_i18n: {
  201. src: "ui/i18n/jquery.ui.datepicker-*.js",
  202. strip: "ui/",
  203. dest: "dist/<%= files.cdn %>"
  204. },
  205. cdn_i18n_min: {
  206. src: "dist/minified/i18n/jquery.ui.datepicker-*.js",
  207. strip: "dist/minified",
  208. dest: "dist/<%= files.cdn %>"
  209. },
  210. cdn_min: {
  211. src: "dist/minified/*.js",
  212. strip: /^dist\/minified/,
  213. dest: "dist/<%= files.cdn %>/ui"
  214. },
  215. cdn_min_images: {
  216. src: "themes/base/images/*",
  217. strip: /^themes\/base\//,
  218. dest: "dist/<%= files.cdn %>/themes/base/minified"
  219. },
  220. cdn_themes: {
  221. src: "dist/<%= files.themes %>/themes/**/*",
  222. strip: "dist/<%= files.themes %>",
  223. dest: "dist/<%= files.cdn %>"
  224. },
  225. themes: {
  226. src: [
  227. "AUTHORS.txt",
  228. "MIT-LICENSE.txt",
  229. "package.json"
  230. ],
  231. dest: "dist/<%= files.themes %>"
  232. }
  233. },
  234. zip: {
  235. dist: {
  236. src: "<%= files.dist %>",
  237. dest: "<%= files.dist %>.zip"
  238. },
  239. cdn: {
  240. src: "<%= files.cdn %>",
  241. dest: "<%= files.cdn %>.zip"
  242. },
  243. themes: {
  244. src: "<%= files.themes %>",
  245. dest: "<%= files.themes %>.zip"
  246. }
  247. },
  248. md5: {
  249. dist: {
  250. src: "dist/<%= files.dist %>",
  251. dest: "dist/<%= files.dist %>/MANIFEST"
  252. },
  253. cdn: {
  254. src: "dist/<%= files.cdn %>",
  255. dest: "dist/<%= files.cdn %>/MANIFEST"
  256. },
  257. themes: {
  258. src: "dist/<%= files.themes %>",
  259. dest: "dist/<%= files.themes %>/MANIFEST"
  260. }
  261. },
  262. qunit: {
  263. files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
  264. // disabling everything that doesn't (quite) work with PhantomJS for now
  265. // TODO except for all|index|test, try to include more as we go
  266. return !( /(all|all-active|index|test|draggable|droppable|selectable|resizable|sortable|dialog|slider|datepicker|tabs|tabs_deprecated|tooltip)\.html$/ ).test( file );
  267. })
  268. },
  269. lint: {
  270. ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
  271. // TODO remove items from this list once rewritten
  272. return !( /(mouse|datepicker|draggable|droppable|resizable|selectable|sortable)\.js$/ ).test( file );
  273. }),
  274. grunt: [ "grunt.js", "build/**/*.js" ],
  275. tests: "tests/unit/**/*.js"
  276. },
  277. csslint: {
  278. // nothing: []
  279. // TODO figure out what to check for, then fix and enable
  280. base_theme: {
  281. src: grunt.file.expandFiles( "themes/base/*.css" ).filter(function( file ) {
  282. // TODO remove items from this list once rewritten
  283. return !( /(button|datepicker|core|dialog|theme)\.css$/ ).test( file );
  284. }),
  285. // TODO consider reenabling some of these rules
  286. rules: {
  287. "import": false,
  288. "important": false,
  289. "outline-none": false,
  290. // especially this one
  291. "overqualified-elements": false,
  292. "compatible-vendor-prefixes": false
  293. }
  294. }
  295. },
  296. jshint: (function() {
  297. function parserc( path ) {
  298. var rc = grunt.file.readJSON( (path || "") + ".jshintrc" ),
  299. settings = {
  300. options: rc,
  301. globals: {}
  302. };
  303. (rc.predef || []).forEach(function( prop ) {
  304. settings.globals[ prop ] = true;
  305. });
  306. delete rc.predef;
  307. return settings;
  308. }
  309. return {
  310. grunt: parserc(),
  311. ui: parserc( "ui/" ),
  312. // TODO: `evil: true` is only for document.write() https://github.com/jshint/jshint/issues/519
  313. // TODO: don't create so many globals in tests
  314. tests: parserc( "tests/" )
  315. };
  316. })()
  317. });
  318. grunt.registerTask( "default", "lint csslint htmllint qunit" );
  319. grunt.registerTask( "sizer", "concat:ui min:dist/jquery-ui.min.js compare_size:all" );
  320. grunt.registerTask( "sizer_all", "concat:ui min compare_size" );
  321. grunt.registerTask( "build", "concat min cssmin copy:dist_units_images" );
  322. grunt.registerTask( "release", "clean build copy:dist copy:dist_min copy:dist_min_images copy:dist_css_min md5:dist zip:dist" );
  323. grunt.registerTask( "release_themes", "release generate_themes copy:themes md5:themes zip:themes" );
  324. grunt.registerTask( "release_cdn", "release_themes copy:cdn copy:cdn_min copy:cdn_i18n copy:cdn_i18n_min copy:cdn_min_images copy:cdn_themes md5:cdn zip:cdn" );
  325. };