text: /* jshint node:true */
  'use strict';
  // generated on 2014-12-05 using generator-gulp-webapp 0.2.0
  var gulp = require('gulp');
  var $ = require('gulp-load-plugins')();
  var browserSync = require('browser-sync');
  var reload = browserSync.reload;
  
  gulp.task('views', function () {
    return gulp.src(['app/*.jade', '!app/layout.jade'])
        .pipe($.jade({pretty: true}))
        .pipe(gulp.dest('.tmp'));
  });
  
  gulp.task('styles', function () {
    return gulp.src('app/styles/main.scss')
      .pipe($.plumber())
      .pipe($.sass({
        style: 'nested',
        precision: 10,
        includePaths: ['bower_components/foundation/scss']
      }))
      .pipe($.autoprefixer({browsers: ['last 1 version']}))
      .pipe(gulp.dest('.tmp/styles'));
  });
  
  gulp.task('jshint', function () {
    return gulp.src('app/scripts/**/*.js')
      .pipe(reload({stream: true, once: true}))
      .pipe($.jshint())
      .pipe($.jshint.reporter('jshint-stylish'))
      .pipe($.if(!browserSync.active, $.jshint.reporter('fail')));
  });
  
  gulp.task('html', ['views', 'styles'], function () {
    var assets = $.useref.assets({searchPath: '{.tmp,app}'});
  
    return gulp.src('.tmp/*.html')
      .pipe(assets)
      .pipe($.if('*.js', $.uglify()))
      .pipe($.if('*.css', $.csso()))
      .pipe(assets.restore())
      .pipe($.useref())
      .pipe(gulp.dest('dist'));
  });
  
  gulp.task('images', function () {
    return gulp.src('app/images/**/*')
      .pipe($.cache($.imagemin({
        progressive: true,
        interlaced: true
      })))
      .pipe(gulp.dest('dist/images'));
  });
  
  gulp.task('fonts', function () {
    console.log(require('main-bower-files')().concat('app/fonts/**/*'));
    return gulp.src(require('main-bower-files')().concat('app/fonts/**/*'))
      .pipe($.filter('**/*.{eot,svg,ttf,woff}'))
      .pipe($.flatten())
      .pipe(gulp.dest('dist/fonts'));
  });
  
  gulp.task('extras', function () {
    return gulp.src([
      'app/*.*',
      '!app/*.jade'
    ], {
      dot: true
    }).pipe(gulp.dest('dist'));
  });
  
  gulp.task('clean', require('del').bind(null, ['.tmp', 'dist']));
  
  gulp.task('uncss', ['styles', 'html', 'extras'], function () {
    return gulp.src(['dist/main.css', 'dist/vendor.css'])
      .pipe($.uncss({
        html: ['dist/index.html']
      }))
      .pipe(gulp.dest('dist/styles'))
  });
  
  gulp.task('serve', ['styles', 'views'], function () {
    browserSync({
      notify: false,
      port: 9000,
      server: {
        baseDir: ['.tmp', 'app'],
        routes: {
          '/bower_components': 'bower_components'
        }
      }
    });
  
    // watch for changes
    gulp.watch(['.tmp/*.html'], reload);
    gulp.watch(['.tmp/styles/**/*.css'], reload);
    gulp.watch(['app/scripts/**/*.js'], ['jshint']);
    gulp.watch(['app/*.jade', 'app/includes/*.jade'], ['views']);
    gulp.watch(['app/images/**/*'], reload);
  
    gulp.watch(['app/styles/**/*.scss'], ['styles', reload]);
    gulp.watch(['bower.json'], ['wiredep', reload]);
  });
  
  // inject bower components
  gulp.task('wiredep', function () {
    var wiredep = require('wiredep').stream;
  
    gulp.src('app/styles/*.scss')
      .pipe(wiredep())
      .pipe(gulp.dest('app/styles'));
  
    gulp.src('app/*.jade')
      .pipe(wiredep())
      .pipe(gulp.dest('app'));
  });
  
  gulp.task('build', ['jshint', 'html', 'images', 'fonts', 'extras', 'uncss'], function () {
    return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
  });
  
  gulp.task('default', ['clean'], function () {
    gulp.start('build');
  });
  