Gruntfile.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. concat: {
  48. 'dist': {
  49. options: {
  50. banner: grunt.file.read('src/js/wrapper.start.js'),
  51. },
  52. src: [
  53. 'dist/js/select2.js',
  54. 'src/js/wrapper.end.js'
  55. ],
  56. dest: 'dist/js/select2.js'
  57. },
  58. 'dist.full': {
  59. options: {
  60. banner: grunt.file.read('src/js/wrapper.start.js'),
  61. },
  62. src: [
  63. 'dist/js/select2.full.js',
  64. 'src/js/wrapper.end.js'
  65. ],
  66. dest: 'dist/js/select2.full.js'
  67. }
  68. },
  69. connect: {
  70. tests: {
  71. options: {
  72. base: '.',
  73. hostname: '127.0.0.1',
  74. port: 9999
  75. }
  76. }
  77. },
  78. uglify: {
  79. 'dist': {
  80. src: 'dist/js/select2.js',
  81. dest: 'dist/js/select2.min.js',
  82. options: {
  83. banner: minifiedBanner
  84. }
  85. },
  86. 'dist.full': {
  87. src: 'dist/js/select2.full.js',
  88. dest: 'dist/js/select2.full.min.js',
  89. options: {
  90. banner: minifiedBanner
  91. }
  92. }
  93. },
  94. qunit: {
  95. all: {
  96. options: {
  97. urls: testUrls
  98. }
  99. }
  100. },
  101. jshint: {
  102. options: {
  103. jshintrc: true,
  104. reporterOutput: ''
  105. },
  106. code: {
  107. src: ['src/js/**/*.js']
  108. },
  109. tests: {
  110. src: ['tests/**/*.js']
  111. }
  112. },
  113. sass: {
  114. dist: {
  115. options: {
  116. outputStyle: 'compressed'
  117. },
  118. files: {
  119. 'dist/css/select2.min.css': [
  120. 'src/scss/core.scss',
  121. 'src/scss/theme/default/layout.css'
  122. ]
  123. }
  124. },
  125. dev: {
  126. options: {
  127. outputStyle: 'nested'
  128. },
  129. files: {
  130. 'dist/css/select2.css': [
  131. 'src/scss/core.scss',
  132. 'src/scss/theme/default/layout.css'
  133. ]
  134. }
  135. }
  136. },
  137. requirejs: {
  138. 'dist': {
  139. options: {
  140. baseUrl: 'src/js',
  141. optimize: 'none',
  142. name: 'select2/core',
  143. out: 'dist/js/select2.js',
  144. include: includes,
  145. namespace: 'S2',
  146. paths: {
  147. 'almond': require.resolve('almond').slice(0, -3),
  148. 'jquery': 'jquery.shim',
  149. 'jquery-mousewheel': 'jquery.mousewheel.shim'
  150. },
  151. wrap: {
  152. startFile: 'src/js/banner.start.js',
  153. endFile: 'src/js/banner.end.js'
  154. }
  155. }
  156. },
  157. 'dist.full': {
  158. options: {
  159. baseUrl: 'src/js',
  160. optimize: 'none',
  161. name: 'select2/core',
  162. out: 'dist/js/select2.full.js',
  163. include: fullIncludes,
  164. namespace: 'S2',
  165. paths: {
  166. 'almond': require.resolve('almond').slice(0, -3),
  167. 'jquery': 'jquery.shim',
  168. 'jquery-mousewheel': require.resolve('jquery-mousewheel').slice(0, -3)
  169. },
  170. wrap: {
  171. startFile: 'src/js/banner.start.js',
  172. endFile: 'src/js/banner.end.js'
  173. }
  174. }
  175. },
  176. 'i18n': {
  177. options: {
  178. baseUrl: 'src/js/select2/i18n',
  179. dir: 'dist/js/i18n',
  180. paths: i18nPaths,
  181. modules: i18nModules,
  182. namespace: 'S2',
  183. wrap: {
  184. start: minifiedBanner + grunt.file.read('src/js/banner.start.js'),
  185. end: grunt.file.read('src/js/banner.end.js')
  186. }
  187. }
  188. }
  189. },
  190. watch: {
  191. js: {
  192. files: [
  193. 'src/js/select2/**/*.js',
  194. 'tests/**/*.js'
  195. ],
  196. tasks: [
  197. 'compile',
  198. 'test',
  199. 'minify'
  200. ]
  201. },
  202. css: {
  203. files: [
  204. 'src/scss/**/*.scss'
  205. ],
  206. tasks: [
  207. 'compile',
  208. 'minify'
  209. ]
  210. }
  211. }
  212. });
  213. grunt.loadNpmTasks('grunt-contrib-concat');
  214. grunt.loadNpmTasks('grunt-contrib-connect');
  215. grunt.loadNpmTasks('grunt-contrib-jshint');
  216. grunt.loadNpmTasks('grunt-contrib-qunit');
  217. grunt.loadNpmTasks('grunt-contrib-requirejs');
  218. grunt.loadNpmTasks('grunt-contrib-uglify');
  219. grunt.loadNpmTasks('grunt-contrib-watch');
  220. grunt.loadNpmTasks('grunt-sass');
  221. grunt.registerTask('default', ['compile', 'test', 'minify']);
  222. grunt.registerTask('compile', [
  223. 'requirejs:dist', 'requirejs:dist.full', 'requirejs:i18n',
  224. 'concat:dist', 'concat:dist.full',
  225. 'sass:dev'
  226. ]);
  227. grunt.registerTask('minify', ['uglify', 'sass:dist']);
  228. grunt.registerTask('test', ['connect:tests', 'qunit', 'jshint']);
  229. grunt.registerTask('ci', ['compile', 'test']);
  230. };