/****************************************************************************
 * Copyright (C) 2015, bitmovin GmbH, All Rights Reserved
 *
 * Created on: 6/19/15
 * Author: Reinhard Grandl   <reinhard.grandl@bitmovin.net>
 *         Daniel Weinberger <daniel.weinberger@bitmovin.net>
 *
 * This source code and its use and distribution, is subject to the terms
 * and conditions of the applicable license agreement.
 ****************************************************************************/

module.exports = function(grunt) {
  var header = '/****************************************************************************\n' +
    '* Copyright (C) 2015, bitmovin GmbH, All Rights Reserved\n' +
    '*\n' +
    '* This source code and its use and distribution, is subject to the terms\n' +
    '* and conditions of the applicable license agreement.\n' +
    '****************************************************************************/\n';

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    concat: {
      options: {
        separator: ';\n',
        banner: header + '\n(function(global) {\n',
        footer: 'global.BitcodinApi = BitcodinApi;\n})(this);',
        stripBanners: true
      },
      debug: {
        src: 'src/**/*.js',
        dest: 'debug/<%= pkg.name %>.js'
      }
    },
    watch: {
      local: {
        files: [
          'src/**/*.*',
          'test/**/*.*',
          '!node_modules/**',
          '!_SpecRunner.html'
        ],
        options: {
          livereload: true
        },
        tasks: ['concat', 'jasmine:app']
      }
    },
    jasmine: {
      app: {
        src: [
          'src/**/*.js'
        ],
        options: {
          helpers: 'test/helpers/**/*.js',
          specs: 'test/**/*Spec.js',
          outfile: 'test/SpecRunner.html',
          keepRunner: true,
          polyfills: [
            'libs/es6-promise.js'
          ]
        }
      }
    }
  });


  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-jasmine');

  grunt.registerTask('test', ['concat:debug', 'jasmine:app']);
};

@@ -1003,16 +1003,83 @@
 .json'),
+%0A    settings: grunt.file.readJSON('test/resources/settings.json'),
 %0A%0A    co
@@ -1623,31 +1623,319 @@
 : %5B'
-concat', 'jasmine:app'%5D
+test'%5D%0A      %7D%0A    %7D,%0A    'string-replace': %7B%0A      insertApiKey: %7B%0A        files: %7B%0A          'dist/': %5B%0A            'test/**'%0A          %5D%0A        %7D,%0A        options: %7B%0A          replacements: %5B%7B%0A            pattern: /%5C%7B%5C%7BAPI_KEY%5C%7D%5C%7D/ig,%0A            replacement: '%3C%25= settings.apikey %25%3E'%0A          %7D%5D%0A        %7D
 %0A   
@@ -2265,32 +2265,369 @@
     %5D%0A        %7D%0A
+      %7D,%0A      dist: %7B%0A        src: %5B%0A          'src/**/*.js'%0A        %5D,%0A        options: %7B%0A          helpers: 'dist/test/helpers/**/*.js',%0A          specs: 'dist/test/**/*Spec.js',%0A          outfile: 'dist/test/SpecRunner.html',%0A          keepRunner: true,%0A          polyfills: %5B%0A            'libs/es6-promise.js'%0A          %5D%0A        %7D%0A
       %7D%0A    %7D%0A  
@@ -2769,16 +2769,62 @@
 smine');
+%0A  grunt.loadNpmTasks('grunt-string-replace');
 %0A%0A  grun
@@ -2847,16 +2847,47 @@
 test', %5B
+'string-replace:insertApiKey', 
 'concat:
@@ -2903,19 +2903,20 @@
 jasmine:
-app
+dist
 '%5D);%0A%7D;%0A

Create a dist/ folder with the ready-to-run test cases as the API Key is read from settings.json and inserted by grunt into the test files.