/**
 * Tâmia workflow for Grunt.
 * Image optimization: PNG, GIF, JPEG, SVG.
 *
 * @author Artem Sapegin (http://sapegin.me)
 */

module.exports = function(grunt, util, config) {
	'use strict';

	var glob = require('glob');
	var _ = require('lodash');

	var imagesDir = 'images_src';

	var images = !!glob.sync(imagesDir + '/*.{png,jpg,gif}');
	var svgs = !!glob.sync(imagesDir + '/*.svg');

	if (!images && !svgs) return config;

	var localConfig = {
		watch: {
			images: {
				options: {
					atBegin: true
				},
				files: imagesDir + '/*.{png,jpg,gif,svg}',
				tasks: ['images']
			}
		}
	};
	var deps = ['grunt-newer'];
	var tasks = [];

	if (images) {
		deps.push('grunt-contrib-imagemin');
		tasks.push('newer:imagemin');
		localConfig.imagemin = {
			options: {
				pngquant: true
			},
			images: {
				files: [
					{
						expand: true,
						cwd: imagesDir,
						src: '*.{png,jpg,gif}',
						dest: 'images'
					}
				]
			}
		};
	}

	if (svgs) {
		deps.push('grunt-svgmin');
		tasks.push('newer:svgmin');
		localConfig.svgmin = {
			images: {
				files: [
					{
						expand: true,
						cwd: imagesDir,
						src: '*.svg',
						dest: 'images'
					}
				]
			}
		};
	}

	config = _.merge(localConfig, config);

	util.npmDependencies(deps);

	grunt.registerTask('images', tasks);

	return config;
};

@@ -335,16 +335,23 @@
 g,gif%7D')
+.length
 ;%0A%09var s
@@ -389,16 +389,23 @@
 /*.svg')
+.length
 ;%0A%0A%09if (

Fix images module check.