<commit_before>const path = require('path');
const preparePlugins = require('../config/preparePlugins');
const compileGlueStickConfig = require('../config/compileGlueStickConfig');
const compileWebpackConfig = require('../config/compileWebpackConfig');
const logger = require('./logger');

const execHooks = (context, hooks) => {
  if (Array.isArray(hooks)) {
    hooks.forEach(fn => fn(context));
  } else if (typeof hooks === 'function') {
    hooks(context);
  }
};

type ExecWithConfig = (
  func: Function,
  commandArguments: Array<*>,
  options: {
    useGSConfig: boolean;
    useWebpackConfig: boolean;
    skipProjectConfig: boolean;
    skipClientEntryGeneration: boolean;
    skipServerEntryGeneration: boolean;
  },
  hooks: {
    pre: Function;
    post: Function;
  }
) => void;

module.exports = (
  func,
  commandArguments,
  {
    useGSConfig,
    useWebpackConfig,
    skipProjectConfig,
    skipClientEntryGeneration,
    skipServerEntryGeneration,
  } = {},
  { pre, post } = {},
): ExecWithConfig => {
  const projectConfig = skipProjectConfig
    ? {}
    : require(path.join(process.cwd(), 'package.json')).gluestick;
  const plugins = preparePlugins(projectConfig);
  const GSConfig = useGSConfig ? compileGlueStickConfig(plugins, projectConfig) : null;
  const webpackConfig = useWebpackConfig ? compileWebpackConfig(
    logger, plugins, projectConfig, GSConfig,
    { skipClientEntryGeneration, skipServerEntryGeneration },
  ) : null;
  const context = {
    config: {
      projectConfig,
      GSConfig,
      webpackConfig,
      plugins,
    },
    logger,
  };
  try {
    execHooks(context, pre);
    func(context, ...commandArguments);
    execHooks(context, post);
  } catch (error) {
    process.stderr.write(error.message);
    process.exit(1);<commit_msg>check if we have gluestick in dependencies<commit_after>const path = require('path');
const preparePlugins = require('../config/preparePlugins');
const compileGlueStickConfig = require('../config/compileGlueStickConfig');
const compileWebpackConfig = require('../config/compileWebpackConfig');
const logger = require('./logger');

const execHooks = (context, hooks) => {
  if (Array.isArray(hooks)) {
    hooks.forEach(fn => fn(context));
  } else if (typeof hooks === 'function') {
    hooks(context);
  }
};

type ExecWithConfig = (
  func: Function,
  commandArguments: Array<*>,
  options: {
    useGSConfig: boolean;
    useWebpackConfig: boolean;
    skipProjectConfig: boolean;
    skipClientEntryGeneration: boolean;
    skipServerEntryGeneration: boolean;
  },
  hooks: {
    pre: Function;
    post: Function;
  }
) => void;

module.exports = (
  func,
  commandArguments,
  {
    useGSConfig,
    useWebpackConfig,
    skipProjectConfig,
    skipClientEntryGeneration,
    skipServerEntryGeneration,
  } = {},
  { pre, post } = {},
): ExecWithConfig => {
  let packageJson = null;
  try {
    packageJson = require(path.join(process.cwd(), 'package.json'));
    if (!packageJson.dependencies.gluestick) {
      throw new Error('Command need to be run in gluestick project.');
    }
  } catch (error) {
    logger.error(error.message);
    process.exit(1);
  }
  const projectConfig = skipProjectConfig
    ? {}
    : packageJson.gluestick;
  const plugins = preparePlugins(projectConfig);
  const GSConfig = useGSConfig ? compileGlueStickConfig(plugins, projectConfig) : null;
  const webpackConfig = useWebpackConfig ? compileWebpackConfig(
    logger, plugins, projectConfig, GSConfig,
    { skipClientEntryGeneration, skipServerEntryGeneration },
  ) : null;
  const context = {
    config: {
      projectConfig,
      GSConfig,
      webpackConfig,
      plugins,
    },
    logger,
  };
  try {
    execHooks(context, pre);
    func(context, ...commandArguments);
    execHooks(context, post);
  } catch (error) {
    process.stderr.write(error.message);
    process.exit(1);
{'fraction_non_alphanumeric': 0.12757201646090535, 'fraction_numerical': 0.0007716049382716049, 'mean_word_length': 3.7717791411042945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3007722', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1167, 'n_words': 241}