import Spawner from 'promise-spawner';
import logger from './logger';
import { isDebug } from './utils';

export default class Command {
  constructor(command, inheritIo = isDebug()) {
    this.command = command;
    const modifiers = {
      out(d) { return d; },
      err: 'this is an error: ',
    };

    this.spawner = new Spawner(modifiers, {
      stdio: inheritIo ? 'inherit' : 'ignore',
    });

    if (inheritIo) {
      this.spawner.out.pipe(process.stdout);
      this.spawner.err.pipe(process.stdout);
    }
  }
  run = () => {
    logger(`running command: ${this.command}`);
    return this.spawner.spawn(this.command);
  }
}

import Spawner from 'promise-spawner';
import logger from './logger';
import { isDebug } from './utils';

export default class Command {
  constructor(command, inheritIo = isDebug()) {
    this.command = command;
    const modifiers = {};

    this.spawner = new Spawner(modifiers, {
      stdio: inheritIo ? 'inherit' : 'pipe',
    });

    if (isDebug()) {
      this.spawner.out.pipe(process.stdout);
      this.spawner.err.pipe(process.stderr);
    }
  }
  run = () => {
    logger(`running command: ${this.command}`);
    return new Promise((resolve, reject) => {
      this.spawner.spawn(this.command).then(function(code) {
        resolve(this.data);
      })
    });
    return this.spawner.spawn(this.command);
  }
}

update command.js to return output with run()