Gruntfile.js 7.3 KB

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