var gulp = require('gulp');

gulp.task('default', function() {
  console.log('Hello Gulp!');
});

var tslint = require('gulp-tslint');
gulp.task('lint', function() {
  return gulp.src([
   './source/ts/**/**.ts', './test/**/**.test.ts'
 ]).pipe(tslint.report({
      formatter: 'verbose'
    }))
    .pipe(tslint.report());
});

var ts = require('gulp-typescript');
var tsProject = ts.createProject({
    removeComments : true,
    noImplicitAny : true,
    target : 'ES3',
    module : 'commonjs',
    declarationFiles : false
});

gulp.task('tsc', function() {
return gulp.src('./source/ts/**/**.ts')
           .pipe(tsProject())
           .js.pipe(gulp.dest('./temp/source/js'));
});

var tsTestProject = ts.createProject({
    removeComments : true,
    noImplicitAny : true,
    target : 'ES3',
    module : 'commonjs',
    declarationFiles : false
});

gulp.task('tsc-tests', function() {
  return gulp.src('./test/**/**.test.ts')
             .pipe(tsTestProject())
             .js.pipe(gulp.dest('./temp/test/'));
});

var browserify  = require('browserify'),
    transform   = require('vinyl-transform'),
    uglify      = require('gulp-uglify'),
    sourcemaps  = require('gulp-sourcemaps');

var browserified = transform(function(filename) {
  var b = browserify({ entries: filename, debug: true });
  return b.bundle();
});

gulp.task('bundle-js', function () {
  return gulp.src('./temp/source/js/main.js')
             .pipe(browserified)
             .pipe(sourcemaps.init({ loadMaps: true }))
             .pipe(uglify())
             .pipe(sourcemaps.write('./'))
             .pipe(gulp.dest('./dist/source/js/'));
});

gulp.task('bundle-test', function () {
  return gulp.src('./temp/test/**/**.test.js')
             .pipe(browserified)
             .pipe(gulp.dest('./dist/test/'));
});

var runSequence = require('run-sequence');
gulp.task('default', function(cb) {
  runSequence(
    'lint',                      // lint
    ['tsc', 'tsc-tests'],        // compile
    ['bundle-js','bundle-test'], // optimize
    'karma'                      // test
    'browser-sync',              // serve
    cb                           // callback
  );
});

var karma = require("gulp-karma");

gulp.task('karma', function(cb) {
  gulp.src('./dist/test/**/**.test.js')
      .pipe(karma({
         configFile: 'karma.conf.js',
         action: 'run'
       }))
       .on('end', cb)
       .on('error', function(err) {
         // Make sure failed tests cause gulp to exit non-zero
         throw err;
       });
});

gulp.task('bundle', function(cb) {
  runSequence('build', [
    'bundle-js', 'bundle-test'
  ], cb);
});

gulp.task('test', function(cb) {
  runSequence('bundle', ['karma'], cb);
});

var browserSync = require('browser-sync');
gulp.task('browser-sync', ['test'], function() {
  browserSync({
    server: {
      baseDir: "./dist"
    }
  });

  return gulp.watch([
    "./dist/source/js/**/*.js",
    "./dist/source/css/**.css",
    "./dist/test/**/**.test.js",
    "./dist/data/**/**",
    "./index.html"
  ], [browserSync.reload]);
});

@@ -2273,24 +2273,24 @@
 ire(
-%22gulp-karma%22);%0D%0A
+'karma').Server;
 %0D%0Agu
@@ -2318,83 +2318,35 @@
 tion
-(cb
+ (done
 ) %7B%0D%0A  
-gulp.src('./dist/test/**/**.test.js')%0D%0A      .pipe(karma(%7B%0D%0A     
+new Server(%7B%0D%0A
     
@@ -2357,17 +2357,30 @@
 igFile: 
-'
+__dirname + '/
 karma.co
@@ -2396,80 +2396,68 @@
     
-     action: 'run'
+singleRun: true
 %0D%0A  
-     %7D))%0D%0A       .on('end', cb)%0D%0A       .on('error
+%7D, done).start();%0D%0A%7D);%0D%0A%0D%0Agulp.task('test
 ', f
@@ -2467,110 +2467,98 @@
 tion
-(err
+ (done
 ) %7B%0D%0A  
-       // Make sure failed tests cause gulp to exit non-zero%0D%0A         throw err;%0D%0A       %7D
+new Server(%7B%0D%0A    configFile: __dirname + '/karma.conf.js'%0D%0A  %7D, done).start(
 );%0D%0A
@@ -2680,90 +2680,8 @@
 %0D%0A%0D%0A
-gulp.task('test', function(cb) %7B%0D%0A  runSequence('bundle', %5B'karma'%5D, cb);%0D%0A%7D);%0D%0A%0D%0A
 var 

Update to non deprecated gul-karma code per the gulp-karma github entry