Gruntfile.js 7.4 KB

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