Gruntfile.js 8.1 KB

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