title: creating tar archives using gulp
body: <p>I'm using gulp-tar to create a tar file... how do I add a top level folder so that when the user runs <code>tar -xzf myArchive.tar</code> it extracts into a specific folder.</p>
  
  <p>here's my code:</p>
  
  <pre><code>gulp.task('prod', ['min', 'gittag'], function() {
  
    //copy all files under /server into a zip file
      gulp.src('../server/**/*')
      .pipe(tar('xoserver' + '-'+ gittag +'.tar'))
      .pipe(gzip())
      .pipe(gulp.dest('../prod'));
  });
  </code></pre>
  
  <p>The above creates a <code>tar.zip</code> file all right, but I have to be careful to add a <code>-C &lt;folder&gt;</code> while extracting, else the files get extracted to the current folder. </p>
  
  <p>[edited]</p>
  
  <p>What I'm trying to do here is generate a tarball of the format <code>xoserver-alpha-d414ddf.tar.gz</code> which, when extracted with a <code>tar xvf</code> will create a folder <code>xoserver-alpha-d414ddf</code> and unpack all the files under it. Essentially I am trying to add new folder name above my packed files.
  If I add a <code>base</code> option, the folder extracted to is just <code>server</code></p>
  
  <p>[ANSWER]</p>
  
  <p>Thanks to ddprrt for a good answer. I am reproducing the final code in case someone else wants to use a similar strategy of embedding the git tag into the name of the tarball for distribution/testing.</p>
  
  <pre><code>gulp.task('gittag', function(cb) {   // generate the git tag 
      git.exec({args : 'branch -v'}, function (err, stdout) {
        var lines = stdout.split('\n');
        for (var l in lines) {
          if (lines[l][0] == '*') {
            var words = lines[l].split(/\s+/);
            gittag = words[1]+ '-' + words[2];
            console.log('Gittag is %s', gittag);
            break;
          }
        }
        cb();
      });
  });
  
  gulp.task('min', ['runbmin', 'template', 'vendor']); // generate min files
  
  gulp.task('prod', ['min', 'gittag'], function() { // create tarball
    //copy all files under /server into a zip file
      return gulp.src('../server/**/*')
      .pipe(rename(function(path) {
          path.dirname = 'server-' + gittag + '/' + path.dirname;
      }))
      .pipe(tar('xoserver-'+gittag+'.tar'))
      .pipe(gzip())
      .pipe(gulp.dest('../prod'));
  });
  </code></pre>