Gruntfile.js 7.9 KB

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