Gruntfile.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. module.exports = function (grunt) {
  2. // Full list of files that must be included by RequireJS
  3. includes = [
  4. 'jquery.select2'
  5. ];
  6. amdIncludes = [
  7. 'almond'
  8. ];
  9. fullIncludes = [
  10. 'jquery',
  11. 'jquery.mousewheel',
  12. 'select2/compat/matcher',
  13. 'select2/dropdown/attachContainer'
  14. ].concat(includes);
  15. var i18nModules = [];
  16. var i18nPaths = {};
  17. var i18nFiles = grunt.file.expand({
  18. cwd: 'src/js'
  19. }, 'select2/i18n/*.js');
  20. for (var i = 0; i < i18nFiles.length; i++) {
  21. var file = i18nFiles[i];
  22. var name = file.split('.')[0];
  23. i18nModules.push({
  24. name: name
  25. });
  26. i18nPaths[name] = '../../' + name;
  27. }
  28. grunt.initConfig({
  29. clean: {
  30. docs: ['docs/_site']
  31. },
  32. uglify: {
  33. 'dist': {
  34. src: 'dist/js/select2.js',
  35. dest: 'dist/js/select2.min.js'
  36. },
  37. 'dist.full': {
  38. src: 'dist/js/select2.full.js',
  39. dest: 'dist/js/select2.full.min.js'
  40. }
  41. },
  42. qunit: {
  43. all: [
  44. 'tests/**/*.html'
  45. ]
  46. },
  47. 'gh-pages': {
  48. options: {
  49. base: 'docs',
  50. branch: 'master',
  51. clone: 'node_modules/grunt-gh-pages/repo',
  52. message: 'Updated docs with master',
  53. push: true,
  54. repo: '[email protected]:select2/select2.github.io.git'
  55. },
  56. src: '**'
  57. },
  58. jekyll: {
  59. options: {
  60. src: 'docs',
  61. dest: 'docs/_site'
  62. },
  63. build: {
  64. d: null
  65. },
  66. serve: {
  67. options: {
  68. serve: true,
  69. watch: true
  70. }
  71. }
  72. },
  73. jshint: {
  74. options: {
  75. jshintrc: true
  76. },
  77. code: {
  78. src: ['src/js/**/*.js']
  79. },
  80. tests: {
  81. src: ['tests/**/*.js']
  82. }
  83. },
  84. sass: {
  85. dist: {
  86. options: {
  87. outputStyle: 'compressed'
  88. },
  89. files: {
  90. 'dist/css/select2.min.css': [
  91. 'src/scss/core.scss',
  92. 'src/scss/theme/default/layout.css'
  93. ]
  94. }
  95. },
  96. dev: {
  97. options: {
  98. outputStyle: 'nested'
  99. },
  100. files: {
  101. 'dist/css/select2.css': [
  102. 'src/scss/core.scss',
  103. 'src/scss/theme/default/layout.css'
  104. ]
  105. }
  106. }
  107. },
  108. symlink: {
  109. docs: {
  110. cwd: 'dist',
  111. expand: true,
  112. overwrite: false,
  113. src: [
  114. '*'
  115. ],
  116. dest: 'docs/dist',
  117. filter: 'isDirectory'
  118. }
  119. },
  120. requirejs: {
  121. 'dist': {
  122. options: {
  123. baseUrl: 'src/js',
  124. optimize: 'none',
  125. name: 'select2/core',
  126. out: 'dist/js/select2.js',
  127. include: amdIncludes.concat(includes),
  128. paths: {
  129. almond: '../../vendor/almond-0.2.9',
  130. jquery: 'jquery.shim'
  131. },
  132. wrap: grunt.file.readJSON('src/js/banner.json')
  133. }
  134. },
  135. 'dist.full': {
  136. options: {
  137. baseUrl: 'src/js',
  138. optimize: 'none',
  139. name: 'select2/core',
  140. out: 'dist/js/select2.full.js',
  141. include: amdIncludes.concat(fullIncludes),
  142. paths: {
  143. almond: '../../vendor/almond-0.2.9',
  144. jquery: '../../vendor/jquery-2.1.0',
  145. 'jquery.mousewheel': '../../vendor/jquery.mousewheel'
  146. },
  147. wrap: grunt.file.readJSON('src/js/banner.json')
  148. }
  149. },
  150. 'amd': {
  151. options: {
  152. baseUrl: 'src/js',
  153. optimize: 'none',
  154. name: 'select2/core',
  155. out: 'dist/js/select2.amd.js',
  156. include: includes,
  157. paths: {
  158. jquery: 'empty:'
  159. },
  160. wrap: grunt.file.readJSON('src/js/banner.json')
  161. }
  162. },
  163. 'amd.full': {
  164. options: {
  165. baseUrl: 'src/js',
  166. optimize: 'none',
  167. name: 'select2/core',
  168. out: 'dist/js/select2.amd.full.js',
  169. include: fullIncludes,
  170. paths: {
  171. jquery: 'empty:',
  172. 'jquery.mousewheel': '../../vendor/jquery.mousewheel'
  173. },
  174. wrap: grunt.file.readJSON('src/js/banner.json')
  175. }
  176. },
  177. 'i18n': {
  178. options: {
  179. baseUrl: 'src/js/select2/i18n',
  180. dir: 'dist/js/i18n',
  181. paths: i18nPaths,
  182. modules: i18nModules,
  183. wrap: grunt.file.readJSON('src/js/banner.json')
  184. }
  185. }
  186. },
  187. watch: {
  188. js: {
  189. files: [
  190. 'src/js/select2/**/*.js',
  191. 'tests/**/*.js'
  192. ],
  193. tasks: [
  194. 'compile',
  195. 'test',
  196. 'minify'
  197. ]
  198. },
  199. css: {
  200. files: [
  201. 'src/scss/**/*.scss'
  202. ],
  203. tasks: [
  204. 'compile',
  205. 'minify'
  206. ]
  207. }
  208. }
  209. });
  210. grunt.loadNpmTasks('grunt-contrib-clean');
  211. grunt.loadNpmTasks('grunt-contrib-concat');
  212. grunt.loadNpmTasks('grunt-contrib-jshint');
  213. grunt.loadNpmTasks('grunt-contrib-qunit');
  214. grunt.loadNpmTasks('grunt-contrib-requirejs');
  215. grunt.loadNpmTasks('grunt-contrib-symlink');
  216. grunt.loadNpmTasks('grunt-contrib-uglify');
  217. grunt.loadNpmTasks('grunt-contrib-watch');
  218. grunt.loadNpmTasks('grunt-gh-pages');
  219. grunt.loadNpmTasks('grunt-jekyll');
  220. grunt.loadNpmTasks('grunt-sass');
  221. grunt.registerTask('default', ['compile', 'test', 'minify']);
  222. grunt.registerTask('compile', ['requirejs', 'sass:dev']);
  223. grunt.registerTask('minify', ['uglify', 'sass:dist']);
  224. grunt.registerTask('test', ['qunit', 'jshint']);
  225. grunt.registerTask('docs', ['symlink:docs', 'jekyll:serve']);
  226. grunt.registerTask('docs-release', ['default', 'clean:docs', 'gh-pages']);
  227. };