/gulpfile.js

https://github.com/ajanthanm/colors · JavaScript · 112 lines · 20 code · 6 blank · 86 comment · 0 complexity · 4b1d66974a2022538c402f389c4d5f64 MD5 · raw file

  1. // Load plugins
  2. var gulp = require('gulp'),
  3. gutil = require('gulp-util'),
  4. watch = require('gulp-watch'),
  5. prefix = require('gulp-autoprefixer'),
  6. minifyCSS = require('gulp-minify-css'),
  7. sass = require('gulp-sass'),
  8. myth = require('gulp-myth'),
  9. stylus = require('gulp-stylus'),
  10. rename = require('gulp-rename'),
  11. size = require('gulp-size'),
  12. csslint = require('gulp-csslint')
  13. browserSync = require('browser-sync'),
  14. browserReload = browserSync.reload;
  15. // Use csslint without box-sizing or compatible vendor prefixes (these
  16. // don't seem to be kept up to date on what to yell about)
  17. gulp.task('lint', function(){
  18. gulp.src('./css/*.css')
  19. .pipe(csslint({
  20. 'compatible-vendor-prefixes': false,
  21. 'box-sizing': false
  22. }))
  23. .pipe(csslint.reporter());
  24. });
  25. // Task that compiles scss files down to good old css
  26. gulp.task('sass', function(){
  27. gulp.src('./sass/colors.scss')
  28. .pipe(watch(function(files) {
  29. return files.pipe(sass())
  30. .pipe(prefix())
  31. .pipe(size({gzip: true, showFiles: true, title:'unminified colors.css'}))
  32. .pipe(gulp.dest('css'))
  33. .pipe(browserSync.reload({stream:true}));
  34. }));
  35. });
  36. // Task to minify colors.css then rename as colors.min.css
  37. gulp.task('minify', function(){
  38. gulp.src('./css/colors.css')
  39. .pipe(minifyCSS())
  40. .pipe(size({gzip: true, showFiles: true, title:'minified colors.css'}))
  41. .pipe(rename('colors.min.css'))
  42. .pipe(gulp.dest('./css/'));
  43. });
  44. // Task that compiles css using the myth processor
  45. gulp.task('myth', function(){
  46. gulp.src('./myth/*.css')
  47. .pipe(watch(function(files) {
  48. return files.pipe(myth())
  49. .pipe(prefix())
  50. .pipe(gulp.dest('./css/'));
  51. }));
  52. });
  53. // Just runs autoprefixer on the compiled css
  54. gulp.task('prefix', function(){
  55. gulp.src('./css/*.css')
  56. .pipe(prefix())
  57. .pipe(gulp.dest('./css/'));
  58. });
  59. gulp.task('stylus', function(){
  60. gulp.src('./stylus/colors.styl')
  61. .pipe(watch(function(files) {
  62. return files.pipe(stylus())
  63. .pipe(prefix())
  64. .pipe(gulp.dest('./css/'));
  65. }));
  66. });
  67. // Initialize browser-sync which starts a static server also allows for
  68. // browsers to reload on filesave
  69. gulp.task('browser-sync', function() {
  70. browserSync.init(null, {
  71. server: {
  72. baseDir: "./"
  73. }
  74. });
  75. });
  76. gulp.task('bs-reload', function () {
  77. browserSync.reload();
  78. });
  79. /*
  80. DEFAULT TASK
  81. • Process sass and lints outputted css
  82. • Outputted css is run through autoprefixer
  83. • Runs jshint on all js files in ./js/
  84. • Sends updates to any files in directory to browser for
  85. automatic reloading
  86. */
  87. gulp.task('default', function(){
  88. gulp.watch(['./sass/colors.scss'], function(event) {
  89. gulp.run('sass', 'lint');
  90. });
  91. });