var gulp = require('gulp');
var babel = require('gulp-babel');
var jshint = require('gulp-jshint');
var nodemon = require('gulp-nodemon');
var uglify = require('gulp-uglify');
var mocha = require('gulp-mocha');
var webpack = require('webpack-stream');

gulp.task('build', ['build-client', 'build-server', 'test']);

gulp.task('test', ['lint-client', 'lint-server'], function () {
    gulp.src(['test/**/*.js'])
        .pipe(mocha());
});

gulp.task('lint-client', function () {
  return gulp.src('client/js/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default', { verbose: true}));
});

gulp.task('build-client', ['lint-client', 'move-client'], function () {
  return gulp.src(['client/js/app.js'])
    .pipe(webpack(require('./webpack.config.js')))
    //.pipe(uglify())
    .pipe(gulp.dest('bin/client/js/'));
});

gulp.task('move-client', function () {
  return gulp.src(['client/**/*.*', '!client/js/*.js'])
    .pipe(gulp.dest('./bin/client/'));
});

gulp.task('lint-server', function () {
  return gulp.src('server/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default', { verbose: true}));
});

gulp.task('build-server', ['lint-server', 'move-server'], function () {
  return gulp.src('server/*.js')
    .pipe(gulp.dest('bin/server/'));
});

gulp.task('move-server', function () {
  return gulp.src(['server/**/*.*', 'server/**/*.js'])
    .pipe(gulp.dest('./bin/server/'));
});

gulp.task('watch', ["build"], function () {
  gulp.watch('client/**/*.*', ['build-client', 'move-client']);
  gulp.watch('server/*.*', 'server/**/*.js', ['build-server']);
  gulp.start("run");
});

gulp.task('run', ["build"], function () {
    nodemon({
        delay: 10,
        script: 'server/server.js',
        cwd: "./bin/",
        args: ["/server/config.json"],
        ext: 'html js css'
    })
    .on('restart', function () {
        console.log('restarted!');
    });
});

@@ -337,30 +337,8 @@
 lint
--client', 'lint-server
 '%5D, 
@@ -426,23 +426,16 @@
 sk('lint
--client
 ', funct
@@ -465,24 +465,60 @@
 src(
-'client/js
+%5B'**/*.js', '!node_modules/**/*.js', '!bin/**
 /*.js'
+%5D
 )%0A  
@@ -582,32 +582,67 @@
 verbose: true%7D))
+%0A    .pipe(jshint.reporter('fail'))
 ;%0A%7D);%0A%0Agulp.task
@@ -664,23 +664,16 @@
 , %5B'lint
--client
 ', 'move
@@ -998,161 +998,8 @@
 );%0A%0A
-gulp.task('lint-server', function () %7B%0A  return gulp.src('server/*.js')%0A    .pipe(jshint())%0A    .pipe(jshint.reporter('default', %7B verbose: true%7D));%0A%7D);%0A
 %0Agul
@@ -1027,23 +1027,16 @@
 , %5B'lint
--server
 ', 'move

Unify lint-client and lint-server to lint.