var gulp = require("gulp");
var uglifycss = require('gulp-uglifycss');
var image = require('gulp-image');
var uglify = require('gulp-uglify');
var pipeline = require('readable-stream').pipeline;
var concatCss = require('gulp-concat-css');
var htmlmin = require('gulp-htmlmin');
var inlineCss = require('gulp-inline-css');
var injectJS = require('gulp-inject-js');

gulp.task('minifyhtml', () => {
    return gulp.src('*.html')
        .pipe(htmlmin({ collapseWhitespace: true }))
        .pipe(inlineCss())
        .pipe(injectJS())
        .pipe(gulp.dest('dist'));
});

gulp.task('css', async function () {
    gulp.src('./css/*.css')
        .pipe(concatCss("Stylecss.css"))
        .pipe(uglifycss({
            "maxLineLen": 80,
            "uglyComments": true
        }))
        .pipe(gulp.dest('dist/css'));
});



gulp.task('image', async function () {
    gulp.src('./img/*')
        .pipe(image())
        .pipe(gulp.dest('./dist/img'));
});

gulp.task('compress', async function () {
    return pipeline(
        gulp.src('./skripts/*.js'),
        uglify(),
        gulp.dest('./dist/skripts')
    );
});

gulp.task('watch', async function () {
    gulp.watch('app/img/*', gulp.series('image'));
    gulp.watch('app/*.html', gulp.series('minifyhtml'));
});
