<commit_before>var fs = require('fs')
var cp = require('child_process')
var path = require('path')
var formattedOutput = require('./formatted_output')
var CommonEnv = require(path.join(process.env.SALINGER_HOME_PATH, 'env'))

var scripts = [
  { ext: 'sh', cmd: 'sh' },
  { ext: 'js', cmd: 'node' },
  { ext: 'py', cmd: 'python' },
  { ext: 'rb', cmd: 'ruby' },
  { ext: 'pl', cmd: 'perl' },
  { ext: 'lua', cmd: 'lua' }
]

module.exports = function run(taskname, SpecialEnv) {
  formattedOutput.start({ taskname })

  var _env = SpecialEnv ? Object.assign({}, CommonEnv, SpecialEnv) : CommonEnv
  var env = Object.assign({}, process.env, _env)

  return execute(taskname, env)
    .then(formattedOutput.success)
    .catch(formattedOutput.fail)
}

function findScript(_path, scriptIndex = 0) {
  return new Promise((resolve, reject) => {
    var script = scripts[scriptIndex]
    var name = `${_path}.${script.ext}`
    fs.stat(name, err => {
      if (err) {
        if (scripts.length > scriptIndex + 1) {
          return resolve(findScript(_path, scriptIndex + 1))
        }
        return reject({ err, notFound: true })
      }
      resolve(script)
    })
  })
}

function execute(taskname, env) {
  return new Promise((resolve, reject) => {
    var file = path.join(__dirname, '..', 'tasks', `${taskname}`)<commit_msg>Fix tasks path<commit_after>var fs = require('fs')
var cp = require('child_process')
var path = require('path')
var formattedOutput = require('./formatted_output')
var CommonEnv = require(path.join(process.env.SALINGER_HOME_PATH, 'env'))

var scripts = [
  { ext: 'sh', cmd: 'sh' },
  { ext: 'js', cmd: 'node' },
  { ext: 'py', cmd: 'python' },
  { ext: 'rb', cmd: 'ruby' },
  { ext: 'pl', cmd: 'perl' },
  { ext: 'lua', cmd: 'lua' }
]

module.exports = function run(taskname, SpecialEnv) {
  formattedOutput.start({ taskname })

  var _env = SpecialEnv ? Object.assign({}, CommonEnv, SpecialEnv) : CommonEnv
  var env = Object.assign({}, process.env, _env)

  return execute(taskname, env)
    .then(formattedOutput.success)
    .catch(formattedOutput.fail)
}

function findScript(_path, scriptIndex = 0) {
  return new Promise((resolve, reject) => {
    var script = scripts[scriptIndex]
    var name = `${_path}.${script.ext}`
    fs.stat(name, err => {
      if (err) {
        if (scripts.length > scriptIndex + 1) {
          return resolve(findScript(_path, scriptIndex + 1))
        }
        return reject({ err, notFound: true })
      }
      resolve(script)
    })
  })
}

function execute(taskname, env) {
  return new Promise((resolve, reject) => {
    var file = path.join(process.env.SALINGER_HOME_PATH, 'tasks', `${taskname}`)
{'fraction_non_alphanumeric': 0.17191011235955056, 'fraction_numerical': 0.0022471910112359553, 'mean_word_length': 3.542517006802721, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3766857', 'n_tokens_mistral': 905, 'n_tokens_neox': 894, 'n_words': 219}