/*global module:false*/
module.exports = function (grunt) {

    grunt.initConfig({

        bower: {
            install: {
                options: {
                    targetDir: './components/',
                    layout: 'byComponent',
                    install: true,
                    copy: true,
                    verbose: true,
                    cleanTargetDir: false,
                    cleanBowerDir: false,
                    bowerOptions: {}
                }
            },
            clean: {
                options: {
                    targetDir: './components/',
                    layout: 'byComponent',
                    install: false,
                    copy: false,
                    cleanTargetDir: true,
                    cleanBowerDir: true
                }
            }
        },

        cssmin: {
            minify: {
                src: ['components/*/*.css', 'src/css/style.css'],
                dest: 'public/css/style.min.css',
                keepSpecialComments: '0'
            }
        },

        jshint: {
            files: ['src/js/*', 'Gruntfile.js']
        },

        concat: {
            options: {
                separator: ';'
            },
            dist: {
                src: ['components/jquery/jquery.js',
                      'components/uikit/**/*.js',
                      'node_modules/geopoint/geopoint.js',
                      'src/js/*.js'],
                dest: 'public/js/script.min.js'
            }
        },


        uglify: {
            dist: {
                files: {
                    'public/js/script.min.js': ['public/js/script.min.js'],
                }
            }
        },

        watch: {
            scripts: {
                files: ['src/**/*.*', 'src/*.*', 'Gruntfile.js'],
                tasks: ['jshint', 'csslint', 'validation', 'concat',  'cssmin', 'copy'],
                options: {
                    spawn: true,
                },
            },
        },

        csslint: {
            options: {
                import: 2
            },
            src: ['src/css/*']
        },

        validation: {
            options: {
                failHard : true,
                stoponerror : true,
                reset: true
            },
            files: {
                src: ['src/*.html']
            }
        },

          copy: {
            main: {
              files: [
                {src: 'bower_components/uikit/fonts/fontawesome-webfont.woff', dest: 'public/fonts/fontawesome-webfont.woff'},
                {src: 'bower_components/uikit/fonts/fontawesome-webfont.eot', dest: 'public/fonts/fontawesome-webfont.eot'},
                {src: 'bower_components/uikit/fonts/fontawesome-webfont.ttf', dest: 'public/fonts/fontawesome-webfont.ttf'},
                {expand: true, cwd: 'src/img', src: ['**'], dest: 'public/img/'},
                {src: 'src/index.html', dest: 'public/index.html'},
              ]
            }
          }


    });

    grunt.loadNpmTasks('grunt-bower-task');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-csslint');
    grunt.loadNpmTasks('grunt-html-validation');

    grunt.registerTask('dev', [ 'bower:install', 'concat',  'cssmin', 'copy', 'watch']);
    grunt.registerTask('build', [ 'bower:install', 'concat', 'uglify',  'cssmin', 'copy', 'bower:clean']);
    grunt.registerTask('test', ['jshint', 'csslint', 'validation']);

};
