text: 'use strict';
  
  module.exports = function(grunt) {
    require('time-grunt')(grunt);
    // Project Configuration
    grunt.initConfig({
      pkg: grunt.file.readJSON('package.json'),
      watch: {
        js: {
          files: ['gruntfile.js', 'application.js', 'lib/**/*.js', 'test/**/*.js'],
          options: {
            livereload: true
          }
        },
        html: {
          files: ['public/views/**', 'app/views/**'],
          options: {
            livereload: true
          }
        }
      },
      nodemon: {
        dev: {
          script: 'application.js',
          options: {
            args: [],
            ignore: ['public/**'],
            ext: 'js,html',
            nodeArgs: [],
            delayTime: 1,
            env: {
              PORT: 3000
            },
            cwd: __dirname
          }
        }
      },
      concurrent: {
        serve: ['nodemon', 'watch'],
        debug: ['node-inspector', 'shell:debug', 'open:debug'],
        options: {
          logConcurrentOutput: true
        }
      },
      env : {
        options : {},
        // environment variables - see https://github.com/jsoverson/grunt-env for more information
        local: {
          FH_USE_LOCAL_DB: true,
          FH_SERVICE_MAP: function() {
            /*
             * Define the mappings for your services here - for local development.
             * You must provide a mapping for each service you wish to access
             * This can be a mapping to a locally running instance of the service (for local development)
             * or a remote instance.
             */
            // var serviceMap = {
            //   'xw5w5fsmgfcz7vlpfo72edpy': 'https://testing-xw5w5fsmgfcz7vlpfo72edpy-dev.mbaas1.us.feedhenry.com/',
            //   'ifwsei3d5hjvkwrimed5tmxs': 'https://testing-ifwsei3d5hjvkwrimed5tmxs-dev.mbaas1.us.feedhenry.com/',
            //   'u2hzmq3yac46v5cmacwacjqx': 'https://testing-u2hzmq3yac46v5cmacwacjqx-dev.mbaas1.us.feedhenry.com/'
            // };
  
            // var serviceMap = {
            //   'd5ds624szo43efphrj2y3em5': 'https://testing-d5ds624szo43efphrj2y3em5-dev.mbaas1.epsilon.feedhenry.com/',
            //   'lyzdppxaaba3hhqskzqr5rv4': 'https://testing-lyzdppxaaba3hhqskzqr5rv4-dev.mbaas1.epsilon.feedhenry.com/',
            //   'wjnooer3tajhmji5tdayzpgr': 'https://testing-wjnooer3tajhmji5tdayzpgr-dev.mbaas1.epsilon.feedhenry.com/'
            // }
  
            // {
            //   'barcode' : 'fo3inxdemphile6yn4ct7iqi',
            //   'image' : 'r6n4x35cqq6qzcr77t6l2tbb',
            //   'order' : '2g7stzwgjcfplrc4tgnf7ipa'
            // }
  
            // var serviceMap = {
            //   'fo3inxdemphile6yn4ct7iqi': 'https://barcodemicroservopen7iqi.b5e6.rhm-eng-a.openshiftapps.com',
            //   'r6n4x35cqq6qzcr77t6l2tbb': 'https://imagemicroservicopen2tbb.b5e6.rhm-eng-a.openshiftapps.com',
            //   '2g7stzwgjcfplrc4tgnf7ipa': 'https://ordermicroservicopen7ipa.b5e6.rhm-eng-a.openshiftapps.com'
            // }
  
            var serviceMap = {
              'fo3inxdemphile6yn4ct7iqi': 'http://127.0.0.1:8002',
              'r6n4x35cqq6qzcr77t6l2tbb': 'https://imagemicroservicopen2tbb.b5e6.rhm-eng-a.openshiftapps.com',
              '2g7stzwgjcfplrc4tgnf7ipa': 'https://ordermicroservicopen7ipa.b5e6.rhm-eng-a.openshiftapps.com'
            }
  
  console.log('serviceMap = ', serviceMap);
            return JSON.stringify(serviceMap);
          }
        }
      },
      'node-inspector': {
        dev: {}
      },
      shell: {
        debug: {
          options: {
            stdout: true
          },
          command: 'env NODE_PATH=. node --debug-brk application.js'
        },
        unit: {
          options: {
            stdout: true,
            stderr: true,
            failOnError: true
          },
          command: 'env NODE_PATH=. ./node_modules/.bin/mocha -A -u exports --recursive test/unit/'
        },
        accept: {
          options: {
            stdout: true,
            stderr: true,
            failOnError: true
          },
          command: 'env NODE_PATH=. ./node_modules/.bin/mocha -A -u exports --recursive test/server.js test/accept/'
        },
        coverage_unit: {
          options: {
            stdout: true,
            stderr: true,
            failOnError: true
          },
          command: [
            'rm -rf coverage cov-unit',
            'env NODE_PATH=. ./node_modules/.bin/istanbul cover --dir cov-unit ./node_modules/.bin/_mocha -- -A -u exports --recursive test/unit/',
            './node_modules/.bin/istanbul report',
            'echo "See html coverage at: `pwd`/coverage/lcov-report/index.html"'
          ].join('&&')
        },
        coverage_accept: {
          options: {
            stdout: true,
            stderr: true,
            failOnError: true
          },
          command: [
            'rm -rf coverage cov-accept',
            'env NODE_PATH=. ./node_modules/.bin/istanbul cover --dir cov-accept ./node_modules/.bin/_mocha -- -A -u exports --recursive test/server.js test/accept/',
            './node_modules/.bin/istanbul report',
            'echo "See html coverage at: `pwd`/coverage/lcov-report/index.html"'
          ].join('&&')
        }
      },
      open: {
        debug: {
          path: 'http://127.0.0.1:8080/debug?port=5858',
          app: 'Google Chrome'
        },
        platoReport: {
          path: './plato/index.html',
          app: 'Google Chrome'
        }
      },
      plato: {
        src: {
          options : {
            jshint : grunt.file.readJSON('.jshintrc')
          },
          files: {
            'plato': ['lib/**/*.js']
          }
        }
      }
    });
  
    // Load NPM tasks
    require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
  
    // Testing tasks
    grunt.registerTask('test', ['shell:unit', 'shell:accept']);
    grunt.registerTask('unit', ['shell:unit']);
    grunt.registerTask('accept', ['env:local', 'shell:accept']);
  
    // Coverate tasks
    grunt.registerTask('coverage', ['shell:coverage_unit', 'shell:coverage_accept']);
    grunt.registerTask('coverage-unit', ['shell:coverage_unit']);
    grunt.registerTask('coverage-accept', ['env:local', 'shell:coverage_accept']);
  
    // Making grunt default to force in order not to break the project.
    grunt.option('force', true);
  
    grunt.registerTask('analysis', ['plato:src', 'open:platoReport']);
  
    grunt.registerTask('serve', ['env:local', 'concurrent:serve']);
    grunt.registerTask('debug', ['env:local', 'concurrent:debug']);
    grunt.registerTask('default', ['serve']);
  };
  