'use strict';

var gulp        = require('gulp'),
    runSequence = require('run-sequence'),
    del         = require('del'),
    browserify  = require('gulp-browserify'),
    less        = require('gulp-less'),
    connect     = require('gulp-connect');

gulp.task('clean', function(done) {
  del('dist', done);
});

gulp.task('build-styles', function() {
  return gulp.src('src/less/main.less')
    .pipe(less())
    .pipe(gulp.dest('dist/css/'))
    .pipe(connect.reload());
});

gulp.task('build-scripts', function() {
  return gulp.src(['src/js/app.js'])
    .pipe(browserify({
      debug: true,
      transform: ['reactify']
    }))
    .pipe(gulp.dest('dist/js/'))
    .pipe(connect.reload());
});

gulp.task('build-assets', function() {
  return gulp.src('src/**/*.html')
    .pipe(gulp.dest('dist/'))
    .pipe(connect.reload());
});

gulp.task('build', function(done) {
  runSequence('clean', ['build-styles', 'build-scripts'], 'build-assets', done);
});

gulp.task('serve', function() {
  connect.server({
    root: 'dist/',
    livereload: true,
    port: process.env.PORT
  });
});

gulp.task('watch', function () {
  gulp.watch(['src/**'], ['build']);
});

gulp.task('default', ['build'], function() {
  runSequence('serve', 'watch');
});

@@ -246,24 +246,126 @@
 connect');%0A%0A
+var sources = %7B%0A  app: 'src/js/app.js',%0A  styles: 'src/less/main.less',%0A  assets: 'src/**/*.html'%0A%7D;%0A%0A
 gulp.task('c
@@ -431,22 +431,19 @@
 ('build-
-styles
+app
 ', funct
@@ -472,45 +472,98 @@
 src(
-'src/less/main.less')%0A    .pipe(less(
+sources.app)%0A    .pipe(browserify(%7B%0A      debug: true,%0A      transform: %5B'reactify'%5D%0A    %7D
 ))%0A 
@@ -591,10 +591,9 @@
 ist/
-cs
+j
 s/')
@@ -646,21 +646,20 @@
 'build-s
-cript
+tyle
 s', func
@@ -689,104 +689,39 @@
 src(
-%5B'src/js/app.js'%5D)%0A    .pipe(browserify(%7B%0A      debug: true,%0A      transform: %5B'reactify'%5D%0A    %7D
+sources.styles)%0A    .pipe(less(
 ))%0A 
@@ -737,33 +737,34 @@
 gulp.dest('dist/
-j
+cs
 s/'))%0A    .pipe(
@@ -844,31 +844,30 @@
 ulp.src(
-'src/**/*.html'
+sources.assets
 )%0A    .p
@@ -991,22 +991,19 @@
 %5B'build-
-styles
+app
 ', 'buil
@@ -1009,13 +1009,12 @@
 ld-s
-cript
+tyle
 s'%5D,
@@ -1199,17 +1199,16 @@
 function
- 
 () %7B%0A  g
@@ -1221,18 +1221,115 @@
 tch(
-%5B'src/**'%5D
+sources.app, %5B'build-script'%5D);%0A  gulp.watch(sources.styles, %5B'build-styles'%5D);%0A  gulp.watch(sources.assets
 , %5B'
@@ -1333,16 +1333,23 @@
  %5B'build
+-assets
 '%5D);%0A%7D);

Fix reload