All files / src/util shell.js

52% Statements 13/25
8.33% Branches 1/12
50% Functions 4/8
52.17% Lines 12/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48    1x     1x 1x 1x   1x   1x   1x                                                                   1x
import { spawn } from 'child_process'
import { stop } from 'simple-spinner'
import { exec as cmd, cd } from 'shelljs'
 
/**
 * executes a command asynchronously that shares the stdin and stdout
 */
export function exec (command, args, options = { stdio: 'inherit', env: process.env, cwd: process.cwd(), detached: true }) {
  return new Promise((resolve) => {
    if (options && options.start) {
      process.stdout.write(options.start)
    }
 
    process.nextTick(() => {
      const child = spawn(command, args, options)
 
      child.on('close', (code) => {
        stop()
        if (options && options.stop) {
          process.stdout.write(options.stop)
        }
        resolve({
          code, out: '', err: ''
        })
      })
    })
  })
}
 
/**
 * execute a command asynchronously without sharing stdin and stdiout
 * @type {Object}
 */
export function execp (command, options = { silent: true }) {
  return new Promise((resolve, reject) => {
    cmd(command, options, function (code, out, err) {
      resolve({ code, err, out })
    })
  })
}
 
/**
 *  change the current directory
 */
export function chdir (path) {
  cd(path)
}
E