 
 err = (x...) -> gutil.log(x...); gutil.beep(x...)
 
-webpack = (name, ext, failhard) ->
+webpack = (name, ext, watch) ->
   options =
 #    bail: true
-#    cache: true
-#    watch: true
+    watch: watch
+    cache: true
     devtool: "source-map"
     output:
       filename: "#{name}.js"


gulp.task 'build', ['clean', 'copy', 'css', 'js']

gulp.task 'build-dev', ['clean', 'copy', 'css', 'js-dev']

gulp.task 'server', -> require('./app/js/server.coffee')

server_main = "#{src_path}/server.coffee"

gulp.task 'dev', ['build-dev', 'watch'], ->
  nodemon
    script: server_main
    watch: [server_main]
    env:
      PORT: process.env.PORT or 3000

gulp.task 'default', ['dev']

gulp.task 'watch', ->
  livereload.listen()
  gulp.watch(["#{dist_path}/**"]).on('change', livereload.changed)
  gulp.watch ["#{src_path}/**/*.coffee", "#{src_path}/**/*.cjsx", "#{src_path}/**/*.js"], ['js-dev']
  gulp.watch ["#{src_path}/**/*.less"], ['css']
  gulp.watch ["#{src_path}/**/*.html"], ['copy']

  .pipe(gulp.dest(dist_path))


js = (watch) -> webpack("client", "cjsx", watch)

gulp.task 'js', -> js(false)

gulp.task 'js-dev', -> js(true)

gulp.task 'css', ->
  gulp.src("#{src_path}/styles.less")
