 pkg = require('./package')
+_ = require('lodash')
 
 gulp = require('gulp')
 util = require('gulp-util')

    ))
    .pipe(gulp.dest(options.dest))


gulp.task 'clean', ->
  gulp.src('./public/assets', read: false)
    .pipe(clean())

gulp.task 'browserify', ['clean'], ->
  compileJavascripts './app/javascripts/client/index.coffee',
    name: 'app.js'
    dest: './public/assets'

gulp.task 'stylus', ['clean'], ->
  compileStylesheets './app/stylesheets/index.styl',
    name: 'app.css'
    dest: './public/assets'

gulp.task 'static', ['clean'], ->
  compileStylesheets './app/stylesheets/static.styl',
    name: 'static.css'
    dest: './public'

  compileTemplates ['./app/templates/static/**/*.jade', '!./app/templates/static/**/_*.jade'],
    dest: './public'

gulp.task 'minify', ['browserify', 'stylus'], ->
  gulp.src('./public/assets/*.js')
    .pipe(uglify())
    .pipe(rename(suffix: '.min'))
    .pipe(gulp.dest('./public/assets'))

  gulp.src('./public/assets/*.css')
    .pipe(minifyCSS())
    .pipe(rename(suffix: '.min'))
    .pipe(gulp.dest('./public/assets'))

  gulp.src('./public/static.css')
    .pipe(minifyCSS())
    .pipe(gulp.dest('./public'))

  gulp.src('./public/*.html')
    .pipe(htmlmin(
      removeComments: true
      collapseWhitespace: true

      useShortDoctype: true
      removeEmptyAttributes: true
    ))
    .pipe(gulp.dest(PUBLIC_LOCATION))

gulp.task 'hashify', ['minify'], ->
  gulp.src("#{ASSETS_LOCATION}/*.min.*")
    .pipe(rev())
    .pipe(gulp.dest("#{ASSETS_LOCATION}/"))
    .pipe(rev.manifest())
    .pipe(rename('hashmap.json'))
    .pipe(gulp.dest("#{ASSETS_LOCATION}/"))

gulp.task 'compress', ['hashify'], ->
  gulp.src("#{ASSETS_LOCATION}/*.min-*.*")
    .pipe(gzip())
    .pipe(gulp.dest(ASSETS_LOCATION))

  gulp.src("#{PUBLIC_LOCATION}/*.css")
    .pipe(gzip())
    .pipe(gulp.dest(PUBLIC_LOCATION))

gulp.task 'watch', ->
  processJavascripts(watch: true)

  stylesheets = [
    "#{CORE_LOCATION}/stylesheets/**/*.styl"
    './vendor/**/*.css'
    './vendor/**/*.styl'
    "!#{CORE_LOCATION}/stylesheets/static.styl"
  ]
  gulp.watch(stylesheets).on 'change', (event)->
    watchReporter(event)
    processStylesheets()

  templates = [
    "#{CORE_LOCATION}/stylesheets/static.styl"
    "#{CORE_LOCATION}/templates/static/**/*.jade"
  ]
  gulp.watch(templates).on 'change', (event)->
    watchReporter(event)
    processStatic()

gulp.task('default', ['browserify', 'stylus', 'static'])
gulp.task('build', ['compress'])
