No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Gruntfile.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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/compat/containerCss',
  12. 'select2/compat/dropdownCss',
  13. 'select2/compat/initSelection',
  14. 'select2/compat/inputData',
  15. 'select2/compat/matcher',
  16. 'select2/compat/query',
  17. 'select2/dropdown/attachContainer',
  18. 'select2/dropdown/stopPropagation',
  19. 'select2/selection/stopPropagation'
  20. ].concat(includes);
  21. var i18nModules = [];
  22. var i18nPaths = {};
  23. var i18nFiles = grunt.file.expand({
  24. cwd: 'src/js'
  25. }, 'select2/i18n/*.js');
  26. var testFiles = grunt.file.expand('tests/**/*.html');
  27. var testUrls = testFiles.map(function (filePath) {
  28. return 'http://localhost:9999/' + filePath;
  29. });
  30. var testBuildNumber = "unknown";
  31. if (process.env.TRAVIS_JOB_ID) {
  32. testBuildNumber = "travis-" + process.env.TRAVIS_JOB_ID;
  33. } else {
  34. var currentTime = new Date();
  35. testBuildNumber = "manual-" + currentTime.getTime();
  36. }
  37. for (var i = 0; i < i18nFiles.length; i++) {
  38. var file = i18nFiles[i];
  39. var name = file.split('.')[0];
  40. i18nModules.push({
  41. name: name
  42. });
  43. i18nPaths[name] = '../../' + name;
  44. }
  45. var minifiedBanner = '/*! Select2 <%= package.version %> | https://github.com/select2/select2/blob/master/LICENSE.md */';
  46. grunt.initConfig({
  47. package: grunt.file.readJSON('package.json'),
  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. jshint: {
  103. options: {
  104. jshintrc: true,
  105. reporterOutput: ''
  106. },
  107. code: {
  108. src: ['src/js/**/*.js']
  109. },
  110. tests: {
  111. src: ['tests/**/*.js']
  112. }
  113. },
  114. sass: {
  115. dist: {
  116. options: {
  117. implementation: sass,
  118. outputStyle: 'compressed'
  119. },
  120. files: {
  121. 'dist/css/select2.min.css': [
  122. 'src/scss/core.scss',
  123. 'src/scss/theme/default/layout.css'
  124. ]
  125. }
  126. },
  127. dev: {
  128. options: {
  129. implementation: sass,
  130. outputStyle: 'nested'
  131. },
  132. files: {
  133. 'dist/css/select2.css': [
  134. 'src/scss/core.scss',
  135. 'src/scss/theme/default/layout.css'
  136. ]
  137. }
  138. }
  139. },
  140. requirejs: {
  141. 'dist': {
  142. options: {
  143. baseUrl: 'src/js',
  144. optimize: 'none',
  145. name: 'select2/core',
  146. out: 'dist/js/select2.js',
  147. include: includes,
  148. namespace: 'S2',
  149. paths: {
  150. 'almond': require.resolve('almond').slice(0, -3),
  151. 'jquery': 'jquery.shim',
  152. 'jquery-mousewheel': 'jquery.mousewheel.shim'
  153. },
  154. wrap: {
  155. startFile: 'src/js/banner.start.js',
  156. endFile: 'src/js/banner.end.js'
  157. }
  158. }
  159. },
  160. 'dist.full': {
  161. options: {
  162. baseUrl: 'src/js',
  163. optimize: 'none',
  164. name: 'select2/core',
  165. out: 'dist/js/select2.full.js',
  166. include: fullIncludes,
  167. namespace: 'S2',
  168. paths: {
  169. 'almond': require.resolve('almond').slice(0, -3),
  170. 'jquery': 'jquery.shim',
  171. 'jquery-mousewheel': require.resolve('jquery-mousewheel').slice(0, -3)
  172. },
  173. wrap: {
  174. startFile: 'src/js/banner.start.js',
  175. endFile: 'src/js/banner.end.js'
  176. }
  177. }
  178. },
  179. 'i18n': {
  180. options: {
  181. baseUrl: 'src/js/select2/i18n',
  182. dir: 'dist/js/i18n',
  183. paths: i18nPaths,
  184. modules: i18nModules,
  185. namespace: 'S2',
  186. wrap: {
  187. start: minifiedBanner + grunt.file.read('src/js/banner.start.js'),
  188. end: grunt.file.read('src/js/banner.end.js')
  189. }
  190. }
  191. }
  192. },
  193. watch: {
  194. js: {
  195. files: [
  196. 'src/js/select2/**/*.js',
  197. 'tests/**/*.js'
  198. ],
  199. tasks: [
  200. 'compile',
  201. 'test',
  202. 'minify'
  203. ]
  204. },
  205. css: {
  206. files: [
  207. 'src/scss/**/*.scss'
  208. ],
  209. tasks: [
  210. 'compile',
  211. 'minify'
  212. ]
  213. }
  214. }
  215. });
  216. grunt.loadNpmTasks('grunt-contrib-concat');
  217. grunt.loadNpmTasks('grunt-contrib-connect');
  218. grunt.loadNpmTasks('grunt-contrib-jshint');
  219. grunt.loadNpmTasks('grunt-contrib-qunit');
  220. grunt.loadNpmTasks('grunt-contrib-requirejs');
  221. grunt.loadNpmTasks('grunt-contrib-uglify');
  222. grunt.loadNpmTasks('grunt-contrib-watch');
  223. grunt.loadNpmTasks('grunt-sass');
  224. grunt.registerTask('default', ['compile', 'test', 'lint', 'minify']);
  225. grunt.registerTask('compile', [
  226. 'requirejs:dist', 'requirejs:dist.full', 'requirejs:i18n',
  227. 'concat:dist', 'concat:dist.full',
  228. 'sass:dev'
  229. ]);
  230. grunt.registerTask('minify', ['uglify', 'sass:dist']);
  231. grunt.registerTask('lint', ['jshint']);
  232. grunt.registerTask('test', ['connect:tests', 'qunit']);
  233. };