title: Access Grunt config data within initConfig()
body: <p>How can I access the Grunt config property <code>site</code> to read the <code>project.json</code> file at the path specified by the config property value?</p>
  
  <pre><code>grunt.registerTask('build', function(target) {
    grunt.config('site', target);
    grunt.task.run('foo:dist', 'bar:dist');
  });
  
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    site: grunt.file.readJSON('./sites/' + grunt.config('site') + '/project.json')
  });
  </code></pre>
  
  <p><strong>grunt-cli:</strong></p>
  
  <pre><code>grunt build:sitename
  
  &gt;&gt; Error: Unable to read "./sites/undefined/project.json"
  </code></pre>
  
  <hr>
  
  <p>Using an <a href="http://gruntjs.com/frequently-asked-questions#globals-and-configs" rel="noreferrer">example</a> from the docs, I also tried this:</p>
  
  <pre><code>grunt.registerTask('global', 'site', function(prop, value) {
    global[prop] = val;
  });
  
  grunt.registerTask('build', ['foo:dist', 'bar:dist']);
  
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    site: grunt.file.readJSON('./sites/' + global.site + '/project.json')
  });
  </code></pre>
  
  <p><strong>grunt-cli:</strong></p>
  
  <pre><code>grunt global:site:sitename
  
  &gt;&gt; Error: Unable to read "./sites/undefined/project.json"
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong>:</p>
  
  <p>Using the @FelixKling answer as a guide, I've made some progress:</p>
  
  <pre><code>grunt.registerTask('build', function(target) {
    grunt.config.set('target', target);
    grunt.config.set('site', grunt.file.readJSON('./sites/' + grunt.config.get('target') + '/project.json'));
    grunt.task.run('watch');
  });
  
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    site: grunt.config.get('site'),
  
    watch: {
      sass: {
        files: ['&lt;%= site.dev %&gt;/scss/*.scss'],
        tasks: ['sass:dist']
      }
    },
  
    sass: {
      dist: {
        files: {
          '&lt;%= site.dist %&gt;/style.css': '&lt;%= site.dev %&gt;/scss/style.scss'
        }
      }
    },
  });
  </code></pre>
  
  <p>Now I'm able to read in the <code>project.json</code> file successfully, and (somehow) it's even able to recognize when edits are made to watched files. But for some reason when it runs the <code>sass:dist</code> task, I get this error: <code>Warning: An error occurred while processing a template (Cannot read property 'dev' of undefined).</code></p>
  
  <p>I'm not clear on how the <code>watch</code> task is able to get the correct value for <code>site</code>, but more importantly, I need to figure out a way to get that same value to the <code>sass</code> task.</p>