 coveralls  = require 'gulp-coveralls'
 run        = require 'gulp-run'
 coffee     = require 'gulp-coffee'
+istanbul   = require 'gulp-coffee-istanbul'
 browserify = require 'browserify'
 coffeeify  = require 'coffeeify'
 source     = require 'vinyl-source-stream'

SRC = './src/*.coffee'
TEST = './test/*_test.coffee'
LIBDIR = './lib'

gulp.task 'default', ->
  gulp.src SRC

gulp.task 'watch', [ 'build' ], ->
  gulp.watch [ './src/*' ] , [ 'build' ]

# this is also ugly but it works
gulp.task 'test', ->
  gulp.src SRC
    .pipe istanbul { includeUntested: true }
    .pipe istanbul.hookRequire()
    .on 'finish', ->
      gulp.src TEST, { read: false }
        .pipe mocha MOCHA_OPTS
        .on 'error', (e) ->
          if e.name is 'SyntaxError'
            gutil.log e.stack 
          else 
            gutil.log e.message
        .pipe istanbul.writeReports()
        .on 'end', ->
          gulp.src './coverage/lcov.info'
            .pipe coveralls()

#gulp.task 'browsers', ->
  #run "zuul -- #{TEST}", { silent: true }
  #  .exec()
    
gulp.task 'travis', [ 'test' ], ->

gulp.task 'testwatch', ['test' ], ->
  gulp.watch ['./src/*', './test/*'], ['test', 'default']
