<commit_before>import $ from 'jquery';
import fs from 'fs';
import stylus from 'stylus';
import { join } from 'path';
import { settings, packages } from './paths';

/**
 * Load stylesheets into process.
 */
function themes() {
  const { theme: themeName } = require(settings);
  const theme = join(packages, themeName);

  // Atempt to fetch theme configuration
  let config = {};
  try {
    config = require(theme, 'package.json');
  } catch (e) {
    throw new Error(`Reference "${themeName}" is not a package`);
  }

  // Check that it has required properties
  if (config.type !== 'theme') {
    throw new Error(`Package "${themeName}" is not a theme`);
  }

  // Set defaults
  if (typeof config.main !== 'string') {
    config.main = 'index.styl';
  }

  // Load theme
  const root = $($('html').shadowRoot);
  const themeInject = $('<style></style>');
  const stylusSource = fs.readFileSync();

  stylus(stylusSource)
  .render(function render(err, css) {
    themeInject.text(css);
    root.append(themeInject);
  });
}

export default themes;<commit_msg>Add node_modules fallback<commit_after>import $ from 'jquery';
import fs from 'fs';
import stylus from 'stylus';
import { join, resolve } from 'path';
import { ipcRenderer } from 'electron';
import { settings, packages } from './paths';

/**
 * Load stylesheets into process.
 */
function themes() {
  const { theme: themeName } = require(settings);
  let theme = join(packages, themeName);

  // Atempt to fetch theme configuration
  let config = {};
  try {
    config = require(join(theme, 'package'));
  } catch (e) {
    try {
      theme = join(__dirname, '..', 'node_modules', themeName);
      config = require(join(theme, 'package'));
    } catch (a) {
      throw new Error(`Reference "${themeName}" is not a package`);
    }
  }

  // // Check that it has required properties
  // if (config.type !== 'theme') {
  //   throw new Error(`Package "${themeName}" is not a theme`);
  // }

  // Set defaults
  if (typeof config.main !== 'string') {
    config.main = 'index.styl';
  }

  // Load theme
  const root = $('head');
  const themeInject = $('<style></style>');
  const stylusSource = fs.readFileSync(resolve(theme, config.main)).toString();

  stylus(stylusSource)
  .render(function render(err, css) {
    themeInject.text(css);
    root.append(themeInject);
    ipcRenderer.send('neta-theme-injected');
  });
}

export default themes;
{'fraction_non_alphanumeric': 0.1621845262722383, 'fraction_numerical': 0.0, 'mean_word_length': 3.4612546125461257, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3654709', 'n_tokens_mistral': 758, 'n_tokens_neox': 748, 'n_words': 218}