 gzip = require('gulp-gzip')
 
 watchReporter = (e)->
-  util.log("File #{util.colors.cyan(e.path)} was #{util.colors.red(e.type)}, compiling 💪")
+  util.log("File #{util.colors.cyan(e.path)} was #{util.colors.red(e.type)}, flexing 💪")
+errorReporter = (e)->
+  stack = e.stack or e
+  util.log("#{util.colors.magenta('Browserify error!')}\n#{util.colors.red(stack)}")
 
 compileJavascripts = (src, options)->
   args = [src, extensions: ['.coffee', '.jade']]
   bundler = if options.watch then watchify(args...) else browserify(args...)
 
-  compile = ->
+  compile = (files)->
+    watchReporter(path: files[0], type: 'changed') if files
     bundler.bundle()
-      # .pipe(plumber(util.log))
+      .on('error', errorReporter)
       .pipe(source(options.name))
       .pipe(gulp.dest(options.dest))
 
   bundler.on('update', compile) if options.watch
+  bundler.on('file', (file)-> util.log("Browserifying #{util.colors.cyan(file)}"))
   compile()
 
 compileStylesheets = (src, options)->

    dest: './public/assets'
    watch: true

  javascripts = [
    './app/javascripts/client/**/*.coffee'
    './app/javascripts/shared/**/*.coffee'
    './vendor/**/*.js'
    './vendor/**/*.coffee'
    './app/templates/client/**/*.jade'
    './app/templates/shared/**/*.jade'
  ]
  gulp.watch(javascripts).on('change', watchReporter)

  stylesheets = [
    './app/stylesheets/**/*.styl'
    './vendor/**/*.css'
    './vendor/**/*.styl'
    '!./app/stylesheets/static.styl'
  ]
  gulp.watch(stylesheets, ['stylus']).on('change', watchReporter)

  templates = [
    './app/stylesheets/static.styl'
    './app/templates/static/**/*.jade'
  ]
  gulp.watch(templates, ['static']).on('change', watchReporter)


gulp.task('default', ['browserify', 'stylus'])
gulp.task('build', ['compress'])

    .pipe(gulp.dest(options.dest))


gulp.task 'clean', ->
  gulp.src('./public/assets', read: false)
    .pipe(clean())
