"use strict";

var gulp = require('gulp');
// JS
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var uglify = require('gulp-uglify');
// CSS
var streamqueue = require('streamqueue');
var concatCss = require('gulp-concat-css');
var cleanCSS = require('gulp-clean-css'); // same with gulp-minify-css
var autoprefixer = require('gulp-autoprefixer');
// IMG
var imagemin = require('gulp-imagemin');
// Test
var mocha = require('gulp-mocha');
// Watch
var livereload = require('gulp-livereload');

var src = "./public/src";
var paths = {
	js: src + "/js/**/*.js",
	css: src + "/css/**/*.css",
    img: src + "/img/**/*",
	dist: "./public/dist",
};

gulp.task("default", function() {
	console.log("[Gulp] read gulpfile.js");
});

gulp.task("js", function() {
	return gulp.src(paths.js)
		.pipe(concat("all.js"))
		.pipe(jshint())
		.pipe(jshint.reporter(stylish))
		.pipe(uglify())
		.pipe(gulp.dest(paths.dist + "/js"))
        .pipe(livereload());
});

gulp.task("css", function() {
	return streamqueue({ objectMode: true },
			gulp.src(src + "/css/reset.css"),
			gulp.src(["!" + src + "/css/reset.css", paths.css])
		)
		.pipe(concatCss("all.css"))
		.pipe(cleanCSS({debug: true}, function(details) {
			console.log(details.name + "(origin): " + details.stats.originalSize + " Kb");
			console.log(details.name + "(min): " + details.stats.minifiedSize + " Kb");
		}))
		.pipe(autoprefixer())
		.pipe(gulp.dest(paths.dist + "/css"))
        .pipe(livereload());
});

gulp.task("img", function () {
    return gulp.src(paths.img)
        .pipe(imagemin({
            optimizationLevel: 3,
            progressive: true,
            interlaced: true
        }))
        .pipe(gulp.dest(paths.dist + "/img"))
        .pipe(livereload());
});

/*
gulp.task("test", function () {
    return gulp.src( test js path )
        .pipe(mocha({reporter: 'nyan'}));
});
*/

gulp.task('watch', function () {
	livereload.listen();
	gulp.watch(paths.js, ["js"]);
	gulp.watch(paths.css, ["css"]);
    gulp.watch(paths.img, ["img"]);
});

gulp.task("build", ["js", "css"/*, "img"*/]);



@@ -8,19 +8,21 @@
 rict%22;%0A%0A
-var
+const
  gulp = 
@@ -44,19 +44,21 @@
 ;%0A// JS%0A
-var
+const
  concat 
@@ -81,22 +81,19 @@
 concat')
-;%0Avar 
+,%0A%09
 jshint =
@@ -115,22 +115,19 @@
 jshint')
-;%0Avar 
+,%0A%09
 stylish 
@@ -153,22 +153,19 @@
 tylish')
-;%0Avar 
+,%0A%09
 uglify =
@@ -196,19 +196,21 @@
 %0A// CSS%0A
-var
+const
  streamq
@@ -238,22 +238,19 @@
 mqueue')
-;%0Avar 
+,%0A%09
 concatCs
@@ -279,22 +279,19 @@
 at-css')
-;%0Avar 
+,%0A%09
 cleanCSS
@@ -318,17 +318,17 @@
 an-css')
-;
+,
  // same
@@ -349,20 +349,17 @@
 ify-css%0A
-var 
+%09
 autopref
@@ -402,19 +402,21 @@
 %0A// IMG%0A
-var
+const
  imagemi
@@ -453,19 +453,21 @@
 // Test%0A
-var
+const
  mocha =
@@ -499,19 +499,21 @@
 / Watch%0A
-var
+const
  liverel
@@ -547,19 +547,30 @@
 oad');%0A%0A
-var
+// Paths%0Aconst
  src = %22
@@ -588,11 +588,13 @@
 c%22;%0A
-var
+const
  pat
@@ -2077,32 +2077,64 @@
  %5B%22img%22%5D);%0A%7D);%0A%0A
+// Uncomment to build img files%0A
 gulp.task(%22build

remove vars