Gruntfile.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*global module:false*/
  2. module.exports = function(grunt) {
  3. var packageJSON = grunt.file.readJSON('package.json');
  4. var bumpFiles = ["package.json", "bower.json", "composer.json"];
  5. var commitFiles = bumpFiles.concat(["./dist/*"]);
  6. // Project configuration.
  7. grunt.initConfig({
  8. // Metadata
  9. pkg: packageJSON,
  10. // Task configuration.
  11. header: {
  12. dist: {
  13. options: {
  14. text: "/*! =======================================================\n VERSION <%= pkg.version %> \n========================================================= */"
  15. },
  16. files: {
  17. '<%= pkg.gruntConfig.dist.js %>': '<%= pkg.gruntConfig.temp.js %>',
  18. '<%= pkg.gruntConfig.dist.jsMin %>': '<%= pkg.gruntConfig.temp.jsMin %>',
  19. '<%= pkg.gruntConfig.dist.css %>': '<%= pkg.gruntConfig.temp.css %>',
  20. '<%= pkg.gruntConfig.dist.cssMin %>': '<%= pkg.gruntConfig.temp.cssMin %>'
  21. }
  22. }
  23. },
  24. uglify: {
  25. options: {
  26. preserveComments: 'some'
  27. },
  28. dist: {
  29. src: '<%= pkg.gruntConfig.temp.js %>',
  30. dest: '<%= pkg.gruntConfig.temp.jsMin %>'
  31. }
  32. },
  33. babel: {
  34. options: {
  35. presets: ['es2015']
  36. },
  37. dist: {
  38. src: '<%= pkg.gruntConfig.js.slider %>',
  39. dest: '<%= pkg.gruntConfig.temp.js %>'
  40. }
  41. },
  42. jshint: {
  43. ignore_warning: {
  44. options: {
  45. '-W099': true
  46. },
  47. src: '<%= pkg.gruntConfig.js.slider %>'
  48. },
  49. options: {
  50. esnext: true,
  51. curly: true,
  52. eqeqeq: true,
  53. immed: true,
  54. latedef: false,
  55. newcap: true,
  56. noarg: true,
  57. sub: true,
  58. undef: true,
  59. unused: true,
  60. boss: true,
  61. eqnull: true,
  62. browser: true,
  63. globals: {
  64. $ : true,
  65. Modernizr : true,
  66. console: true,
  67. define: true,
  68. module: true,
  69. require: true
  70. },
  71. "-W099": true
  72. },
  73. gruntfile: {
  74. src: 'Gruntfile.js'
  75. },
  76. js: {
  77. src: '<%= pkg.gruntConfig.js.slider %>'
  78. },
  79. spec : {
  80. src: '<%= pkg.gruntConfig.spec %>',
  81. options : {
  82. globals : {
  83. document: true,
  84. console: false,
  85. Slider: false,
  86. $: false,
  87. jQuery: false,
  88. _: false,
  89. _V_: false,
  90. afterEach: false,
  91. beforeEach: false,
  92. confirm: false,
  93. context: false,
  94. describe: false,
  95. expect: false,
  96. it: false,
  97. jasmine: false,
  98. JSHINT: false,
  99. mostRecentAjaxRequest: false,
  100. qq: false,
  101. runs: false,
  102. spyOn: false,
  103. spyOnEvent: false,
  104. waitsFor: false,
  105. xdescribe: false
  106. }
  107. }
  108. }
  109. },
  110. sasslint: {
  111. options: {
  112. configFile: './.sass-lint.yml',
  113. },
  114. target: ['./src/sass/**/*.scss']
  115. },
  116. lesslint: {
  117. src: ['./src/less/bootstrap-slider.less']
  118. },
  119. jasmine : {
  120. src : '<%= pkg.gruntConfig.temp.js %>',
  121. options : {
  122. specs : '<%= pkg.gruntConfig.spec %>',
  123. vendor : ['<%= pkg.gruntConfig.js.jquery %>', '<%= pkg.gruntConfig.js.bindPolyfill %>'],
  124. styles : ['<%= pkg.gruntConfig.css.bootstrap %>', '<%= pkg.gruntConfig.temp.css %>'],
  125. template : '<%= pkg.gruntConfig.tpl.SpecRunner %>'
  126. }
  127. },
  128. template : {
  129. 'generate-index-page' : {
  130. options : {
  131. data : {
  132. js : {
  133. highlightjs: '<%= pkg.gruntConfig.js.highlightjs %>',
  134. modernizr : '<%= pkg.gruntConfig.js.modernizr %>',
  135. jquery : '<%= pkg.gruntConfig.js.jquery %>',
  136. slider : '<%= pkg.gruntConfig.temp.js %>'
  137. },
  138. css : {
  139. highlightjs: '<%= pkg.gruntConfig.css.highlightjs %>',
  140. bootstrap : '<%= pkg.gruntConfig.css.bootstrap %>',
  141. slider : '<%= pkg.gruntConfig.temp.css %>'
  142. }
  143. }
  144. },
  145. files : {
  146. 'index.html' : ['<%= pkg.gruntConfig.tpl.index %>']
  147. }
  148. },
  149. 'generate-gh-pages' : {
  150. options : {
  151. data : {
  152. js : {
  153. highlightjs: '<%= pkg.gruntConfig.js.highlightjs %>',
  154. modernizr : '<%= pkg.gruntConfig.js.modernizr %>',
  155. jquery : '<%= pkg.gruntConfig.js.jquery %>',
  156. slider : 'js/bootstrap-slider.js'
  157. },
  158. css : {
  159. highlightjs: '<%= pkg.gruntConfig.css.highlightjs %>',
  160. bootstrap : 'css/bootstrap.min.css',
  161. slider : 'css/bootstrap-slider.css'
  162. }
  163. }
  164. },
  165. files : {
  166. 'index.html' : ['<%= pkg.gruntConfig.tpl.index %>']
  167. }
  168. }
  169. },
  170. watch: {
  171. options: {
  172. livereload: true
  173. },
  174. js: {
  175. files: '<%= pkg.gruntConfig.js.slider %>',
  176. tasks: ['jshint:js', 'babel', 'jasmine']
  177. },
  178. gruntfile: {
  179. files: '<%= jshint.gruntfile %>',
  180. tasks: ['jshint:gruntfile']
  181. },
  182. spec: {
  183. files: '<%= pkg.gruntConfig.spec %>',
  184. tasks: ['jshint:spec', 'jasmine:src']
  185. },
  186. css: {
  187. files: [
  188. '<%= pkg.gruntConfig.less.slider %>',
  189. '<%= pkg.gruntConfig.less.rules %>',
  190. '<%= pkg.gruntConfig.less.variables %>'
  191. ],
  192. tasks: ['less:development']
  193. },
  194. index: {
  195. files: '<%= pkg.gruntConfig.tpl.index %>',
  196. tasks: ['template:generate-index-page']
  197. }
  198. },
  199. connect: {
  200. server: {
  201. options: {
  202. port: "<%= pkg.gruntConfig.devPort %>"
  203. }
  204. }
  205. },
  206. open : {
  207. development : {
  208. path: 'http://localhost:<%= connect.server.options.port %>'
  209. }
  210. },
  211. less: {
  212. options: {
  213. paths: ["bower_components/bootstrap/less"]
  214. },
  215. development: {
  216. files: {
  217. '<%= pkg.gruntConfig.temp.css %>': '<%= pkg.gruntConfig.less.slider %>'
  218. }
  219. },
  220. production: {
  221. files: {
  222. '<%= pkg.gruntConfig.temp.css %>': '<%= pkg.gruntConfig.less.slider %>',
  223. }
  224. },
  225. "production-min": {
  226. options: {
  227. yuicompress: true
  228. },
  229. files: {
  230. '<%= pkg.gruntConfig.temp.cssMin %>': '<%= pkg.gruntConfig.less.slider %>'
  231. }
  232. }
  233. },
  234. clean: {
  235. dist: ["dist"],
  236. temp: ["temp"]
  237. },
  238. bump: {
  239. options: {
  240. files: bumpFiles,
  241. updateConfigs: [],
  242. commit: true,
  243. commitMessage: 'Release v%VERSION%',
  244. commitFiles: commitFiles,
  245. createTag: true,
  246. tagName: 'v%VERSION%',
  247. tagMessage: 'Version %VERSION%',
  248. push: false,
  249. pushTo: 'origin'
  250. }
  251. }
  252. });
  253. // These plugins provide necessary tasks.
  254. grunt.loadNpmTasks('grunt-contrib-uglify');
  255. grunt.loadNpmTasks('grunt-contrib-jshint');
  256. grunt.loadNpmTasks('grunt-contrib-jasmine');
  257. grunt.loadNpmTasks('grunt-contrib-watch');
  258. grunt.loadNpmTasks('grunt-contrib-connect');
  259. grunt.loadNpmTasks('grunt-contrib-clean');
  260. grunt.loadNpmTasks('grunt-contrib-less');
  261. grunt.loadNpmTasks('grunt-open');
  262. grunt.loadNpmTasks('grunt-template');
  263. grunt.loadNpmTasks('grunt-header');
  264. grunt.loadNpmTasks('grunt-bump');
  265. grunt.loadNpmTasks('grunt-babel');
  266. grunt.loadNpmTasks('grunt-sass-lint');
  267. grunt.loadNpmTasks('grunt-lesslint');
  268. // Create custom tasks
  269. grunt.registerTask('append-header', ['header', 'clean:temp']);
  270. grunt.registerTask('lint', [
  271. 'jshint',
  272. 'lesslint',
  273. 'sasslint'
  274. ]);
  275. grunt.registerTask('test', [
  276. 'babel',
  277. 'less:development',
  278. 'jasmine',
  279. 'clean:temp'
  280. ]);
  281. grunt.registerTask('build', [
  282. 'less:development',
  283. 'test',
  284. 'template:generate-index-page'
  285. ]);
  286. grunt.registerTask('build-gh-pages', [
  287. 'less:development',
  288. 'babel',
  289. 'template:generate-gh-pages'
  290. ]);
  291. grunt.registerTask('dist', [
  292. 'clean:dist',
  293. 'less:production',
  294. 'less:production-min',
  295. 'babel',
  296. 'uglify',
  297. 'append-header'
  298. ]);
  299. grunt.registerTask('development', [
  300. 'less:development',
  301. 'babel',
  302. 'template:generate-index-page',
  303. 'connect',
  304. 'open:development',
  305. 'watch'
  306. ]);
  307. grunt.registerTask('production', ['dist']);
  308. grunt.registerTask('dev', 'development');
  309. grunt.registerTask('prod', 'production');
  310. grunt.registerTask('default', ['build']);
  311. }; // End of module