<commit_before>var fs = require('fs');

var actions = function(api, next){
  api.actions = {};
  api.actions.actions = {};
  api.actions.versions = {};

  api.actions.preProcessors = [];
  api.actions.postProcessors = [];

  api.actions.load = function(fullFilePath, reload){
    if(reload == null){ reload = false; }

    var loadMessage = function(action){
      if(reload){
        loadMessage = "action (re)loaded: " + action.name + " @ v" + action.version + ", " + fullFilePath;
      }else{
        var loadMessage = "action loaded: " + action.name + " @ v" + action.version + ", " + fullFilePath;
      }
      api.log(loadMessage, "debug");
    }

    var parts = fullFilePath.split("/");
    var file = parts[(parts.length - 1)];
    var actionName = file.split(".")[0];
    
    if(!reload){
      if(api.configData.general.developmentMode == true){
        api.watchedFiles.push(fullFilePath);
        (function() {
          fs.watchFile(fullFilePath, {interval:1000}, function(curr, prev){
            if(curr.mtime > prev.mtime){
              process.nextTick(function(){
                if(fs.readFileSync(fullFilePath).length > 0){
                  var cleanPath;
                  if(process.platform === 'win32'){
                    cleanPath = fullFilePath.replace(/\//g, "\\");
                  } else {
                    cleanPath = fullFilePath;
                  }

                  delete require.cache[require.resolve(cleanPath)];
                  delete api.actions.actions[actionName];
                  api.actions.load(fullFilePath, true);
                  api.params.buildPostVariables();
                }
              });
            }
          });
        })();
      }
    }

    var loadInAction = function(action){
      if(action.version == null){ action.version = 1.0; }
      if(api.actions.actions[action.name] == null){ api.actions.actions[action.name] = {}; }
      api.actions.actions[action.name][action.version] = action;
      if(api.actions.versions[action.name] == null){
        api.actions.versions[action.name] = [];
      }
      api.actions.versions[action.name].push(action.version);
      api.actions.versions[action.name].sort();
      validateAction(api.actions.actions[action.name][action.version]);
      loadMessage(action);
    }

    try{
      var collection = require(fullFilePath);
      if(api.utils.hashLength(collection) == 1){
        var action = collection.action
        loadInAction(action);
      }else{
        for(var i in collection){
          var action = collection[i];
          loadInAction(action);
        }
      }       
    }catch(err){
      api.exceptionHandlers.loader(fullFilePath, err);
      delete api.actions.actions[action.name][action.version];
    }
  }

  if(api.configData.general.simultaneousActions == null){
    api.configData.general.simultaneousActions = 5;
  }
  
  var validateAction = function(action){
    var fail = function(msg){
      api.log(msg + "; exiting.", "emerg");
      process.exit();
    }<commit_msg>allow for single exports in actionFiles of any name<commit_after>var fs = require('fs');

var actions = function(api, next){
  api.actions = {};
  api.actions.actions = {};
  api.actions.versions = {};

  api.actions.preProcessors = [];
  api.actions.postProcessors = [];

  api.actions.load = function(fullFilePath, reload){
    if(reload == null){ reload = false; }

    var loadMessage = function(action){
      if(reload){
        loadMessage = "action (re)loaded: " + action.name + " @ v" + action.version + ", " + fullFilePath;
      }else{
        var loadMessage = "action loaded: " + action.name + " @ v" + action.version + ", " + fullFilePath;
      }
      api.log(loadMessage, "debug");
    }

    var parts = fullFilePath.split("/");
    var file = parts[(parts.length - 1)];
    var actionName = file.split(".")[0];
    
    if(!reload){
      if(api.configData.general.developmentMode == true){
        api.watchedFiles.push(fullFilePath);
        (function() {
          fs.watchFile(fullFilePath, {interval:1000}, function(curr, prev){
            if(curr.mtime > prev.mtime){
              process.nextTick(function(){
                if(fs.readFileSync(fullFilePath).length > 0){
                  var cleanPath;
                  if(process.platform === 'win32'){
                    cleanPath = fullFilePath.replace(/\//g, "\\");
                  } else {
                    cleanPath = fullFilePath;
                  }

                  delete require.cache[require.resolve(cleanPath)];
                  delete api.actions.actions[actionName];
                  api.actions.load(fullFilePath, true);
                  api.params.buildPostVariables();
                }
              });
            }
          });
        })();
      }
    }

    var loadInAction = function(action){
      if(action.version == null){ action.version = 1.0; }
      if(api.actions.actions[action.name] == null){ api.actions.actions[action.name] = {}; }
      api.actions.actions[action.name][action.version] = action;
      if(api.actions.versions[action.name] == null){
        api.actions.versions[action.name] = [];
      }
      api.actions.versions[action.name].push(action.version);
      api.actions.versions[action.name].sort();
      validateAction(api.actions.actions[action.name][action.version]);
      loadMessage(action);
    }

    try{
      var collection = require(fullFilePath);
      for(var i in collection){
        var action = collection[i];
        loadInAction(action);
      }
    }catch(err){
      api.exceptionHandlers.loader(fullFilePath, err);
      delete api.actions.actions[action.name][action.version];
    }
  }

  if(api.configData.general.simultaneousActions == null){
    api.configData.general.simultaneousActions = 5;
  }
  
  var validateAction = function(action){
    var fail = function(msg){
      api.log(msg + "; exiting.", "emerg");
      process.exit();
    }
{'fraction_non_alphanumeric': 0.1483036614040981, 'fraction_numerical': 0.004198857910648304, 'mean_word_length': 2.179391350774159, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3064602', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1671, 'n_words': 277}