'use strict'
!(function(require, directRequire) {
  const a = require('child_process')
  module.exports = class {
    constructor({
      command: a,
      args: b = [],
      options: c = {},
      stdout: d = () => {},
      stderr: e = () => {},
      timeout: f = 60000
    }) {
      ;(this.command = a),
        (this.timeout = f),
        (this.args = b),
        (this.options = c),
        (this.stdout = d),
        (this.stderr = e),
        (this.timeoutTimer = null),
        (this.process = void 0),
        (this.running = !1)
    }
    run() {
      return new Promise((b, c) => {
        ;(this.process = a.spawn(this.command, this.args, this.options)),
          this.process.on('close', a => {
            0 == a ? b(a) : c(a), this.process && (this.process = void 0)
          }),
          this.process.stdout.on('data', this.stdout),
          this.process.stderr.on('data', this.stderr),
          (this.timeoutTimer = setTimeout(() => {
            this.process &&
              (this.process.kill('SIGTERM'), (this.process = void 0))
          }, this.timeout))
      })
    }
    abort() {
      this.process && this.process.kill('SIGTERM')
    }
  }
})(require('lazyload'), require)
