var gulp = require('gulp');
var browserSync = require('browser-sync');

var useref = require('gulp-useref'),
    gulpif = require('gulp-if'),
    uglify = require('gulp-uglify'),
    minifyCss = require('gulp-minify-css'),
    del = require('del');


gulp.task('copyCombineJsCss', function () {
    var assets = useref.assets();

    return gulp.src('index.html')
        .pipe(assets)
        .pipe(assets.restore())
        .pipe(useref())
        .pipe(gulp.dest('dist'));
});

gulp.task('copyCombineMinifyJsCss', function () {
    var assets = useref.assets();

    return gulp.src('index.html')
        .pipe(assets)
        .pipe(gulpif('*.js', uglify({mangle: false})))// If we omit mangle, angular will fail
        .pipe(gulpif('*.css', minifyCss()))
        .pipe(assets.restore())
        .pipe(useref())
        .pipe(gulp.dest('dist'));
});

gulp.task('copyHtml', function () {
    gulp.src(['app/**/*.html'])
        .pipe(gulp.dest('dist/app/'));
    gulp.src(['assets/img/**/*'])
        .pipe(gulp.dest('dist/assets/img/'));
});

gulp.task('copyAssets', function () {
    gulp.src(['assets/img/**/*'])
        .pipe(gulp.dest('dist/assets/img/'));
});

gulp.task('copySvg', function () {
    gulp.src(['../joint-military-symbology-xml/svg/**/*.svg'])
        .pipe(gulp.dest('dist/svg/'));
});

gulp.task('clean', function (cb) {
    del(['dist/**/*', '!dist/svg/**'], cb);
});

gulp.task('copy', ['copyHtml', 'copyAssets']);
gulp.task('build', ['copy', 'copyCombineJsCss']);
gulp.task('buildMinify', ['copy', 'copyCombineMinifyJsCss']);

// Static server
gulp.task('browser-sync', function () {
    var files = [
        '*.html',
        'app/components/**',
        'assets/css/**',
        'app/*.js'
    ];
    browserSync(files, {
        server: {
            baseDir: "./"
        }
    });
});


@@ -259,26 +259,29 @@
 sk('copy
-C
+-c
 ombine
-JsC
+-js-c
 ss', fun
@@ -492,32 +492,35 @@
 sk('copy
-C
+-c
 ombine
-M
+-m
 inify
-JsC
+-jsc
 ss', fun
@@ -865,25 +865,26 @@
 p.task('copy
-H
+-h
 tml', functi
@@ -1058,25 +1058,26 @@
 p.task('copy
-A
+-a
 ssets', func
@@ -1190,11 +1190,20 @@
 copy
-Svg
+-svg-to-dist
 ', f
@@ -1271,19 +1271,17 @@
 vg/**/*.
-svg
+*
 '%5D)%0A    
@@ -1312,32 +1312,175 @@
 t/svg/'));%0A%7D);%0A%0A
+gulp.task('copy-svg-to-main', function () %7B%0A    gulp.src(%5B'../joint-military-symbology-xml/svg/**/*.*'%5D)%0A        .pipe(gulp.dest('svg'));%0A%7D);%0A%0A
 gulp.task('clean
@@ -1539,32 +1539,112 @@
 **'%5D, cb);%0A%7D);%0A%0A
+gulp.task('clean-everything', function (cb) %7B%0A     del(%5B'dist/**/*'%5D, cb);%0A%7D);%0A%0A
 gulp.task('copy'
@@ -1655,9 +1655,10 @@
 copy
-H
+-h
 tml'
@@ -1668,9 +1668,10 @@
 copy
-A
+-a
 sset
@@ -1713,18 +1713,21 @@
 copy
-C
+-c
 ombine
-JsC
+-js-c
 ss'%5D
@@ -1745,17 +1745,18 @@
 k('build
-M
+-m
 inify', 
@@ -1773,24 +1773,27 @@
 copy
-C
+-c
 ombine
-M
+-m
 inify
-JsC
+-jsc
 ss'%5D

Clean up gulp script and add new tasks for handling SVGs