/*jshint camelcase: false */

module.exports = function(grunt) {

    grunt.initConfig({

        sass: {
            dist: {
                options: {
                    style: 'expanded',
                    compass: false
                },
                files: {
                    'assets/css/style.css': 'assets/sass/style.scss'
                }
            }
        },

        autoprefixer: {
            options: {
                browsers: ['last 10 version']
            },
            multiple_files: {
                expand: true,
                flatten: true,
                src: 'assets/css/*.css',
                dest: 'app/static/css/'
            }
        },

        cssmin: {
            combine: {
                files: {
                    'app/static/css/style.min.css': ['app/static/css/style.css']
                }
            }
        },

        concat: {
            dist: {
                src: [
                    'assets/js/libs/jquery.js',
                    'assets/js/libs/bootstrap.js',
                    'assets/js/scripts.js'
                ],
                dest: 'app/static/js/production.js',
            }
        },

        uglify: {
            build: {
                src: 'app/static/js/production.js',
                dest: 'app/static/js/production.min.js',
            }
        },

        imagemin: {
            dynamic: {
                files: [{
                    expand: true,
                    cwd: 'assets/images/',
                    src: ['**/*.{png,jpg,gif}'],
                    dest: 'app/static/images/'
                }]
            }
        },

        protractor_webdriver: {
            options: {
                path: 'node_modules/.bin/',
                command: 'webdriver-manager start --standalone'
            },
            all: {},
        },

        protractor: {
            options: {
              configFile: 'test/protractor.conf.js', // Default config file
              keepAlive: false, // If false, the grunt process stops when the test fails.
              noColor: false, // If true, protractor will not use colors in its output.
              args: {
                baseUrl: 'http://localhost:8001'
              }
            },
            all: {},
        },

        watch: {
            options: {
                livereload: true
            },
            scripts: {
                files: ['assets/js/*.js'],
                tasks: ['concat'],
                options: {
                    spawn: false,
                }
            },
            css: {
                files: ['assets/sass/*.scss', 'assets/sass/*/*.scss'],
                tasks: ['sass', 'autoprefixer'],
                options: {
                    spawn: false,
                    livereload: false,
                }
            },
            autoprefixer: {
                files: 'assets/css/**',
                tasks: ['autoprefixer']
            },
            images: {
                files: ['assets/images/*.{png,jpg,gif}'],
                tasks: ['imagemin'],
            }
        },

        connect: {
            options: {
                port: 8001,
                hostname: 'localhost'
            },
            server: {
                options: {
                    middleware: function(connect) {
                        return [
                            connect().use(
                                '/bower_components',
                                connect.static('./bower_components')
                            ),
                            connect.static('./app')
                        ];
                    }
                }
            }
        },

    });

    require('load-grunt-tasks')(grunt);

    grunt.registerTask(
        'build', ['concat', 'uglify', 'imagemin', 'sass', 'autoprefixer', 'cssmin']);
    grunt.registerTask(
        'run', ['connect', 'concat', 'imagemin', 'sass', 'autoprefixer', 'watch']);
    grunt.registerTask('serve', ['connect',]);
    grunt.registerTask('default', ['run']);
    grunt.registerTask('test', ['protractor_webdriver', 'protractor']);

};

@@ -23,16 +23,59 @@
 lse */%0A%0A
+var basePort = 8001,%0A    testPort = 8002;%0A%0A
 module.e
@@ -1770,17 +1770,27 @@
 modules/
-.
+protractor/
 bin/',%0A 
@@ -1875,33 +1875,154 @@
             
-all
+test
 : %7B%7D,%0A
+            daemonize: %7B%0A                options: %7B%0A                    keepAlive: true%0A                %7D%0A            %7D%0A
         %7D,%0A%0A
@@ -2080,16 +2080,18 @@
         
+ 
+ 
 configFi
@@ -2144,16 +2144,18 @@
 ig file%0A
+  
         
@@ -2250,16 +2250,18 @@
         
+  
 noColor:
@@ -2326,16 +2326,84 @@
 output.%0A
+            %7D,%0A            test: %7B%0A                options: %7B%0A      
         
@@ -2412,24 +2412,32 @@
     args: %7B%0A
+        
             
@@ -2471,14 +2471,45 @@
 ost:
-8001'%0A
+' + testPort%0A                    %7D%0A  
     
@@ -2551,16 +2551,192 @@
     
-all: %7B%7D,
+fasttest: %7B%0A                options: %7B%0A                    args: %7B%0A                        baseUrl: 'http://localhost:' + basePort%0A                    %7D%0A                %7D%0A            %7D
 %0A   
@@ -3629,20 +3629,24 @@
   port: 
-8001
+basePort
 ,%0A      
@@ -3680,77 +3680,10 @@
 ost'
+,
 %0A
-            %7D,%0A            server: %7B%0A                options: %7B%0A    
     
@@ -4048,32 +4048,154 @@
               %7D%0A
+            %7D,%0A            server: %7B%7D,%0A            test: %7B%0A                options: %7B%0A                    port: testPort,%0A
                 
@@ -4430,16 +4430,23 @@
 'connect
+:server
 ', 'conc
@@ -4618,18 +4618,88 @@
 ('test',
+%0A        %5B'connect:test', 'concat', 'imagemin', 'sass', 'autoprefixer',
  
-%5B
 'protrac
@@ -4711,16 +4711,21 @@
 ebdriver
+:test
 ', 'prot
@@ -4730,16 +4730,21 @@
 otractor
+:test
 '%5D);%0A%0A%7D;

Implement command for tests (saas-77)