Gruntfile.js 7.9 KB

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