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

module.exports = {
  name: 'fastboot',
  description: 'Runs a server to render your app using FastBoot.',

  availableOptions: [
    { name: 'build', type: Boolean, default: true },
    { name: 'environment', type: String, default: 'development', aliases: ['e',{'dev' : 'development'}, {'prod' : 'production'}] },
    { name: 'serve-assets', type: Boolean, default: false},
    { name: 'port', type: Number, default: 3000 },
    { name: 'output-path', type: String, default: 'fastboot-dist' }
  ],

  runCommand: function(appName, options) {
    var FastBootServer = require('../models/server');
    var RSVP = require('rsvp');
    var express = require('express');
    var outputPath = this.commandOptions.outputPath;

    var server = new FastBootServer({
      appFile: findAppFile(outputPath, appName),
      vendorFile: findVendorFile(outputPath),
      htmlFile: findHTMLFile(outputPath),
      ui: this.ui
    });

    var app = express();

    if (this.commandOptions.serveAssets) {
      app.get('/', server.middleware());
      app.use(express.static(outputPath));
    }

    app.get('/*', server.middleware());

    var ui = this.ui;

    var listener = app.listen(options.port, function() {
      var host = listener.address().address;
      var port = listener.address().port;

      ui.writeLine('Ember FastBoot running at http://' + host + ":" + port);
    });

    // Block forever
    return new RSVP.Promise(function() { });
  },

  triggerBuild: function(commandOptions) {
    var BuildTask = this.tasks.Build;
    var buildTask = new BuildTask({
      ui: this.ui,
      analytics: this.analytics,
      project: this.project
    });

    return buildTask.run(commandOptions);
  },

  run: function(options, args) {
    process.env.EMBER_CLI_FASTBOOT = true;

    this.commandOptions = options;

    var runCommand = function() {
      var appName = process.env.EMBER_CLI_FASTBOOT_APP_NAME || this.project.name();

      return this.runCommand(appName, options);
    }.bind(this);

    if (options.build) {
      return this.triggerBuild(options)
        .then(runCommand);
    }

    return runCommand();
  },
};

function findAppFile(outputPath, appName) {
  return findFile("app", path.join(outputPath, "assets", appName + "*.js"));
}

function findVendorFile(outputPath) {
  return findFile("vendor", path.join(outputPath, "assets", "vendor*.js"));
}

function findHTMLFile(outputPath) {
  var fs = require('fs');
  if (fs.existsSync('app/fastboot.html')) {
    return 'app/fastboot.html';
  }

  return findFile('html', path.join(outputPath, 'index*.html'));
}

function findFile(name, globPath) {<commit_msg>remove fastboot.html, always use index.html<commit_after>var path = require('path');

module.exports = {
  name: 'fastboot',
  description: 'Runs a server to render your app using FastBoot.',

  availableOptions: [
    { name: 'build', type: Boolean, default: true },
    { name: 'environment', type: String, default: 'development', aliases: ['e',{'dev' : 'development'}, {'prod' : 'production'}] },
    { name: 'serve-assets', type: Boolean, default: false},
    { name: 'port', type: Number, default: 3000 },
    { name: 'output-path', type: String, default: 'fastboot-dist' }
  ],

  runCommand: function(appName, options) {
    var FastBootServer = require('../models/server');
    var RSVP = require('rsvp');
    var express = require('express');
    var outputPath = this.commandOptions.outputPath;

    var server = new FastBootServer({
      appFile: findAppFile(outputPath, appName),
      vendorFile: findVendorFile(outputPath),
      htmlFile: findHTMLFile(outputPath),
      ui: this.ui
    });

    var app = express();

    if (this.commandOptions.serveAssets) {
      app.get('/', server.middleware());
      app.use(express.static(outputPath));
    }

    app.get('/*', server.middleware());

    var ui = this.ui;

    var listener = app.listen(options.port, function() {
      var host = listener.address().address;
      var port = listener.address().port;

      ui.writeLine('Ember FastBoot running at http://' + host + ":" + port);
    });

    // Block forever
    return new RSVP.Promise(function() { });
  },

  triggerBuild: function(commandOptions) {
    var BuildTask = this.tasks.Build;
    var buildTask = new BuildTask({
      ui: this.ui,
      analytics: this.analytics,
      project: this.project
    });

    return buildTask.run(commandOptions);
  },

  run: function(options, args) {
    process.env.EMBER_CLI_FASTBOOT = true;

    this.commandOptions = options;

    var runCommand = function() {
      var appName = process.env.EMBER_CLI_FASTBOOT_APP_NAME || this.project.name();

      return this.runCommand(appName, options);
    }.bind(this);

    if (options.build) {
      return this.triggerBuild(options)
        .then(runCommand);
    }

    return runCommand();
  },
};

function findAppFile(outputPath, appName) {
  return findFile("app", path.join(outputPath, "assets", appName + "*.js"));
}

function findVendorFile(outputPath) {
  return findFile("vendor", path.join(outputPath, "assets", "vendor*.js"));
}

function findHTMLFile(outputPath) {
  return findFile('html', path.join(outputPath, 'index*.html'));
}

function findFile(name, globPath) {
{'fraction_non_alphanumeric': 0.15514301951127107, 'fraction_numerical': 0.0015154385300246258, 'mean_word_length': 3.463229078613694, 'pattern_counts': {'":': 2, '<': 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': '5968740', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1618, 'n_words': 375}