Gruntfile.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. const sass = require('node-sass');
  2. module.exports = function (grunt) {
  3. // Full list of files that must be included by RequireJS
  4. includes = [
  5. 'jquery.select2',
  6. 'almond',
  7. 'jquery-mousewheel' // shimmed for non-full builds
  8. ];
  9. fullIncludes = [
  10. 'jquery',
  11. 'select2/dropdown/attachContainer',
  12. 'select2/dropdown/stopPropagation',
  13. 'select2/selection/stopPropagation'
  14. ].concat(includes);
  15. var i18nModules = [];
  16. var i18nPaths = {};
  17. var i18nFiles = grunt.file.expand({
  18. cwd: 'src/js'
  19. }, 'select2/i18n/*.js');
  20. var testFiles = grunt.file.expand('tests/**/*.html');
  21. var testUrls = testFiles.map(function (filePath) {
  22. return 'http://localhost:9999/' + filePath;
  23. });
  24. var testBuildNumber = "unknown";
  25. if (process.env.TRAVIS_JOB_ID) {
  26. testBuildNumber = "travis-" + process.env.TRAVIS_JOB_ID;
  27. } else {
  28. var currentTime = new Date();
  29. testBuildNumber = "manual-" + currentTime.getTime();
  30. }
  31. for (var i = 0; i < i18nFiles.length; i++) {
  32. var file = i18nFiles[i];
  33. var name = file.split('.')[0];
  34. i18nModules.push({
  35. name: name
  36. });
  37. i18nPaths[name] = '../../' + name;
  38. }
  39. var minifiedBanner = '/*! Select2 <%= package.version %> | https://github.com/select2/select2/blob/master/LICENSE.md */';
  40. grunt.initConfig({
  41. package: grunt.file.readJSON('package.json'),
  42. concat: {
  43. 'dist': {
  44. options: {
  45. banner: grunt.file.read('src/js/wrapper.start.js'),
  46. },
  47. src: [
  48. 'dist/js/select2.js',
  49. 'src/js/wrapper.end.js'
  50. ],
  51. dest: 'dist/js/select2.js'
  52. },
  53. 'dist.full': {
  54. options: {
  55. banner: grunt.file.read('src/js/wrapper.start.js'),
  56. },
  57. src: [
  58. 'dist/js/select2.full.js',
  59. 'src/js/wrapper.end.js'
  60. ],
  61. dest: 'dist/js/select2.full.js'
  62. }
  63. },
  64. connect: {
  65. tests: {
  66. options: {
  67. base: '.',
  68. hostname: '127.0.0.1',
  69. port: 9999
  70. }
  71. }
  72. },
  73. uglify: {
  74. 'dist': {
  75. src: 'dist/js/select2.js',
  76. dest: 'dist/js/select2.min.js',
  77. options: {
  78. banner: minifiedBanner
  79. }
  80. },
  81. 'dist.full': {
  82. src: 'dist/js/select2.full.js',
  83. dest: 'dist/js/select2.full.min.js',
  84. options: {
  85. banner: minifiedBanner
  86. }
  87. }
  88. },
  89. qunit: {
  90. all: {
  91. options: {
  92. urls: testUrls
  93. }
  94. }
  95. },
  96. jshint: {
  97. options: {
  98. jshintrc: true,
  99. reporterOutput: ''
  100. },
  101. code: {
  102. src: ['src/js/**/*.js']
  103. },
  104. tests: {
  105. src: ['tests/**/*.js']
  106. }
  107. },
  108. sass: {
  109. dist: {
  110. options: {
  111. implementation: sass,
  112. outputStyle: 'compressed'
  113. },
  114. files: {
  115. 'dist/css/select2.min.css': [
  116. 'src/scss/core.scss',
  117. 'src/scss/theme/default/layout.css'
  118. ]
  119. }
  120. },
  121. dev: {
  122. options: {
  123. implementation: sass,
  124. outputStyle: 'nested'
  125. },
  126. files: {
  127. 'dist/css/select2.css': [
  128. 'src/scss/core.scss',
  129. 'src/scss/theme/default/layout.css'
  130. ]
  131. }
  132. }
  133. },
  134. requirejs: {
  135. 'dist': {
  136. options: {
  137. baseUrl: 'src/js',
  138. optimize: 'none',
  139. name: 'select2/core',
  140. out: 'dist/js/select2.js',
  141. include: includes,
  142. namespace: 'S2',
  143. paths: {
  144. 'almond': require.resolve('almond').slice(0, -3),
  145. 'jquery': 'jquery.shim',
  146. 'jquery-mousewheel': 'jquery.mousewheel.shim'
  147. },
  148. wrap: {
  149. startFile: 'src/js/banner.start.js',
  150. endFile: 'src/js/banner.end.js'
  151. }
  152. }
  153. },
  154. 'dist.full': {
  155. options: {
  156. baseUrl: 'src/js',
  157. optimize: 'none',
  158. name: 'select2/core',
  159. out: 'dist/js/select2.full.js',
  160. include: fullIncludes,
  161. namespace: 'S2',
  162. paths: {
  163. 'almond': require.resolve('almond').slice(0, -3),
  164. 'jquery': 'jquery.shim',
  165. 'jquery-mousewheel': require.resolve('jquery-mousewheel').slice(0, -3)
  166. },
  167. wrap: {
  168. startFile: 'src/js/banner.start.js',
  169. endFile: 'src/js/banner.end.js'
  170. }
  171. }
  172. },
  173. 'i18n': {
  174. options: {
  175. baseUrl: 'src/js/select2/i18n',
  176. dir: 'dist/js/i18n',
  177. paths: i18nPaths,
  178. modules: i18nModules,
  179. namespace: 'S2',
  180. wrap: {
  181. start: minifiedBanner + grunt.file.read('src/js/banner.start.js'),
  182. end: grunt.file.read('src/js/banner.end.js')
  183. }
  184. }
  185. }
  186. },
  187. watch: {
  188. js: {
  189. files: [
  190. 'src/js/select2/**/*.js',
  191. 'tests/**/*.js'
  192. ],
  193. tasks: [
  194. 'compile',
  195. 'test',
  196. 'minify'
  197. ]
  198. },
  199. css: {
  200. files: [
  201. 'src/scss/**/*.scss'
  202. ],
  203. tasks: [
  204. 'compile',
  205. 'minify'
  206. ]
  207. }
  208. }
  209. });
  210. grunt.loadNpmTasks('grunt-contrib-concat');
  211. grunt.loadNpmTasks('grunt-contrib-connect');
  212. grunt.loadNpmTasks('grunt-contrib-jshint');
  213. grunt.loadNpmTasks('grunt-contrib-qunit');
  214. grunt.loadNpmTasks('grunt-contrib-requirejs');
  215. grunt.loadNpmTasks('grunt-contrib-uglify');
  216. grunt.loadNpmTasks('grunt-contrib-watch');
  217. grunt.loadNpmTasks('grunt-sass');
  218. grunt.registerTask('default', ['compile', 'test', 'lint', 'minify']);
  219. grunt.registerTask('compile', [
  220. 'requirejs:dist', 'requirejs:dist.full', 'requirejs:i18n',
  221. 'concat:dist', 'concat:dist.full',
  222. 'sass:dev'
  223. ]);
  224. grunt.registerTask('minify', ['uglify', 'sass:dist']);
  225. grunt.registerTask('lint', ['jshint']);
  226. grunt.registerTask('test', ['connect:tests', 'qunit']);
  227. };