<commit_before>var connect = require('connect');
var path = require('path');
var http = require('http');

module.exports = function(grunt) {

  /* Spin up a connect server to display the documentation. */
  grunt.registerMultiTask('viewdocs', function() {   

    // A little trick to keep this task running indefinitely 
    this.async();

    // Merge the options with default values
    var options = this.options({
      port: 9001,
      base: '.',
      hostname: 'localhost'
    });

    startServer();

    // Starts a connect server to display the docs (using static and directory middleware).
    function startServer() {
    
      var app = connect();
      app.use(connect.static(options.base));
      app.use(connect.directory(options.base));

      var server = http.createServer(app);
      server.listen(options.port, options.hostname);

      server.on('listening', function() {
        grunt.log.writeln('Started docs server on ' + (options.host || 'localhost') + ':' + options.port);
        openInChrome();
      });

      server.on('error', function(err) {
        grunt.fatal(err);
      });
    }

    // Spawn a new child process to open up the docs in a new tab in chrome.
    function openInChrome() {

      var cp = require('child_process').spawn('open', [
        '-a',
        '/Applications/Google Chrome.app',
        'http://' + options.hostname + ':' + options.port
      ]);

      // Silently ignore errors
      cp.on('error', function(){});
    }        
  });
};<commit_msg>Updated viewdocs grunt task to use grunt api to spawn child process<commit_after>var connect = require('connect');
var http = require('http');

module.exports = function(grunt) {

  /* Spin up a connect server to display the documentation. */
  grunt.registerMultiTask('viewdocs', function() {   

    // A little trick to keep this task running indefinitely 
    this.async();

    // Merge the options with default values
    var options = this.options({
      port: 9001,
      base: '.',
      hostname: 'localhost'
    });

    // Starts a connect server to display the docs (using static and directory middleware).
    function startServer() {
    
      var app = connect();
      app.use(connect.static(options.base));
      app.use(connect.directory(options.base));

      var server = http.createServer(app);
      server.listen(options.port, options.hostname);

      server.on('listening', function() {
        grunt.log.writeln('Started docs server on ' + (options.host || 'localhost') + ':' + options.port);
        openInChrome();
      });

      server.on('error', function(err) {
        grunt.fatal(err);
      });
    }

    // Spawn a new child process to open up the docs in a new tab in chrome.
    function openInChrome() {
      grunt.util.spawn({
        cmd: 'open',
        args: [
          '-a',
          '/Applications/Google Chrome.app',
          'http://' + options.hostname + ':' + options.port
        ]
      }, function(){});
    }  

    startServer();          
  });
};
{'fraction_non_alphanumeric': 0.14077990746860541, 'fraction_numerical': 0.0026437541308658294, 'mean_word_length': 2.42420814479638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4517759', 'n_tokens_mistral': 889, 'n_tokens_neox': 846, 'n_words': 239}