Gruntfile.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. jasmine : {
  117. src : '<%= pkg.gruntConfig.temp.js %>',
  118. options : {
  119. specs : '<%= pkg.gruntConfig.spec %>',
  120. vendor : ['<%= pkg.gruntConfig.js.jquery %>', '<%= pkg.gruntConfig.js.popper %>', '<%= pkg.gruntConfig.js.bootstrap %>', '<%= pkg.gruntConfig.js.bindPolyfill %>'],
  121. styles : ['<%= pkg.gruntConfig.css.bootstrap %>', '<%= pkg.gruntConfig.temp.css %>'],
  122. template : '<%= pkg.gruntConfig.tpl.SpecRunner %>'
  123. }
  124. },
  125. template : {
  126. 'generate-index-page' : {
  127. options : {
  128. data : {
  129. js : {
  130. highlightjs: '<%= pkg.gruntConfig.js.highlightjs %>',
  131. modernizr : '<%= pkg.gruntConfig.js.modernizr %>',
  132. jquery : '<%= pkg.gruntConfig.js.jquery %>',
  133. popper : '<%= pkg.gruntConfig.js.popper %>',
  134. bootstrap : '<%= pkg.gruntConfig.js.bootstrap %>',
  135. slider : '<%= pkg.gruntConfig.temp.js %>'
  136. },
  137. css : {
  138. highlightjs: '<%= pkg.gruntConfig.css.highlightjs %>',
  139. bootstrap : '<%= pkg.gruntConfig.css.bootstrap %>',
  140. slider : '<%= pkg.gruntConfig.temp.css %>'
  141. }
  142. }
  143. },
  144. files : {
  145. 'index.html' : ['<%= pkg.gruntConfig.tpl.index %>']
  146. }
  147. },
  148. 'generate-gh-pages' : {
  149. options : {
  150. data : {
  151. js : {
  152. highlightjs: '<%= pkg.gruntConfig.js.ghpages.highlightjs %>',
  153. modernizr : '<%= pkg.gruntConfig.js.ghpages.modernizr %>',
  154. jquery : '<%= pkg.gruntConfig.js.ghpages.jquery %>',
  155. popper : '<%= pkg.gruntConfig.js.ghpages.popper %>',
  156. bootstrap : '<%= pkg.gruntConfig.js.ghpages.bootstrap %>',
  157. slider : 'js/bootstrap-slider.js'
  158. },
  159. css : {
  160. highlightjs: '<%= pkg.gruntConfig.css.highlightjs %>',
  161. bootstrap : 'css/bootstrap.min.css',
  162. slider : 'css/bootstrap-slider.css'
  163. }
  164. }
  165. },
  166. files : {
  167. 'index.html' : ['<%= pkg.gruntConfig.tpl.index %>']
  168. }
  169. }
  170. },
  171. watch: {
  172. options: {
  173. livereload: true
  174. },
  175. js: {
  176. files: '<%= pkg.gruntConfig.js.slider %>',
  177. tasks: ['jshint:js', 'babel', 'jasmine']
  178. },
  179. gruntfile: {
  180. files: '<%= jshint.gruntfile %>',
  181. tasks: ['jshint:gruntfile']
  182. },
  183. spec: {
  184. files: '<%= pkg.gruntConfig.spec %>',
  185. tasks: ['jshint:spec', 'jasmine:src']
  186. },
  187. css: {
  188. files: [
  189. '<%= pkg.gruntConfig.sass.slider %>',
  190. '<%= pkg.gruntConfig.sass.variables %>',
  191. '<%= pkg.gruntConfig.sass.mixins %>',
  192. '<%= pkg.gruntConfig.sass.rules %>'
  193. ],
  194. tasks: ['sass:development']
  195. },
  196. index: {
  197. files: '<%= pkg.gruntConfig.tpl.index %>',
  198. tasks: ['template:generate-index-page']
  199. }
  200. },
  201. connect: {
  202. server: {
  203. options: {
  204. port: "<%= pkg.gruntConfig.devPort %>"
  205. }
  206. }
  207. },
  208. open : {
  209. development : {
  210. path: 'http://localhost:<%= connect.server.options.port %>'
  211. }
  212. },
  213. sass: {
  214. development: {
  215. options: {
  216. sourceMap: true,
  217. outputStyle: 'expanded'
  218. },
  219. files: {
  220. '<%= pkg.gruntConfig.temp.css %>': '<%= pkg.gruntConfig.sass.slider %>'
  221. }
  222. },
  223. production: {
  224. options: {
  225. sourceMap: true,
  226. outputStyle: 'expanded'
  227. },
  228. files: {
  229. '<%= pkg.gruntConfig.temp.css %>': '<%= pkg.gruntConfig.sass.slider %>'
  230. }
  231. },
  232. "production-min": {
  233. options: {
  234. sourceMap: true,
  235. outputStyle: 'compressed'
  236. },
  237. files: {
  238. '<%= pkg.gruntConfig.temp.cssMin %>': '<%= pkg.gruntConfig.sass.slider %>'
  239. }
  240. }
  241. },
  242. clean: {
  243. dist: ["dist"],
  244. temp: ["temp"]
  245. },
  246. bump: {
  247. options: {
  248. files: bumpFiles,
  249. updateConfigs: [],
  250. commit: true,
  251. commitMessage: 'Release v%VERSION%',
  252. commitFiles: commitFiles,
  253. createTag: true,
  254. tagName: 'v%VERSION%',
  255. tagMessage: 'Version %VERSION%',
  256. push: false,
  257. pushTo: 'origin'
  258. }
  259. }
  260. });
  261. // These plugins provide necessary tasks.
  262. grunt.loadNpmTasks('grunt-contrib-uglify');
  263. grunt.loadNpmTasks('grunt-contrib-jshint');
  264. grunt.loadNpmTasks('grunt-contrib-jasmine');
  265. grunt.loadNpmTasks('grunt-contrib-watch');
  266. grunt.loadNpmTasks('grunt-contrib-connect');
  267. grunt.loadNpmTasks('grunt-contrib-clean');
  268. grunt.loadNpmTasks('grunt-sass');
  269. grunt.loadNpmTasks('grunt-open');
  270. grunt.loadNpmTasks('grunt-template');
  271. grunt.loadNpmTasks('grunt-header');
  272. grunt.loadNpmTasks('grunt-bump');
  273. grunt.loadNpmTasks('grunt-babel');
  274. grunt.loadNpmTasks('grunt-sass-lint');
  275. // Create custom tasks
  276. grunt.registerTask('append-header', ['header', 'clean:temp']);
  277. grunt.registerTask('lint', [
  278. 'jshint',
  279. 'sasslint'
  280. ]);
  281. grunt.registerTask('test', [
  282. 'babel',
  283. 'sass:development',
  284. 'jasmine',
  285. 'clean:temp'
  286. ]);
  287. grunt.registerTask('build', [
  288. 'sass:development',
  289. 'test',
  290. 'template:generate-index-page'
  291. ]);
  292. grunt.registerTask('build-gh-pages', [
  293. 'sass:development',
  294. 'babel',
  295. 'template:generate-gh-pages'
  296. ]);
  297. grunt.registerTask('dist', [
  298. 'clean:dist',
  299. 'sass:production',
  300. 'sass:production-min',
  301. 'babel',
  302. 'uglify',
  303. 'append-header'
  304. ]);
  305. grunt.registerTask('development', [
  306. 'sass:development',
  307. 'babel',
  308. 'template:generate-index-page',
  309. 'connect',
  310. 'open:development',
  311. 'watch'
  312. ]);
  313. grunt.registerTask('production', ['dist']);
  314. grunt.registerTask('dev', 'development');
  315. grunt.registerTask('prod', 'production');
  316. grunt.registerTask('default', ['build']);
  317. }; // End of module