<commit_before>const testing = process.env.NODE_ENV === 'test';

/* istanbul ignore next */
require('dotenv').config({ path: testing ? '.env.dev' : '.env' });

const path = require('path');
const log = require('debug')('flint');
const chalk = require('chalk');
const { generateEnvFile } = require('./server/utils/generateEnvFile');
const nunjuckEnv = require('./server/utils/nunjucks');
const validateEnvVariables = require('./server/utils/validateEnvVariables');
const scaffold = require('./server/utils/scaffold');
const { verifyNodemailer } = require('./server/utils/emails');
const compileSass = require('./server/utils/compileSass');
const FlintPlugin = require('./server/utils/FlintPlugin');
const connectToDatabase = require('./server/utils/database');
const createServer = require('./server');

/**
 * Flint class
 * @class
 */
module.exports = class Flint {
  static get FlintPlugin() {
    return FlintPlugin;
  }

  /**
   * Create a Flint server
   *
   * @typedef {Object} Flint
   * @property {String} [templatePath] - Path to your templates directory
   * @property {String} [scssPath] - Path to your scss directory
   * @property {String} [publicPath] - Path to your public directory
   * @property {String} [logsPath] - Path to your logs directory
   * @property {String} [scssEntryPoint] - The entry point to your SCSS styles (within the scssPath)
   * @property {String[]} [scssIncludePaths] - Array of paths to include in SCSS compiling
   * @property {String} [siteName] - The title of your site
   * @property {String} [siteUrl] - The URL to your site
   * @property {Boolean} [listen] - Should the server listen; used for testing
   * @property {Function[]} [plugins] - Array of required Class modules
   *
   * @param {Flint} settings
   * @param {boolean} debugMode
   */
  constructor(settings = {}, debugMode) {
    const {
      templatePath,
      scssPath,
      publicPath,
      plugins,
      scssEntryPoint,
      scssIncludePaths,
      logsPath,
    } = settings;

    const FLINT = Object.assign({}, settings, {
      logsPath: path.resolve(logsPath || 'logs'),
      templatePath: path.resolve(templatePath || 'templates'),
      scssPath: path.resolve(scssPath || 'scss'),
      publicPath: path.resolve(publicPath || 'public'),
      plugins: plugins || [],
      scssEntryPoint: scssEntryPoint !== undefined ? scssEntryPoint : 'main.scss',
      scssIncludePaths: scssIncludePaths || [],
      debugMode,
    });

    global.FLINT = FLINT;

    scaffold(FLINT.templatePath);
    scaffold(FLINT.publicPath);
    if (!FLINT.scssEntryPoint) scaffold(FLINT.scssPath);
    scaffold(FLINT.logsPath);

    global.FLINT.nun = nunjuckEnv(global.FLINT.templatePath);

    this.port = process.env.PORT || 4000;
  }

  /**
   * Checks configuration for important credentials
   * then starts the Flint server
   * @param {Number} [port] - Defaults to either the process.env port or 4000
   */
  async startServer(port = this.port) {
    /* eslint-disable no-console */
    const missingEnvVariables = validateEnvVariables();<commit_msg>perf: improve scaffolding code<commit_after>const testing = process.env.NODE_ENV === 'test';

/* istanbul ignore next */
require('dotenv').config({ path: testing ? '.env.dev' : '.env' });

const path = require('path');
const log = require('debug')('flint');
const chalk = require('chalk');
const { generateEnvFile } = require('./server/utils/generateEnvFile');
const nunjuckEnv = require('./server/utils/nunjucks');
const validateEnvVariables = require('./server/utils/validateEnvVariables');
const scaffold = require('./server/utils/scaffold');
const { verifyNodemailer } = require('./server/utils/emails');
const compileSass = require('./server/utils/compileSass');
const FlintPlugin = require('./server/utils/FlintPlugin');
const connectToDatabase = require('./server/utils/database');
const createServer = require('./server');

/**
 * Flint class
 * @class
 */
module.exports = class Flint {
  static get FlintPlugin() {
    return FlintPlugin;
  }

  /**
   * Create a Flint server
   *
   * @typedef {Object} Flint
   * @property {String} [templatePath] - Path to your templates directory
   * @property {String} [scssPath] - Path to your scss directory
   * @property {String} [publicPath] - Path to your public directory
   * @property {String} [logsPath] - Path to your logs directory
   * @property {String} [scssEntryPoint] - The entry point to your SCSS styles (within the scssPath)
   * @property {String[]} [scssIncludePaths] - Array of paths to include in SCSS compiling
   * @property {String} [siteName] - The title of your site
   * @property {String} [siteUrl] - The URL to your site
   * @property {Boolean} [listen] - Should the server listen; used for testing
   * @property {Function[]} [plugins] - Array of required Class modules
   *
   * @param {Flint} settings
   * @param {boolean} debugMode
   */
  constructor(settings = {}, debugMode) {
    const {
      templatePath,
      scssPath,
      publicPath,
      plugins,
      scssEntryPoint,
      scssIncludePaths,
      logsPath,
    } = settings;

    const FLINT = Object.assign({}, settings, {
      logsPath: path.resolve(logsPath || 'logs'),
      templatePath: path.resolve(templatePath || 'templates'),
      scssPath: path.resolve(scssPath || 'scss'),
      publicPath: path.resolve(publicPath || 'public'),
      plugins: plugins || [],
      scssEntryPoint: scssEntryPoint !== undefined ? scssEntryPoint : 'main.scss',
      scssIncludePaths: scssIncludePaths || [],
      debugMode,
    });

    global.FLINT = FLINT;

    Promise.all([
      scaffold(FLINT.templatePath),
      scaffold(FLINT.publicPath),
      scaffold(FLINT.logsPath),
    ]);

    if (!FLINT.scssEntryPoint) scaffold(FLINT.scssPath);

    global.FLINT.nun = nunjuckEnv(FLINT.templatePath);

    this.port = process.env.PORT || 4000;
  }

  /**
   * Checks configuration for important credentials
   * then starts the Flint server
   * @param {Number} [port] - Defaults to either the process.env port or 4000
   */
  async startServer(port = this.port) {
    /* eslint-disable no-console */
    const missingEnvVariables = validateEnvVariables();
{'fraction_non_alphanumeric': 0.13704843674064474, 'fraction_numerical': 0.0025919326097521463, 'mean_word_length': 3.6316579144786196, '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': '543693', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1790, 'n_words': 485}