Gruntfile.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. var testFiles = grunt.file.expand('tests/**/*.html');
  25. var testUrls = testFiles.map(function (filePath) {
  26. return 'http://localhost:9999/' + filePath;
  27. });
  28. var testBuildNumber = "unknown";
  29. if (process.env.TRAVIS_JOB_ID) {
  30. testBuildNumber = "travis-" + process.env.TRAVIS_JOB_ID;
  31. } else {
  32. var currentTime = new Date();
  33. testBuildNumber = "manual-" + currentTime.getTime();
  34. }
  35. for (var i = 0; i < i18nFiles.length; i++) {
  36. var file = i18nFiles[i];
  37. var name = file.split('.')[0];
  38. i18nModules.push({
  39. name: name
  40. });
  41. i18nPaths[name] = '../../' + name;
  42. }
  43. grunt.initConfig({
  44. clean: {
  45. docs: ['docs/_site']
  46. },
  47. connect: {
  48. tests: {
  49. options: {
  50. base: '.',
  51. hostname: '127.0.0.1',
  52. port: 9999
  53. }
  54. }
  55. },
  56. uglify: {
  57. 'dist': {
  58. src: 'dist/js/select2.js',
  59. dest: 'dist/js/select2.min.js'
  60. },
  61. 'dist.full': {
  62. src: 'dist/js/select2.full.js',
  63. dest: 'dist/js/select2.full.min.js'
  64. }
  65. },
  66. qunit: {
  67. all: {
  68. options: {
  69. urls: testUrls
  70. }
  71. }
  72. },
  73. 'saucelabs-qunit': {
  74. all: {
  75. options: {
  76. build: testBuildNumber,
  77. tags: ['tests', 'qunit'],
  78. urls: testUrls,
  79. testname: 'QUnit test for Select2',
  80. browsers: [
  81. {
  82. browserName: 'internet explorer',
  83. version: '9'
  84. },
  85. {
  86. browserName: 'firefox'
  87. },
  88. {
  89. browserName: 'chrome'
  90. }
  91. ]
  92. }
  93. }
  94. },
  95. 'gh-pages': {
  96. options: {
  97. base: 'docs',
  98. branch: 'master',
  99. clone: 'node_modules/grunt-gh-pages/repo',
  100. message: 'Updated docs with master',
  101. push: true,
  102. repo: '[email protected]:select2/select2.github.io.git'
  103. },
  104. src: '**'
  105. },
  106. jekyll: {
  107. options: {
  108. src: 'docs',
  109. dest: 'docs/_site'
  110. },
  111. build: {
  112. d: null
  113. },
  114. serve: {
  115. options: {
  116. serve: true,
  117. watch: true
  118. }
  119. }
  120. },
  121. jshint: {
  122. options: {
  123. jshintrc: true
  124. },
  125. code: {
  126. src: ['src/js/**/*.js']
  127. },
  128. tests: {
  129. src: ['tests/**/*.js']
  130. }
  131. },
  132. sass: {
  133. dist: {
  134. options: {
  135. outputStyle: 'compressed'
  136. },
  137. files: {
  138. 'dist/css/select2.min.css': [
  139. 'src/scss/core.scss',
  140. 'src/scss/theme/default/layout.css'
  141. ]
  142. }
  143. },
  144. dev: {
  145. options: {
  146. outputStyle: 'nested'
  147. },
  148. files: {
  149. 'dist/css/select2.css': [
  150. 'src/scss/core.scss',
  151. 'src/scss/theme/default/layout.css'
  152. ]
  153. }
  154. }
  155. },
  156. symlink: {
  157. docs: {
  158. cwd: 'dist',
  159. expand: true,
  160. overwrite: false,
  161. src: [
  162. '*'
  163. ],
  164. dest: 'docs/dist',
  165. filter: 'isDirectory'
  166. }
  167. },
  168. requirejs: {
  169. 'dist': {
  170. options: {
  171. baseUrl: 'src/js',
  172. optimize: 'none',
  173. name: 'select2/core',
  174. out: 'dist/js/select2.js',
  175. include: amdIncludes.concat(includes),
  176. paths: {
  177. almond: '../../vendor/almond-0.2.9',
  178. jquery: 'jquery.shim'
  179. },
  180. wrap: grunt.file.readJSON('src/js/banner.json')
  181. }
  182. },
  183. 'dist.full': {
  184. options: {
  185. baseUrl: 'src/js',
  186. optimize: 'none',
  187. name: 'select2/core',
  188. out: 'dist/js/select2.full.js',
  189. include: amdIncludes.concat(fullIncludes),
  190. paths: {
  191. almond: '../../vendor/almond-0.2.9',
  192. jquery: 'jquery.shim',
  193. 'jquery.mousewheel': '../../vendor/jquery.mousewheel'
  194. },
  195. wrap: grunt.file.readJSON('src/js/banner.json')
  196. }
  197. },
  198. 'amd': {
  199. options: {
  200. baseUrl: 'src/js',
  201. optimize: 'none',
  202. name: 'select2/core',
  203. out: 'dist/js/select2.amd.js',
  204. include: includes,
  205. paths: {
  206. jquery: 'empty:'
  207. },
  208. wrap: grunt.file.readJSON('src/js/banner.amd.json')
  209. }
  210. },
  211. 'amd.full': {
  212. options: {
  213. baseUrl: 'src/js',
  214. optimize: 'none',
  215. name: 'select2/core',
  216. out: 'dist/js/select2.amd.full.js',
  217. include: fullIncludes,
  218. paths: {
  219. jquery: 'empty:',
  220. 'jquery.mousewheel': '../../vendor/jquery.mousewheel'
  221. },
  222. wrap: grunt.file.readJSON('src/js/banner.amd.json')
  223. }
  224. },
  225. 'i18n': {
  226. options: {
  227. baseUrl: 'src/js/select2/i18n',
  228. dir: 'dist/js/i18n',
  229. paths: i18nPaths,
  230. modules: i18nModules,
  231. wrap: grunt.file.readJSON('src/js/banner.json')
  232. }
  233. }
  234. },
  235. watch: {
  236. js: {
  237. files: [
  238. 'src/js/select2/**/*.js',
  239. 'tests/**/*.js'
  240. ],
  241. tasks: [
  242. 'compile',
  243. 'test',
  244. 'minify'
  245. ]
  246. },
  247. css: {
  248. files: [
  249. 'src/scss/**/*.scss'
  250. ],
  251. tasks: [
  252. 'compile',
  253. 'minify'
  254. ]
  255. }
  256. }
  257. });
  258. grunt.loadNpmTasks('grunt-contrib-clean');
  259. grunt.loadNpmTasks('grunt-contrib-concat');
  260. grunt.loadNpmTasks('grunt-contrib-connect');
  261. grunt.loadNpmTasks('grunt-contrib-jshint');
  262. grunt.loadNpmTasks('grunt-contrib-qunit');
  263. grunt.loadNpmTasks('grunt-contrib-requirejs');
  264. grunt.loadNpmTasks('grunt-contrib-symlink');
  265. grunt.loadNpmTasks('grunt-contrib-uglify');
  266. grunt.loadNpmTasks('grunt-contrib-watch');
  267. grunt.loadNpmTasks('grunt-gh-pages');
  268. grunt.loadNpmTasks('grunt-jekyll');
  269. grunt.loadNpmTasks('grunt-saucelabs');
  270. grunt.loadNpmTasks('grunt-sass');
  271. grunt.registerTask('default', ['compile', 'test', 'minify']);
  272. grunt.registerTask('compile', ['requirejs', 'sass:dev']);
  273. grunt.registerTask('minify', ['uglify', 'sass:dist']);
  274. grunt.registerTask('test', ['qunit', 'jshint']);
  275. grunt.registerTask('ci', ['compile', 'connect:tests', 'saucelabs-qunit', 'test']);
  276. grunt.registerTask('docs', ['symlink:docs', 'jekyll:serve']);
  277. grunt.registerTask('docs-release', ['default', 'clean:docs', 'gh-pages']);
  278. };