<commit_before>'use strict'
const grunt = require('gruntfile-api')
const fs = require('fs')
const path = require('path')
const spawn = require('child_process').spawn

global.processes = {}

exports.getTasks = function () {
  return new Promise(function (resolve, reject) {
    const gruntfile = fs.readFileSync(path.join(window.localStorage.getItem('current'), 'Gruntfile.js'))
    grunt.init(gruntfile)
    let tasks = JSON.parse(grunt.getJsonTasks())

    let taskList = []

    for (let task in tasks) {
      taskList.push(task)
    }

    return resolve(taskList)
  })
}

exports.runTask = function (task, cb) {
  // Stop task if running
  if (global.processes[task]) {
    global.processes[task].kill()
    return
  }

  let dir = window.localStorage.getItem('current')
  var command = spawn('grunt', [task], {cwd: dir})

  // Save
  global.processes[task] = command

  cb()

  // Remove when done
  command.on('close', function () {
    delete global.processes[task]
    cb()
  })
}<commit_msg>Use callback instead of sync<commit_after>'use strict'
const grunt = require('gruntfile-api')
const fs = require('fs')
const path = require('path')
const spawn = require('child_process').spawn

global.processes = {}

exports.getTasks = function () {
  return new Promise(function (resolve, reject) {
    fs.readFile(path.join(window.localStorage.getItem('current'), 'Gruntfile.js'), function (err, gruntfile) {
      if (err) return resolve([])

      grunt.init(gruntfile)
      let tasks = JSON.parse(grunt.getJsonTasks())

      let taskList = []

      for (let task in tasks) {
        taskList.push(task)
      }

      return resolve(taskList)
    })
  })
}

exports.runTask = function (task, cb) {
  // Stop task if running
  if (global.processes[task]) {
    global.processes[task].kill()
    return
  }

  let dir = window.localStorage.getItem('current')
  var command = spawn('grunt', [task], {cwd: dir})

  // Save
  global.processes[task] = command

  cb()

  // Remove when done
  command.on('close', function () {
    delete global.processes[task]
    cb()
  })
}
{'fraction_non_alphanumeric': 0.14862914862914864, 'fraction_numerical': 0.0, 'mean_word_length': 3.406779661016949, 'pattern_counts': {'":': 0, '<': 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': '5643397', 'n_tokens_mistral': 682, 'n_tokens_neox': 669, 'n_words': 155}