Gruntfile.js 8.2 KB

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