 
 gulp         = require 'gulp'
 autoprefixer = require 'gulp-autoprefixer'
-bower        = require 'gulp-bower'
+bowerFiles   = require 'gulp-bower-files'
 browserify   = require 'gulp-browserify'
+coffeeify    = require 'coffeeify'
 concat       = require 'gulp-concat'
 connect      = require 'gulp-connect'
 clean        = require 'gulp-clean'

# --------------------------------------------------------




#--------------------------------------------------------
# Compile coffeescript files
#--------------------------------------------------------


gulp.task "coffee", ->
   gulp.src "#{src}/js/*.coffee", read: false
      .pipe browserify {transform: ["coffeeify"], extensions: [".coffee"]}
      .pipe rename("app.js")
      .pipe gulp.dest("#{output}/assets/scripts")





# --------------------------------------------------------
# Concatinate Bower Vendor files copied from `grunt bower`
# --------------------------------------------------------


gulp.task 'concat'




#--------------------------------------------------------
# Stylesheets
#--------------------------------------------------------


gulp.task "stylus", ->
   gulp.src "#{src}/css/*.styl"
      .pipe stylus()
      .pipe autoprefixer()
      .pipe gulp.dest("#{output}/assets/styles")





#--------------------------------------------------------
# Watch
#--------------------------------------------------------


gulp.task "watch", ->

  # CSS Compilation
  gulp.watch "#{src}/css/*.styl", ["stylus"]

  # JavaScript Complilation
  gulp.watch "#{src}/js/*.coffee", ["coffee"]

  # Vendor Concatenation/Minification with Bower
  gulp.watch "#{src}/vendor/**", ["bower"]

  # LiveReload
  server = livereload()
  gulp.watch(["#{dist}/**"]).on "change", (file) ->
    server.changed file.path




#--------------------------------------------------------
# Tasks
#--------------------------------------------------------

gulp.task "default", [
   "stylus",
   "coffee",
   "bower",
   "watch"
]







basePath = '.'
src      = "#{basePath}/src"
output   = "#{basePath}/public/static"
dist     = "#{basePath}/dist"
test     = "#{basePath}/test"
vendor   = "#{src}/vendor"
port     = 3000




#--------------------------------------------------------
# Copy Bower libraries to vendor directory
#--------------------------------------------------------


gulp.task "bower", ->
   bowerFiles()
      .pipe gulp.dest "#{vendor}"




#--------------------------------------------------------
# Compile scripts using Browserify
#--------------------------------------------------------


gulp.task "browserify", ->
   gulp.src "#{src}/scripts/app.coffee", read: false
      .pipe browserify
         transform:  ["coffeeify"]
         extensions: [".coffee", ".js"]

      .pipe rename "app.js"
      .pipe gulp.dest "#{output}/assets/scripts"



