Gruntfile.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*jshint node:true*/
  2. module.exports = function( grunt ) {
  3. "use strict";
  4. var banner,
  5. umdStart,
  6. umdMiddle,
  7. umdEnd,
  8. umdStandardDefine,
  9. umdAdditionalDefine,
  10. umdLocalizationDefine;
  11. banner = "/*!\n" +
  12. " * jQuery Validation Plugin v<%= pkg.version %>\n" +
  13. " *\n" +
  14. " * <%= pkg.homepage %>\n" +
  15. " *\n" +
  16. " * Copyright (c) <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>\n" +
  17. " * Released under the <%= _.map(pkg.licenses, 'type').join(', ') %> license\n" +
  18. " */\n";
  19. // Define UMD wrapper variables
  20. umdStart = "(function( factory ) {\n" +
  21. "\tif ( typeof define === \"function\" && define.amd ) {\n";
  22. umdMiddle = "\t} else if (typeof module === \"object\" && module.exports) {\n" +
  23. "\t\tmodule.exports = factory( require( \"jquery\" ) );\n" +
  24. "\t} else {\n" +
  25. "\t\tfactory( jQuery );\n" +
  26. "\t}\n" +
  27. "}(function( $ ) {\n\n";
  28. umdEnd = "return $;" +
  29. "\n}));";
  30. umdStandardDefine = "\t\tdefine( [\"jquery\"], factory );\n";
  31. umdAdditionalDefine = "\t\tdefine( [\"jquery\", \"./jquery.validate\"], factory );\n";
  32. umdLocalizationDefine = "\t\tdefine( [\"jquery\", \"../jquery.validate\"], factory );\n";
  33. grunt.initConfig( {
  34. pkg: grunt.file.readJSON( "package.json" ),
  35. concat: {
  36. // Used to copy to dist folder
  37. dist: {
  38. options: {
  39. banner: banner +
  40. umdStart +
  41. umdStandardDefine +
  42. umdMiddle,
  43. footer: umdEnd
  44. },
  45. files: {
  46. "dist/jquery.validate.js": [ "src/core.js", "src/*.js" ]
  47. }
  48. },
  49. extra: {
  50. options: {
  51. banner: banner +
  52. umdStart +
  53. umdAdditionalDefine +
  54. umdMiddle,
  55. footer: umdEnd
  56. },
  57. files: {
  58. "dist/additional-methods.js": [ "src/additional/additional.js", "src/additional/*.js" ]
  59. }
  60. }
  61. },
  62. uglify: {
  63. options: {
  64. preserveComments: false,
  65. banner: "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " +
  66. "<%= grunt.template.today('m/d/yyyy') %>\n" +
  67. " * <%= pkg.homepage %>\n" +
  68. " * Copyright (c) <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" +
  69. " Licensed <%= _.map(pkg.licenses, 'type').join(', ') %> */\n"
  70. },
  71. dist: {
  72. files: {
  73. "dist/additional-methods.min.js": "dist/additional-methods.js",
  74. "dist/jquery.validate.min.js": "dist/jquery.validate.js"
  75. }
  76. },
  77. all: {
  78. expand: true,
  79. cwd: "dist/localization",
  80. src: "**/*.js",
  81. dest: "dist/localization",
  82. ext: ".min.js"
  83. }
  84. },
  85. compress: {
  86. dist: {
  87. options: {
  88. mode: "zip",
  89. level: 1,
  90. archive: "dist/<%= pkg.name %>-<%= pkg.version %>.zip",
  91. pretty: true
  92. },
  93. src: [
  94. "changelog.txt",
  95. "demo/**/*.*",
  96. "dist/**/*.js",
  97. "Gruntfile.js",
  98. "lib/**/*.*",
  99. "package.json",
  100. "README.md",
  101. "src/**/*.*",
  102. "test/**/*.*"
  103. ]
  104. }
  105. },
  106. qunit: {
  107. files: "test/index.html"
  108. },
  109. jshint: {
  110. options: {
  111. jshintrc: true
  112. },
  113. core: {
  114. src: "src/**/*.js"
  115. },
  116. test: {
  117. src: [ "test/*.js", "test/additional/*.js" ]
  118. },
  119. grunt: {
  120. src: "Gruntfile.js"
  121. }
  122. },
  123. watch: {
  124. options: {
  125. atBegin: true
  126. },
  127. src: {
  128. files: "<%= jshint.core.src %>",
  129. tasks: [
  130. "concat"
  131. ]
  132. }
  133. },
  134. jscs: {
  135. all: [ "<%= jshint.core.src %>", "<%= jshint.test.src %>", "<%= jshint.grunt.src %>" ]
  136. },
  137. copy: {
  138. dist: {
  139. options: {
  140. // Append UMD wrapper
  141. process: function( content ) {
  142. return umdStart + umdLocalizationDefine + umdMiddle + content + umdEnd;
  143. }
  144. },
  145. src: "src/localization/*",
  146. dest: "dist/localization",
  147. expand: true,
  148. flatten: true,
  149. filter: "isFile"
  150. }
  151. },
  152. replace: {
  153. dist: {
  154. src: "dist/**/*.min.js",
  155. overwrite: true,
  156. replacements: [
  157. {
  158. from: "./jquery.validate",
  159. to: "./jquery.validate.min"
  160. }
  161. ]
  162. }
  163. }
  164. } );
  165. grunt.loadNpmTasks( "grunt-contrib-jshint" );
  166. grunt.loadNpmTasks( "grunt-contrib-qunit" );
  167. grunt.loadNpmTasks( "grunt-contrib-uglify" );
  168. grunt.loadNpmTasks( "grunt-contrib-concat" );
  169. grunt.loadNpmTasks( "grunt-contrib-compress" );
  170. grunt.loadNpmTasks( "grunt-contrib-watch" );
  171. grunt.loadNpmTasks( "grunt-jscs" );
  172. grunt.loadNpmTasks( "grunt-contrib-copy" );
  173. grunt.loadNpmTasks( "grunt-text-replace" );
  174. grunt.registerTask( "default", [ "concat", "copy", "jscs", "jshint", "qunit" ] );
  175. grunt.registerTask( "release", [ "default", "uglify", "replace", "compress" ] );
  176. grunt.registerTask( "start", [ "concat", "watch" ] );
  177. };