<commit_before>/* @flow */
/**
 * loadCytoConfig.js
 * Written by: <NAME>
 */
import path from 'path';
import cloneDeep from 'lodash/cloneDeep';

import mergeCytoConfigs from '../mergeCytoConfigs';
import loadGlobalConfig from '../loadGlobalConfig';
import validateTemplate from '../../template/validateTemplate';

import types from '../../utils/types';

/**
 * Loads the cyto.config.js file for the given template and returns it. If the
 * template has a base, it will recursively load the base template's config
 * and return a merged version of the 2 configs.
 *
 * Whe Cyto configs are loaded, all string dependencies are converted to
 * arrays with 3 values:
 *   1. fileName - The original string with the file
 *   2. templateId - The template that the file comes from
 *   3. isRuntimeDep - Was this dependency created at runtime?
 * We do this to ensure we load the correct dependency files when configs are
 * merged. We can allow also store more information in the future if needed
 *
 * @param {string} templateId - The template to load
 * @returns {Object} The loaded cyto.config.js object
 */
export default function loadCytoConfig(templateId) {
  const { libraryPath } = loadGlobalConfig();
  const templatePath = path.join(libraryPath, templateId);
  const configPath = path.join(templatePath, 'cyto.config');

  let rawConfig;
  try {
    // We have to use eval here to make sure that webpack doesn't try and
    // process this require statement :/
    // Open to other ideas on how to implement this
    // We also deep clone to prevent modifying the original config later on
    rawConfig = cloneDeep(eval('require')(configPath)); // eslint-disable-line
  } catch (e) {
    throw new Error(`Could not find config ${templateId} in ${libraryPath}`);
  }

  // Make sure the config is valid before processing further
  validateTemplate(rawConfig, templateId);
<commit_msg>use default errors for loading cyto configs<commit_after>/* @flow */
/**
 * loadCytoConfig.js
 * Written by: <NAME>
 */
import path from 'path';
import cloneDeep from 'lodash/cloneDeep';

import mergeCytoConfigs from '../mergeCytoConfigs';
import loadGlobalConfig from '../loadGlobalConfig';
import validateTemplate from '../../template/validateTemplate';

import types from '../../utils/types';

/**
 * Loads the cyto.config.js file for the given template and returns it. If the
 * template has a base, it will recursively load the base template's config
 * and return a merged version of the 2 configs.
 *
 * Whe Cyto configs are loaded, all string dependencies are converted to
 * arrays with 3 values:
 *   1. fileName - The original string with the file
 *   2. templateId - The template that the file comes from
 *   3. isRuntimeDep - Was this dependency created at runtime?
 * We do this to ensure we load the correct dependency files when configs are
 * merged. We can allow also store more information in the future if needed
 *
 * @param {string} templateId - The template to load
 * @returns {Object} The loaded cyto.config.js object
 */
export default function loadCytoConfig(templateId) {
  const { libraryPath } = loadGlobalConfig();
  const templatePath = path.join(libraryPath, templateId);
  const configPath = path.join(templatePath, 'cyto.config.js');

  // We have to use eval here to make sure that webpack doesn't try and
  // process this require statement :/
  // Open to other ideas on how to implement this
  // We also deep clone to prevent modifying the original config later on
  const rawConfig = cloneDeep(eval('require')(configPath)); // eslint-disable-line

  // Make sure the config is valid before processing further
  validateTemplate(rawConfig, templateId);

{'fraction_non_alphanumeric': 0.09039087947882736, 'fraction_numerical': 0.0027144408251900108, 'mean_word_length': 3.7919375812743823, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1075043', 'n_tokens_mistral': 983, 'n_tokens_neox': 963, 'n_words': 445}