Gruntfile.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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: 'internet explorer',
  87. version: '10'
  88. },
  89. {
  90. browserName: 'firefox'
  91. },
  92. {
  93. browserName: 'chrome'
  94. },
  95. {
  96. browserName: 'opera',
  97. version: '12'
  98. },
  99. {
  100. browserName: 'opera'
  101. }
  102. ]
  103. }
  104. }
  105. },
  106. 'gh-pages': {
  107. options: {
  108. base: 'docs',
  109. branch: 'master',
  110. clone: 'node_modules/grunt-gh-pages/repo',
  111. message: 'Updated docs with master',
  112. push: true,
  113. repo: '[email protected]:select2/select2.github.io.git'
  114. },
  115. src: '**'
  116. },
  117. jekyll: {
  118. options: {
  119. src: 'docs',
  120. dest: 'docs/_site'
  121. },
  122. build: {
  123. d: null
  124. },
  125. serve: {
  126. options: {
  127. serve: true,
  128. watch: true
  129. }
  130. }
  131. },
  132. jshint: {
  133. options: {
  134. jshintrc: true
  135. },
  136. code: {
  137. src: ['src/js/**/*.js']
  138. },
  139. tests: {
  140. src: ['tests/**/*.js']
  141. }
  142. },
  143. sass: {
  144. dist: {
  145. options: {
  146. outputStyle: 'compressed'
  147. },
  148. files: {
  149. 'dist/css/select2.min.css': [
  150. 'src/scss/core.scss',
  151. 'src/scss/theme/default/layout.css'
  152. ]
  153. }
  154. },
  155. dev: {
  156. options: {
  157. outputStyle: 'nested'
  158. },
  159. files: {
  160. 'dist/css/select2.css': [
  161. 'src/scss/core.scss',
  162. 'src/scss/theme/default/layout.css'
  163. ]
  164. }
  165. }
  166. },
  167. symlink: {
  168. docs: {
  169. cwd: 'dist',
  170. expand: true,
  171. overwrite: false,
  172. src: [
  173. '*'
  174. ],
  175. dest: 'docs/dist',
  176. filter: 'isDirectory'
  177. }
  178. },
  179. requirejs: {
  180. 'dist': {
  181. options: {
  182. baseUrl: 'src/js',
  183. optimize: 'none',
  184. name: 'select2/core',
  185. out: 'dist/js/select2.js',
  186. include: amdIncludes.concat(includes),
  187. paths: {
  188. almond: '../../vendor/almond-0.2.9',
  189. jquery: 'jquery.shim'
  190. },
  191. wrap: grunt.file.readJSON('src/js/banner.json')
  192. }
  193. },
  194. 'dist.full': {
  195. options: {
  196. baseUrl: 'src/js',
  197. optimize: 'none',
  198. name: 'select2/core',
  199. out: 'dist/js/select2.full.js',
  200. include: amdIncludes.concat(fullIncludes),
  201. paths: {
  202. almond: '../../vendor/almond-0.2.9',
  203. jquery: 'jquery.shim',
  204. 'jquery.mousewheel': '../../vendor/jquery.mousewheel'
  205. },
  206. wrap: grunt.file.readJSON('src/js/banner.json')
  207. }
  208. },
  209. 'amd': {
  210. options: {
  211. baseUrl: 'src/js',
  212. optimize: 'none',
  213. name: 'select2/core',
  214. out: 'dist/js/select2.amd.js',
  215. include: includes,
  216. paths: {
  217. jquery: 'empty:'
  218. },
  219. wrap: grunt.file.readJSON('src/js/banner.amd.json')
  220. }
  221. },
  222. 'amd.full': {
  223. options: {
  224. baseUrl: 'src/js',
  225. optimize: 'none',
  226. name: 'select2/core',
  227. out: 'dist/js/select2.amd.full.js',
  228. include: fullIncludes,
  229. paths: {
  230. jquery: 'empty:',
  231. 'jquery.mousewheel': '../../vendor/jquery.mousewheel'
  232. },
  233. wrap: grunt.file.readJSON('src/js/banner.amd.json')
  234. }
  235. },
  236. 'i18n': {
  237. options: {
  238. baseUrl: 'src/js/select2/i18n',
  239. dir: 'dist/js/i18n',
  240. paths: i18nPaths,
  241. modules: i18nModules,
  242. wrap: grunt.file.readJSON('src/js/banner.json')
  243. }
  244. }
  245. },
  246. watch: {
  247. js: {
  248. files: [
  249. 'src/js/select2/**/*.js',
  250. 'tests/**/*.js'
  251. ],
  252. tasks: [
  253. 'compile',
  254. 'test',
  255. 'minify'
  256. ]
  257. },
  258. css: {
  259. files: [
  260. 'src/scss/**/*.scss'
  261. ],
  262. tasks: [
  263. 'compile',
  264. 'minify'
  265. ]
  266. }
  267. }
  268. });
  269. grunt.loadNpmTasks('grunt-contrib-clean');
  270. grunt.loadNpmTasks('grunt-contrib-concat');
  271. grunt.loadNpmTasks('grunt-contrib-connect');
  272. grunt.loadNpmTasks('grunt-contrib-jshint');
  273. grunt.loadNpmTasks('grunt-contrib-qunit');
  274. grunt.loadNpmTasks('grunt-contrib-requirejs');
  275. grunt.loadNpmTasks('grunt-contrib-symlink');
  276. grunt.loadNpmTasks('grunt-contrib-uglify');
  277. grunt.loadNpmTasks('grunt-contrib-watch');
  278. grunt.loadNpmTasks('grunt-gh-pages');
  279. grunt.loadNpmTasks('grunt-jekyll');
  280. grunt.loadNpmTasks('grunt-saucelabs');
  281. grunt.loadNpmTasks('grunt-sass');
  282. grunt.registerTask('default', ['compile', 'test', 'minify']);
  283. grunt.registerTask('compile', ['requirejs', 'sass:dev']);
  284. grunt.registerTask('minify', ['uglify', 'sass:dist']);
  285. grunt.registerTask('test', ['connect:tests', 'qunit', 'jshint']);
  286. var ciTasks = [];
  287. ciTasks.push('compile')
  288. ciTasks.push('connect:tests');
  289. // Can't run Sauce Labs tests in pull requests
  290. if (process.env.TRAVIS_PULL_REQUEST == 'false') {
  291. ciTasks.push('saucelabs-qunit');
  292. }
  293. ciTasks.push('qunit');
  294. ciTasks.push('jshint');
  295. grunt.registerTask('ci', ciTasks);
  296. grunt.registerTask('docs', ['symlink:docs', 'jekyll:serve']);
  297. grunt.registerTask('docs-release', ['default', 'clean:docs', 'gh-pages']);
  298. };