Gruntfile.js 7.5 KB

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