Gruntfile.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*global module:false */
  2. module.exports = function(grunt) {
  3. 'use strict';
  4. var pkg = grunt.file.readJSON( 'package.json' ),
  5. nomod = '/*** This file is dynamically generated ***\n' +
  6. '█████▄ ▄████▄ █████▄ ▄████▄ ██████ ███████▄ ▄████▄ █████▄ ██ ██████ ██ ██\n' +
  7. '██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██\n' +
  8. '██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██▀▀ ▀▀▀▀██\n' +
  9. '█████▀ ▀████▀ ██ ██ ▀████▀ ██ ██ ██ ██ ▀████▀ █████▀ ██ ██ █████▀\n*/\n',
  10. hintOpts = {
  11. 'jquery': true,
  12. 'browser': true,
  13. 'sub': true, // used by layouts
  14. '-W100': true // ignore "This character may get silently deleted by one or more browsers."
  15. };
  16. // Project configuration.
  17. grunt.initConfig({
  18. pkg: pkg,
  19. clean: {
  20. core: {
  21. src: [
  22. 'dist/css/*',
  23. 'dist/js/*',
  24. 'js/jquery.keyboard.extension-all.js'
  25. ]
  26. },
  27. layouts: {
  28. src: [
  29. 'dist/*',
  30. 'js/jquery.keyboard.extension-all.js',
  31. 'layouts/keyboard-layouts-combined.js',
  32. 'layouts/keyboard-layouts-microsoft.js'
  33. ]
  34. },
  35. languages: {
  36. src: [ 'dist/languages/*' ]
  37. }
  38. },
  39. copy: {
  40. js: {
  41. files : [{
  42. expand: true,
  43. dot: true,
  44. flatten: true,
  45. src: [ 'js/jquery.keyboard.js' ],
  46. dest: 'dist/js/'
  47. }]
  48. }
  49. },
  50. concat: {
  51. exts: {
  52. options: {
  53. banner: nomod + '/*! jQuery UI Virtual Keyboard (<%= pkg.version %>) - ALL Extensions + Mousewheel */\n'
  54. },
  55. files: {
  56. 'js/jquery.keyboard.extension-all.js': [ 'js/jquery.keyboard.extension-*.js', 'js/jquery.mousewheel.js' ]
  57. }
  58. },
  59. origLayouts: {
  60. options: {
  61. banner: nomod + '/*! jQuery UI Virtual Keyboard - Original Layouts */\n'
  62. },
  63. files: {
  64. 'layouts/keyboard-layouts-combined.js': [
  65. 'layouts/*',
  66. '!layouts/_layout_template.js',
  67. '!layouts/ms-*.js',
  68. '!layouts/keyboard-layouts-greywyvern.js',
  69. 'languages/*.js',
  70. '!languages/_language_template.js',
  71. '!languages/*.untranslated.js'
  72. ]
  73. }
  74. },
  75. msLayouts: {
  76. options: {
  77. banner: nomod + '/*! jQuery UI Virtual Keyboard - Microsoft Generated Layouts */\n'
  78. },
  79. files: {
  80. 'layouts/keyboard-layouts-microsoft.js': [
  81. 'layouts/ms-*.js',
  82. '!layouts/_layout_template.js',
  83. 'languages/*.js',
  84. '!languages/_language_template.js',
  85. '!languages/*.untranslated.js'
  86. ]
  87. }
  88. },
  89. greyLayouts: {
  90. options: {
  91. banner: nomod + '/*! jQuery UI Virtual Keyboard - Microsoft Generated Layouts */\n'
  92. },
  93. files: {
  94. 'dist/layouts/keyboard-layouts-greywyvern.min.js': [
  95. 'layouts/keyboard-layouts-greywyvern.js',
  96. 'languages/*.js',
  97. '!languages/_language_template.js',
  98. '!languages/*.untranslated.js'
  99. ]
  100. }
  101. }
  102. },
  103. jshint: {
  104. core: {
  105. options: hintOpts,
  106. src: [ 'js/jquery.*.js' ]
  107. },
  108. layouts: {
  109. options: hintOpts,
  110. src: [ 'js/jquery.*.js', 'layouts/*' ]
  111. },
  112. languages: {
  113. option: hintOpts,
  114. src: [ 'languages/*' ]
  115. }
  116. },
  117. cssmin: {
  118. target: {
  119. files: [{
  120. expand: true,
  121. flatten: true,
  122. src: ['css/*.css'],
  123. dest: 'dist/css/',
  124. ext: '.min.css'
  125. }]
  126. }
  127. },
  128. uglify: {
  129. options: {
  130. output: {
  131. comments: /^!/,
  132. beautify: false
  133. },
  134. report: 'gzip'
  135. },
  136. core: {
  137. files: [{
  138. expand: true,
  139. cwd: '',
  140. src: [ 'js/jquery*.js' ],
  141. dest: 'dist/js/',
  142. ext: '.min.js',
  143. extDot: 'last',
  144. flatten: true
  145. }]
  146. },
  147. splitLayouts: {
  148. files: [{
  149. expand: true,
  150. cwd: '',
  151. src: [ 'layouts/*.js', '!layouts/_layout_template.js', '!layouts/keyboard-layouts-greywyvern.js' ],
  152. dest: 'dist/layouts/',
  153. ext: '.min.js',
  154. extDot: 'last',
  155. flatten: true
  156. }]
  157. },
  158. greyLayout: {
  159. files: [{
  160. expand: true,
  161. cwd: '',
  162. src: [ 'dist/layouts/keyboard-layouts-greywyvern.min.js' ],
  163. dest: 'dist/layouts/',
  164. ext: '.js',
  165. extDot: 'last',
  166. flatten: true
  167. }]
  168. },
  169. languages: {
  170. files: [{
  171. expand: true,
  172. cwd: '',
  173. src: [ 'languages/*.js', '!languages/_language_template.js', '!languages/*.untranslated.js' ],
  174. dest: 'dist/languages/',
  175. ext: '.min.js',
  176. extDot: 'last',
  177. flatten: true
  178. }]
  179. }
  180. },
  181. qunit: {
  182. files: ['testing/test.html']
  183. },
  184. watch: {
  185. scripts: {
  186. files: ['js/*.js'],
  187. tasks: ['build']
  188. }
  189. }
  190. });
  191. grunt.loadNpmTasks('grunt-contrib-clean');
  192. grunt.loadNpmTasks('grunt-contrib-jshint');
  193. grunt.loadNpmTasks('grunt-contrib-qunit');
  194. grunt.loadNpmTasks('grunt-contrib-concat');
  195. grunt.loadNpmTasks('grunt-contrib-uglify');
  196. grunt.loadNpmTasks('grunt-contrib-cssmin');
  197. grunt.loadNpmTasks('grunt-contrib-watch');
  198. grunt.loadNpmTasks('grunt-contrib-copy');
  199. // Default task.
  200. grunt.registerTask('default', [
  201. 'clean:core',
  202. 'jshint:core',
  203. 'qunit',
  204. 'copy',
  205. 'concat:exts',
  206. 'cssmin',
  207. 'uglify:core',
  208. 'updateManifest'
  209. ]);
  210. // layout build takes a lot longer to uglify
  211. grunt.registerTask('layouts', [
  212. 'clean:layouts',
  213. 'jshint:layouts',
  214. 'concat',
  215. 'cssmin',
  216. 'uglify'
  217. ]);
  218. function escapeRegExp(str) {
  219. return str.replace(/[$()*+\-.\/?[\\\]^{|}]/g, '\\$&');
  220. }
  221. // update keyboard.jquery.json file version numbers to match the package.json version
  222. grunt.registerTask( 'updateManifest', function() {
  223. var i, project,
  224. projectFile = [ 'keyboard.jquery.json', 'bower.json' ],
  225. len = projectFile.length;
  226. for ( i = 0; i < len; i++ ) {
  227. if ( !grunt.file.exists( projectFile[ i ] ) ) {
  228. grunt.log.error( 'file ' + projectFile[ i ] + ' not found' );
  229. return true; // return false to abort the execution
  230. }
  231. project = grunt.file.readJSON( projectFile[ i ] ); // get file as json object
  232. if (i === 0 ) {
  233. // only update version in keyboard.jquery.json
  234. project.version = pkg.version;
  235. } else if (i === 1) {
  236. // update devDependencies in bower
  237. project.devDependencies = pkg.devDependencies;
  238. }
  239. grunt.file.write( projectFile[i], JSON.stringify( project, null, 2 ) ); // serialize it back to file
  240. }
  241. // check internal version number
  242. project = grunt.file.read('js/jquery.keyboard.js');
  243. if (
  244. new RegExp(escapeRegExp('/*! jQuery UI Virtual Keyboard v' + pkg.version)).test(project) &&
  245. new RegExp(escapeRegExp('base.version = \'' + pkg.version)).test(project)
  246. ) {
  247. console.info('versions all match!');
  248. } else {
  249. grunt.log.writeln('\n**** version mismatch! ****'['red'].bold);
  250. }
  251. // check internal version number
  252. project = grunt.file.read('README.md');
  253. if (!new RegExp(escapeRegExp('### Version ' + pkg.version)).test(project)) {
  254. grunt.log.writeln('\n**** Missing Readme entry! ****'['red'].bold);
  255. }
  256. });
  257. };