Gruntfile.js 5.6 KB

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