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

function extToLang (ext) {
  var lang;
  
  return lang;
}

// same as requireService, only with sync interface ( useful for requiring services as packages )
module['exports'] = function requireServiceSync (opts) {

   var service = {};
   console.log(opts.path)

   if(typeof opts.language === "undefined") {
     var ext = path.extname(opts.path);
     var extentions = {
       ".js": "javascript",
       ".coffee": "coffee-script",
       ".lua": "lua",
       ".php": "php",
       ".pl": "perl",
       ".py": "python", // Remark: You can also use the "--language python" option
       ".py3": "python3", // Remark: You can also use the "--language python3" option
       ".sh": "bash",
       ".rb": "ruby",
       ".tcl": "tcl",
       ".ss": "scheme",
       ".st": "smalltalk"
     };
     opts.language = extentions[ext];
   }

   opts.path = opts.path;

   if (typeof opts.path === "undefined") {
     cb(new Error('`path` is a required argument.'));
   }

   if (typeof opts.language === "undefined") {
     // cb(new Error('`language` is a required argument.'));
   }

   // take stat of path to determine if its file / folder / missing
   var stat;

   try {
     stat = fs.statSync(opts.path);
   } catch (err) {
     throw err;
   }

   if (stat.isDirectory()) {
     // is directory
     console.log('load as directory');
     return loadService(opts.path);
     return loadDir(opts.path);
   } else {
     // is file, 
     //console.log('load file as string');
     //return loadFile(opts.path);
     // TODO: detect language
   }

   function loadFile (p) {
     return loadService(p);
   }

   function loadDir (cb) {
     // TODO: add support for package.json?
     return fs.readFileSync(opts.path + "/package.json").toString();
   }

};

function loadService (p) {

  /*
  var _service = {
    code: '',
    view: '',
    presenter: '',
    schema: {}
  };
  */
  
  var service = {
    name: p,
    owner: "examples"
  };

  var _service = {
    service: "index.js",
    view: "view.html",
    presenter: "presenter.js",
    schema: "schema.js"
  };

  var pkg;
  console.log('ppp', p)
  try {
    pkg = JSON.parse(fs.readFileSync(path.resolve(p) + "/package.json").toString());
  } catch (err) {
    // pkg not available, dont use
    throw err;
  }

  //console.log(pkg)
  if (typeof pkg === "object") {
    if (pkg.name) {
      service.name = pkg.name;
    }
    if (pkg.author) {
      service.owner = pkg.author;
    }
    if (pkg.main) {
      _service.service = pkg.main;
    }
    if (pkg.view) {
      _service.view = pkg.view;
    }
    if (pkg.presenter) {
      _service.presenter = pkg.presenter;
    }
  }

  var ext = path.extname(_service.service);
  var extentions = {
    ".js": "javascript",
    ".coffee": "coffee-script",
    ".lua": "lua",
    ".php": "php",
    ".pl": "perl",
    ".py": "python", // Remark: You can also use the "--language python" option
    ".py3": "python3", // Remark: You can also use the "--language python3" option
    ".sh": "bash",
    ".rb": "ruby",
    ".tcl": "tcl",
    ".ss": "scheme",
    ".st": "smalltalk"
  };
  service.language = extentions[ext];
  // source is legacy parameter
  service.source = fs.readFileSync(path.resolve(p) + "/" + _service.service).toString();
  service.code = fs.readFileSync(path.resolve(p) + "/" + _service.service).toString();

  try {
    service.presenter = fs.readFileSync(path.resolve(p) + "/" + _service.presenter).toString();
  } catch (err) {
    console.log(err);
  }

  try {
    service.view = fs.readFileSync(path.resolve(p) + "/" + _service.view).toString();
  } catch (err) {
    console.log(err);
  }

  try {
    service.schema = fs.readFileSync(path.resolve(p) + "/" + _service.schema).toString();
  } catch (err) {
    console.log(err);
  }
  console.log(service);

  return service;
 }<commit_msg>[minor] Missing commit to requireServiceSync   * Removes errant console.log   * Now using require() instead of fs.readFileSync<commit_after>var fs = require('fs'),
    path = require('path');

function extToLang (ext) {
  var lang;
  
  return lang;
}

// same as requireService, only with sync interface ( useful for requiring services as packages )
module['exports'] = function requireServiceSync (opts) {

   var service = {};
   // console.log(opts.path)

   if(typeof opts.language === "undefined") {
     var ext = path.extname(opts.path);
     var extentions = {
       ".js": "javascript",
       ".coffee": "coffee-script",
       ".lua": "lua",
       ".php": "php",
       ".pl": "perl",
       ".py": "python", // Remark: You can also use the "--language python" option
       ".py3": "python3", // Remark: You can also use the "--language python3" option
       ".sh": "bash",
       ".rb": "ruby",
       ".tcl": "tcl",
       ".ss": "scheme",
       ".st": "smalltalk"
     };
     opts.language = extentions[ext];
   }

   opts.path = opts.path;

   if (typeof opts.path === "undefined") {
     cb(new Error('`path` is a required argument.'));
   }

   if (typeof opts.language === "undefined") {
     // cb(new Error('`language` is a required argument.'));
   }

   // take stat of path to determine if its file / folder / missing
   var stat;

   try {
     stat = fs.statSync(opts.path);
   } catch (err) {
     throw err;
   }

   if (stat.isDirectory()) {
     // is directory
     return loadService(opts.path);
   } else {
     // TODO: add ability to load files again
     //console.log('load file as string');
     //return loadFile(opts.path);
     // TODO: detect language
   }

   function loadFile (p) {
     return loadService(p);
   }

   function loadDir (cb) {
     // TODO: add support for package.json?
     return fs.readFileSync(opts.path + "/package.json").toString();
   }

};

function loadService (p) {

  var service = {
    name: p,
    owner: "examples"
  };

  var _service = {
    service: "index.js",
    view: "view.html",
    presenter: "presenter.js",
    schema: "schema.js"
  };

  var pkg;

  try {
    pkg = JSON.parse(fs.readFileSync(path.resolve(p) + "/package.json").toString());
  } catch (err) {
    // pkg not available, dont use
    throw err;
  }
  //console.log(pkg)

  if (typeof pkg === "object") {
    if (pkg.name) {
      service.name = pkg.name;
    }
    if (pkg.author) {
      service.owner = pkg.author;
    }
    if (pkg.main) {
      _service.service = pkg.main;
    }
    if (pkg.view) {
      _service.view = pkg.view;
    }
    if (pkg.presenter) {
      _service.presenter = pkg.presenter;
    }
  }

  var ext = path.extname(_service.service);
  var extentions = {
    ".js": "javascript",
    ".coffee": "coffee-script",
    ".lua": "lua",
    ".php": "php",
    ".pl": "perl",
    ".py": "python", // Remark: You can also use the "--language python" option
    ".py3": "python3", // Remark: You can also use the "--language python3" option
    ".sh": "bash",
    ".rb": "ruby",
    ".tcl": "tcl",
    ".ss": "scheme",
    ".st": "smalltalk"
  };
  service.language = extentions[ext];

  // source is legacy parameter, now replaced with code
  service.source = fs.readFileSync(path.resolve(p) + "/" + _service.service).toString();
  service.code = fs.readFileSync(path.resolve(p) + "/" + _service.service).toString();

  try {
    // service.presenter = fs.readFileSync(path.resolve(p) + "/" + _service.presenter).toString();
    service.presenter = require(path.resolve(p) + "/" + _service.presenter);
  } catch (err) {
    // console.log(err);
  }

  try {
    service.view = fs.readFileSync(path.resolve(p) + "/" + _service.view).toString();
  } catch (err) {
    // console.log(err);
  }

  try {
    // service.schema = fs.readFileSync(path.resolve(p) + "/" + _service.schema).toString();
    service.schema = require(path.resolve(p) + "/" + _service.schema);
  } catch (err) {
    console.log(err);
  }
  console.log(service)
  return service;
 }
{'fraction_non_alphanumeric': 0.177130610186586, 'fraction_numerical': 0.0015128593040847202, 'mean_word_length': 2.434199134199134, 'pattern_counts': {'":': 48, '<': 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': '4088845', 'n_tokens_mistral': 2714, 'n_tokens_neox': 2622, 'n_words': 645}