 outapp = './Yakayak.app/Contents/Resources/app'
 outui  = outapp + '/ui'
 
-gulp.task 'clean', (cb) ->
-  rimraf outbin, cb
-
 copyPrebuilt = ->
   # XXX this stinks, but gulp can't deal with
   # the symlinks in the binary.

gulp.task 'pre', ->
  copyPrebuilt() unless fs.existsSync outbin

gulp.task 'default', ['pre'], ->

  gulp.src './README.md'
    .pipe changed outapp
    .pipe gulp.dest outapp

  # install runtime deps
  gulp.src './package.json'
    .pipe changed outapp
    .pipe gulp.dest outapp
    .pipe install(production:true)

  # compile coffeescript
  gulp.src './src/**/*.coffee'
    .pipe sourcemaps.init()
    .pipe coffee().on 'error', gutil.log
    .pipe sourcemaps.write()
    .pipe changed outapp
    .pipe gulp.dest outapp

  # move .html-files
  gulp.src './src/**/*.html'
    .pipe changed outapp
    .pipe gulp.dest outapp

  # compile less
  gulp.src './src/**/*.less'
    .pipe sourcemaps.init()
    .pipe less().on 'error', gutil.log
    .pipe concat('ui/app.css')

  reloader.script()
    .pipe gulp.dest outui

  # watch rebuilt stuff
  gulp.watch "#{outui}/**/*", reloader.onChange


gulp.task 'clean', (cb) ->
  rimraf outbin, cb

gulp.task 'default', ['package', 'coffee', 'html', 'less']

gulp.task 'watch', ['reloader', 'default'], ->
  # watch to rebuild
  sources = (v for k, v of paths)
  gulp.watch sources, ['default']
