Gruntfile.js 8.5 KB

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