"use strict"
let gulp = require('gulp');
let cleanCSS = require('gulp-clean-css');
let uglify = require('gulp-uglify');
let concat = require('gulp-concat');
let gulpCopy = require('gulp-copy');
let RevAll = require('gulp-rev-all');

gulp.task('styles', () => {
  return gulp.src([
  	'css/bootstrap.min.css',
  	'css/style.css',
  	'css/owl.carousel.css'
  	])
    .pipe(cleanCSS({compatibility: 'ie8'}))
  	.pipe(concat('all.css'))
    .pipe(gulp.dest('dist'));
});

gulp.task('scripts', () => {
  return gulp.src([
  	'js/jquery-1.11.2.min.js',
  	'js/bootstrap.min.js',
  	'js/owl.carousel.min.js',
  	'js/jquery.bcSwipe.min.js',
  	'js/custom.js'
  	])
  	.pipe(uglify())
  	.pipe(concat('all.js'))
  	.pipe(gulp.dest('dist'))
})

gulp.task('copy:images', () => {
	return gulp.src('img/**/*')
	.pipe(gulp.dest('dist/img'))
})

gulp.task('copy:fonts', () => {
	return gulp.src('fonts/**/*')
	.pipe(gulp.dest('dist/fonts'))
})

gulp.task('copy:html', () => {
	return gulp.src(['index.html', 'favicon.ico'])
	.pipe(gulp.dest('dist'))
})

// Experimental
gulp.task('cdn', () => {
 return gulp
    .src('dist/**')
    .pipe(RevAll.revision({ dontRenameFile: ['.html', '.png', '.svg', '.jpeg', '.jpg']}))
    .pipe(gulp.dest('cdn'));
})

gulp.task('copy', ['copy:images', 'copy:html', 'copy:fonts'])
gulp.task('build', ['styles', 'scripts', 'copy']);

gulp.task('watch', function() {
  gulp.watch(['index.html', 'js/**/*.js', 'css/**/*.css'], ['build']);
});
