         'bower_components/select2/select2-spinner.gif'
       ]
   dest:
+    app: 'build/'
     css: 'build/public/css'
     js: 'build/public/js'
     img: 'build/public/img'
-    app: 'build/'
 }
 
-gulp.task 'app-coffee', ['app-lint'], (cb) ->
+gulp.task 'app-coffee', ['clean', 'app-lint'], (cb) ->
   gulp.src(paths.src.app.coffee, base: '.')
   .pipe(sourcemaps.init(sourceRoot: '../'))
   .pipe(coffee(bare: true).on('error', gutil.log))

  .pipe(gulp.dest(paths.dest.app))
  cb()

gulp.task 'templates', ->
  gulp.src(paths.src.app.jade, base: '.')
  .pipe(gulp.dest(paths.dest.app))

gulp.task 'assets-coffee', ['assets-lint'], ->
  gulp.src(paths.src.assets.coffee)
  .pipe(coffee().on('error', gutil.log))
  .pipe(uglify())
  .pipe(concat('default.js'))
  .pipe(gulp.dest(paths.dest.js))

gulp.task 'js', ->
  gulp.src(paths.src.assets.js)
  .pipe(uglify())
  .pipe(concat('lib.js'))
  .pipe(gulp.dest(paths.dest.js))

gulp.task 'img', ->
  gulp.src(paths.src.assets.img)
  .pipe(gulp.dest(paths.dest.img))

gulp.task 'less', ->
  gulp.src(paths.src.assets.less)
  .pipe(sourcemaps.init())
  .pipe(less(paths: paths.bower)).on('error', gutil.log)

gulp.task 'seed', shell.task 'node_modules/.bin/coffee ./config/seed.coffee'

gulp.task 'watch', ->
  gulp.watch(paths.src.app.coffee, ['app-coffee'])
  gulp.watch(paths.src.app.jade, ['templates'])
  gulp.watch(paths.src.assets.coffee, ['assets-coffee'])
  gulp.watch(paths.src.assets.less, ['less'])

gulp.task 'clean', (cb) ->
  del('build', cb)

commonTasks = ['css', 'js', 'less', 'img', 'assets-coffee']

gulp.task 'build', commonTasks.concat ['app-coffee', 'templates']

