title: grunt call other tasks from the main task
body: <p>Sometimes you may wish to call other tasks from a main task. </p>
  
  <p>Asume we have <code>build</code> and a <code>dist</code> tasks. By passing the option <code>--build</code> to the <code>dist</code> task, the <code>build</code> task should run <em>before</em>.</p>
  
  <p>Unfortunately, the build task <strong>repeats in an endless loop</strong> ?</p>
  
  <pre><code>grunt dist --build
  </code></pre>
  
  <p>Example (short and simplified):</p>
  
  <pre><code>  // command: grunt build
    grunt.registerTask('build', 'Dist task', function() {
  
      grunt.initConfig({...}); // cssmin, htmlmin tasks etc...
  
      grunt.task.run(tasksArray); 
    });
  
    // command: grunt dist
    grunt.registerTask('dist', 'Build task', function() {
  
      // Option: --build
      var buildOption = grunt.option('build');
  
      if (buildOption != null) {
        grunt.task.run('build'); // Run the build task first
      }
  
      grunt.initConfig({...}); // compress task etc...
  
      grunt.task.run(tasksArray);
    });
  </code></pre>
  
  <p>How can I prevent the endless repeat of the build task?</p>
  
  <hr>
  
  <p>Note:</p>
  
  <p>Of course I <em>may</em> use something like: <code>grunt build &amp;&amp; grunt dist</code>, but the example above is (as mentioned) a simplified example for something bigger.</p>