const gulp        = require('gulp');
const imagemin    = require('gulp-imagemin');
const regexRename = require('gulp-regex-rename');
const rename      = require('gulp-rename');
const replace     = require('gulp-replace');
const pngquant    = require('imagemin-pngquant');
const svgstore    = require('gulp-svgstore');

const conf = require('../gulpconfig');





//*------------------------------------*\
//     $SVG INLINE ICONS
//*------------------------------------*/
gulp.task('images:minify:inlinesvgicons', () =>
  gulp.src(`${conf.path.dev.img}/raw/svg/inline-icons/*.svg`)
    .pipe(rename({ prefix: 'icon-' }))
    .pipe(imagemin({
      svgoPlugins: [
        { removeViewBox: false },
      ],
    }))
    .pipe(svgstore())
    .pipe(regexRename(/\.svg/, '.svg.php'))
    .pipe(gulp.dest(`${conf.path.dev.views}/partials/svg`))
);





//*------------------------------------*\
//     $MINIFY IMAGES
//*------------------------------------*/
gulp.task('images:minify', () =>
  gulp.src(`${conf.path.dev.img}/raw/**/*.{jpg,jpeg,png,svg}`)
    .pipe(imagemin({
      optimizationLevel: 3,
      progressive: true,
      interlaced: true,
      svgoPlugins: [
        { removeViewBox: false },
        { cleanupIDs: false },
      ],
      use: [pngquant()]
    }))
    .pipe(gulp.dest(conf.path.dev.img))
);





//*------------------------------------*\
//     $OPTIMISE SVG PARTIALS
//*------------------------------------*/
gulp.task('images:minify:svgpartials', () =>
  gulp.src(`./${conf.path.dev.views}/partials/svg/raw/**/*.svg`)
    .pipe(replace('<g id=', '<g class='))
    .pipe(imagemin({
      svgoPlugins: [
        { removeViewBox: false },
      ],
    }))
    .pipe(regexRename(/\.svg/, '.svg.php'))
    .pipe(gulp.dest(`${conf.path.dev.views}/partials/svg`))
);





//*------------------------------------*\
//     $IMAGES WATCH
//*------------------------------------*/
gulp.task('images:watch', ["images:minify"], function() {});
gulp.task('images:watch:svgpartials', ["images:minify:svgpartials"], function() {});
gulp.task('images:watch:inlinesvgicons', ["images:minify:inlinesvgicons"], function() {});

@@ -629,37 +629,57 @@
 pe(imagemin(
-%7B
+%5B
 %0A      
-svgoP
+imagemin.svgo(%7B%0A        p
 lugins: %5B%0A  
@@ -668,32 +668,34 @@
      plugins: %5B%0A
+  
         %7B remove
@@ -714,32 +714,43 @@
 se %7D,%0A      
+  
 %5D,%0A    
-%7D
+  %7D)%0A    %5D
 ))%0A    .pipe
@@ -1099,43 +1099,82 @@
 min(
-%7B
+%5B
 %0A      
-optimizationLevel: 3,%0A     
+imagemin.gifsicle(%7B interlaced: true %7D),%0A      imagemin.jpegtran(%7B
  pro
@@ -1183,24 +1183,27 @@
 essive: true
+ %7D)
 ,%0A      inte
@@ -1203,36 +1203,82 @@
    i
-nterlaced: true,%0A      svgoP
+magemin.optipng(%7B optimizationLevel: 3 %7D),%0A      imagemin.svgo(%7B%0A        p
 lugi
@@ -1275,32 +1275,34 @@
      plugins: %5B%0A
+  
         %7B remove
@@ -1327,16 +1327,18 @@
         
+  
 %7B cleanu
@@ -1344,32 +1344,34 @@
 upIDs: false %7D,%0A
+  
       %5D,%0A      u
@@ -1373,31 +1373,16 @@
     
-use: %5Bpngquant()%5D
+%7D)
 %0A    
-%7D
+%5D
 ))%0A 
@@ -1417,33 +1417,32 @@
 .dev.img))%0A);%0A%0A%0A
-%0A
 %0A%0A//*-----------
@@ -1716,21 +1716,41 @@
 min(
-%7B
+%5B
 %0A      
-svgoP
+imagemin.svgo(%7B%0A        p
 lugi
@@ -1747,32 +1747,34 @@
      plugins: %5B%0A
+  
         %7B remove
@@ -1801,16 +1801,27 @@
     
+  
 %5D,%0A    
-%7D
+  %7D)%0A    %5D
 ))%0A 

fix #41 - update imagemin syntax