module.exports = function(grunt) {
  "use strict";

  var releaseConfig = {
    appRoot: "/hakemisto/"
  };

  grunt.initConfig({
    // Wipe out previous builds and test reporting.
    clean: ["dist/", "test/reports"],

    // Run your source code through JSHint's defaults.
    jshint: ["app/**/*.js"],

    // This task uses James Burke's excellent r.js AMD builder to take all
    // modules and concatenate them into a single file.
    requirejs: {
      release: {
        options: {
          mainConfigFile: "app/config.js",
          generateSourceMaps: true,
          include: ["main"],
          out: "dist/source.min.js",
          optimize: "uglify2",

          // Since we bootstrap with nested `require` calls this option allows
          // R.js to find them.
          findNestedDependencies: true,

          // Include a minimal AMD implementation shim.
          name: "almond",

          // Setting the base url to the distribution directory allows the
          // Uglify minification process to correctly map paths for Source
          // Maps.
          baseUrl: "dist/app",

          // Wrap everything in an IIFE.
          wrap: true,

          // Modules to stub out in the optimized file.
          stubModules: ['text', 'hbars'],

          // Do not preserve any license comments when working with source
          // maps.  These options are incompatible.
          preserveLicenseComments: false,

          // This is needed for the require-handlebars library
          onBuildWrite : function(moduleName, path, content){
              // replace handlebars with the runtime version
              if (moduleName === 'Handlebars') {
                  path = path.replace('handlebars.js','handlebars.runtime.js');
                  content = grunt.file.read(path).toString();
                  content = content.replace(/(define\()(function)/, '$1"handlebars", $2');
              }
              return content;
          }
        }
      }
    },

    // This task simplifies working with CSS inside Backbone Boilerplate
    // projects.  Instead of manually specifying your stylesheets inside the
    // HTML, you can use `@imports` and this task will concatenate only those
    // paths.
    styles: {
      // Out the concatenated contents of the following styles into the below
      // development file path.
      "dist/styles.css": {
        // Point this to where your `index.css` file is location.
        src: "app/styles/index.css",

        // The relative path to use for the @imports.
        paths: ["app/styles"],

        // Rewrite image paths during release to be relative to the `img`
        // directory.
        forceRelative: "/talkoohakemisto/app/img/"
      }
    },

    // Minify the distribution CSS.
    cssmin: {
      release: {
        files: {
          "dist/styles.min.css": ["dist/styles.css"]
        }
      }
    },

    server: {
      options: {
        host: "0.0.0.0",
        port: 8000
      },

      development: {},

      release: {
        options: {
          prefix: "dist"
        }
      },

      test: {
        options: {
          forever: false,
          port: 8001
        }
      }
    },

    talkooserver: {

    },

    watch: {
      options: {
        spawn: true
      },
      livereload: {
        files: [
          'app/**/*',
          '*.html'
        ],
        options: {
          livereload: true
        }
      }
    },

    // Enables running several task at the same time
    concurrent: {
      options: {
        logConcurrentOutput: true,
      },
      watch: [
        'watch',
        'server',
        'talkooserver'
      ]
    },

    processhtml: {
      release: {
        files: {
          "dist/index.html": ["index.html"]
        }
      }
    },

    // Move vendor and app logic during a build.
    copy: {
      release: {
        files: [
          { src: ["app/**"], dest: "dist/" },
          { src: "vendor/**", dest: "dist/" },
          { src: "etc/.htaccess", dest: "dist/.htaccess" }
        ]
      }
    },

    compress: {
      release: {
        options: {
          archive: "dist/source.min.js.gz"
        },

        files: ["dist/source.min.js"]
      }
    },


    /** Replace some path references for build **/
    replace: {
      appJs: {
        src: ['dist/app/app.js'],             // source files array (supports minimatch)
        dest: 'dist/app/',             // destination directory or file
        replacements: [{
          from: 'app.root = "/";',                   // string replacement
          to: 'app.root = "' + releaseConfig.appRoot + '";'
        }]
      },
      html: {
        src: ['dist/*.html'],
        dest: 'dist/',
        replacements: [{
          from: '/-APP_ROOT-/',
          to: releaseConfig.appRoot
        }]
      }
    }
  });

  // Grunt contribution tasks.
  grunt.loadNpmTasks("grunt-contrib-clean");
  grunt.loadNpmTasks("grunt-contrib-jshint");
  grunt.loadNpmTasks("grunt-contrib-cssmin");
  grunt.loadNpmTasks("grunt-contrib-copy");
  grunt.loadNpmTasks("grunt-contrib-compress");
  grunt.loadNpmTasks('grunt-contrib-watch');

  // Third-party tasks.
  grunt.loadNpmTasks("grunt-processhtml");
  grunt.loadNpmTasks('grunt-text-replace');
  grunt.loadNpmTasks('grunt-concurrent');

  // Grunt BBB tasks.
  grunt.loadNpmTasks("grunt-bbb-server");
  grunt.loadNpmTasks("grunt-bbb-requirejs");
  grunt.loadNpmTasks("grunt-bbb-styles");

  // Own
  grunt.loadNpmTasks("../etc/grunt-talkoo-server");

  // When running the default Grunt command, just lint the code.
  grunt.registerTask("default", [
    "clean",
    "jshint",
    "processhtml",
    "copy",
    "replace",
    "requirejs",
    "styles",
    "cssmin",
  ]);

  grunt.registerTask("dev", [
    "concurrent"
  ]);
};

@@ -1501,16 +1501,97 @@
         
+ // (didn't seem to match anything, not sure if it's needed /Albert)%0A          //
  onBuild
@@ -1636,32 +1636,35 @@
 tent)%7B%0A         
+ //
      // replace 
@@ -1704,24 +1704,27 @@
 on%0A         
+ //
      if (mod
@@ -1752,32 +1752,108 @@
 rs') %7B%0A         
+ //       console.log('matched: ' + moduleName + ' : ' + path);%0A          //
          path = 
@@ -1908,32 +1908,35 @@
 .js');%0A         
+ //
          content
@@ -1935,46 +1935,35 @@
  con
-tent = grunt.file.read(path).toString(
+sole.log('newpath: ' + path
 );%0A 
@@ -1962,32 +1962,35 @@
 path);%0A         
+ //
          content
@@ -2060,24 +2060,27 @@
 );%0A         
+ //
      %7D%0A     
@@ -2079,24 +2079,27 @@
  %7D%0A         
+ //
      return 
@@ -2112,24 +2112,27 @@
 t;%0A         
+ //
  %7D%0A        %7D

Remove unused method