Gruntfile.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. testTimeout: 8000,
  111. testname: 'QUnit test for Select2',
  112. browsers: [
  113. /*
  114. {
  115. browserName: 'internet explorer',
  116. version: '8',
  117. platform: 'Windows 7'
  118. },
  119. {
  120. browserName: 'internet explorer',
  121. version: '9',
  122. platform: 'Windows 7'
  123. },
  124. {
  125. browserName: 'internet explorer',
  126. version: '10',
  127. platform: 'Windows 7'
  128. },
  129. */
  130. {
  131. browserName: 'internet explorer',
  132. version: '11',
  133. platform: 'Windows 10'
  134. },
  135. {
  136. browserName: 'firefox',
  137. platform: 'linux'
  138. },
  139. {
  140. browserName: 'chrome',
  141. platform: 'linux'
  142. },
  143. {
  144. browserName: 'opera',
  145. version: '12',
  146. platform: 'linux'
  147. }
  148. ]
  149. }
  150. }
  151. },
  152. 'gh-pages': {
  153. options: {
  154. base: 'docs',
  155. branch: 'master',
  156. clone: 'node_modules/grunt-gh-pages/repo',
  157. message: 'Updated docs with master',
  158. push: true,
  159. repo: '[email protected]:select2/select2.github.io.git'
  160. },
  161. src: '**'
  162. },
  163. jekyll: {
  164. options: {
  165. src: 'docs',
  166. dest: 'docs/_site'
  167. },
  168. build: {
  169. d: null
  170. },
  171. serve: {
  172. options: {
  173. serve: true,
  174. watch: true
  175. }
  176. }
  177. },
  178. jshint: {
  179. options: {
  180. jshintrc: true
  181. },
  182. code: {
  183. src: ['src/js/**/*.js']
  184. },
  185. tests: {
  186. src: ['tests/**/*.js']
  187. }
  188. },
  189. sass: {
  190. dist: {
  191. options: {
  192. outputStyle: 'compressed'
  193. },
  194. files: {
  195. 'dist/css/select2.min.css': [
  196. 'src/scss/core.scss',
  197. 'src/scss/theme/default/layout.css'
  198. ]
  199. }
  200. },
  201. dev: {
  202. options: {
  203. outputStyle: 'nested'
  204. },
  205. files: {
  206. 'dist/css/select2.css': [
  207. 'src/scss/core.scss',
  208. 'src/scss/theme/default/layout.css'
  209. ]
  210. }
  211. }
  212. },
  213. symlink: {
  214. docs: {
  215. cwd: 'dist',
  216. expand: true,
  217. overwrite: false,
  218. src: [
  219. '*'
  220. ],
  221. dest: 'docs/dist',
  222. filter: 'isDirectory'
  223. }
  224. },
  225. requirejs: {
  226. 'dist': {
  227. options: {
  228. baseUrl: 'src/js',
  229. optimize: 'none',
  230. name: 'select2/core',
  231. out: 'dist/js/select2.js',
  232. include: includes,
  233. namespace: 'S2',
  234. paths: {
  235. 'almond': require.resolve('almond').slice(0, -3),
  236. 'jquery': 'jquery.shim',
  237. 'jquery-mousewheel': 'jquery.mousewheel.shim'
  238. },
  239. wrap: {
  240. startFile: 'src/js/banner.start.js',
  241. endFile: 'src/js/banner.end.js'
  242. }
  243. }
  244. },
  245. 'dist.full': {
  246. options: {
  247. baseUrl: 'src/js',
  248. optimize: 'none',
  249. name: 'select2/core',
  250. out: 'dist/js/select2.full.js',
  251. include: fullIncludes,
  252. namespace: 'S2',
  253. paths: {
  254. 'almond': require.resolve('almond').slice(0, -3),
  255. 'jquery': 'jquery.shim',
  256. 'jquery-mousewheel': require.resolve('jquery-mousewheel').slice(0, -3)
  257. },
  258. wrap: {
  259. startFile: 'src/js/banner.start.js',
  260. endFile: 'src/js/banner.end.js'
  261. }
  262. }
  263. },
  264. 'i18n': {
  265. options: {
  266. baseUrl: 'src/js/select2/i18n',
  267. dir: 'dist/js/i18n',
  268. paths: i18nPaths,
  269. modules: i18nModules,
  270. namespace: 'S2',
  271. wrap: {
  272. start: minifiedBanner + grunt.file.read('src/js/banner.start.js'),
  273. end: grunt.file.read('src/js/banner.end.js')
  274. }
  275. }
  276. }
  277. },
  278. watch: {
  279. js: {
  280. files: [
  281. 'src/js/select2/**/*.js',
  282. 'tests/**/*.js'
  283. ],
  284. tasks: [
  285. 'compile',
  286. 'test',
  287. 'minify'
  288. ]
  289. },
  290. css: {
  291. files: [
  292. 'src/scss/**/*.scss'
  293. ],
  294. tasks: [
  295. 'compile',
  296. 'minify'
  297. ]
  298. }
  299. }
  300. });
  301. grunt.loadNpmTasks('grunt-contrib-clean');
  302. grunt.loadNpmTasks('grunt-contrib-concat');
  303. grunt.loadNpmTasks('grunt-contrib-connect');
  304. grunt.loadNpmTasks('grunt-contrib-jshint');
  305. grunt.loadNpmTasks('grunt-contrib-qunit');
  306. grunt.loadNpmTasks('grunt-contrib-requirejs');
  307. grunt.loadNpmTasks('grunt-contrib-symlink');
  308. grunt.loadNpmTasks('grunt-contrib-uglify');
  309. grunt.loadNpmTasks('grunt-contrib-watch');
  310. grunt.loadNpmTasks('grunt-gh-pages');
  311. grunt.loadNpmTasks('grunt-jekyll');
  312. grunt.loadNpmTasks('grunt-saucelabs');
  313. grunt.loadNpmTasks('grunt-sass');
  314. grunt.registerTask('default', ['compile', 'test', 'minify']);
  315. grunt.registerTask('compile', [
  316. 'requirejs:dist', 'requirejs:dist.full', 'requirejs:i18n',
  317. 'concat:dist', 'concat:dist.full',
  318. 'sass:dev'
  319. ]);
  320. grunt.registerTask('minify', ['uglify', 'sass:dist']);
  321. grunt.registerTask('test', ['connect:tests', 'qunit', 'jshint']);
  322. var ciTasks = [];
  323. ciTasks.push('compile');
  324. ciTasks.push('connect:tests');
  325. // Can't run Sauce Labs tests in pull requests
  326. if (process.env.TRAVIS_PULL_REQUEST == 'false') {
  327. ciTasks.push('saucelabs-qunit');
  328. }
  329. ciTasks.push('qunit');
  330. ciTasks.push('jshint');
  331. grunt.registerTask('ci', ciTasks);
  332. grunt.registerTask('docs', ['symlink:docs', 'jekyll:serve']);
  333. grunt.registerTask('docs-release', ['default', 'clean:docs', 'gh-pages']);
  334. };