<commit_before>'use strict';

const Promise = require('bluebird');
const Server = require('./server');

module.exports = {start};

function start () {
  return Promise.resolve()
  .then(() => {
    Server.start((err) => {
      if (err) {
        throw err;
      }

      Server.log('info', 'Server running at: ' + Server.info.uri);
    });
  })
  .catch((err) => {
    Server.log('==> App Error', err);
    process.exit();
  });
}<commit_msg>Upate core bootstrap new<commit_after>'use strict';

const Promise = require('bluebird');

const fs = Promise.promisifyAll(require('fs'));
const path = require('path');

const db = require('./database');
const Server = require('./server');

module.exports = {start};

function start () {
  return Promise.resolve()
  .then(() => {
    // load core plugins
    return fs.readdirAsync(__dirname)
    .filter(filterCoreFiles)
    .map((file) => {
      return {
        register: require(path.join(__dirname, file)),
        options: { database: db }
      };
    })
    .then(registerToServer);
  })
  .then(() => {
    // load plugins
    return fs.readdirAsync(path.join(__dirname, '..'))
      .filter(filterCoreDirectories)
      .map((dir) => {
        return {
          register: require(path.join(__dirname, '..', dir)),
          options: { database: db }
        };
      })
      .then(registerToServer);
  })
  .then(() => {
    // associate db
    db.doAssociations(db);
  })
  .then(() => {
    if (process.env.NODE_ENV === 'test') {
      return;
    }

    Server.start((err) => {
      if (err) {
        throw err;
      }

      Server.log('info', 'Server running at: ' + Server.info.uri);
    });
  })
  .catch((err) => {
    Server.log('==> App Error', err);
    process.exit();
  });
}

function filterCoreFiles (fileName) {
  try {
    let stat = fs.statSync(path.join(__dirname, fileName));

    if (stat.isFile() && fileName.match(/^[^.]/) && ['server.js', 'bootstrap.js', 'database.js', 'migration.js'].indexOf(fileName) === -1) {
      return true;
    }

    return false;
  } catch (err) {
    return false;
  }
}

function filterCoreDirectories (dirName) {
  try {
    let stat = fs.statSync(path.join(__dirname, '..', dirName));
    if (stat.isDirectory() && dirName.match(/^[^.]/) && ['core'].indexOf(dirName) === -1) {
      return true;
    }

    return false;
  } catch (err) {
    return false;
  }
}

function registerToServer (plugins) {
  return new Promise((resolve, reject) => {
    Server.register(plugins, (err) => {
      if (err) {
        return reject(err);
      }

      return resolve();
    });
  });
}
{'fraction_non_alphanumeric': 0.1926040061633282, 'fraction_numerical': 0.0007704160246533128, 'mean_word_length': 2.5285326086956523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '2720008', 'n_tokens_mistral': 845, 'n_tokens_neox': 837, 'n_words': 173}