src/index.js
function respawn() {
    if (isNil(proc) === false) {
      proc.stderr.removeAllListeners();
      proc.stderr.end();
      proc.stderr.unpipe();
      proc.stdout.removeAllListeners();
      proc.stdout.end();
      proc.stdout.unpipe();
      proc.removeAllListeners();
      proc.kill();
    }

    const { env } = process;
    const opts = { env };
    const args = [];
    let cmd;

    // run opti-node
    // e.g. opti-node script.js
    if (exec === "") {
      args.push(script);
    }

    // execute something else
    if (exec !== "") {
      const [execCmd, ...execArgs] = exec
        .trim()
        .replace(leadingQuotesPattern, "")
        .replace(trailingQuotesPattern)
        .split(" ");
      cmd = execCmd;
      execArgs.forEach(item => args.push(item));
    }

    if (isNil(cmd) === false) {
      // not running opti-node
      proc = spawn(cmd, args, opts);
    } else {
      // running with opti-node
      const optiNodeOpts = { args, opts };
      optiNodeOpts.cmd = cmd;
      proc = createProcess(optiNodeOpts);
    }

    proc.addListener("close", () => watcher.emit("proc-close"));
    proc.addListener("disconnect", () => watcher.emit("proc-disconnect"));
    proc.addListener("error", err => watcher.emit("proc-error", err));
    proc.addListener("exit", () => watcher.emit("proc-exit"));
    proc.stdout.pipe(watcher.stdout);
    proc.stderr.pipe(watcher.stderr);
  }
function respawn() {
    if (isNil(proc) === false) {
      proc.stderr.removeAllListeners();
      proc.stderr.end();
      proc.stderr.unpipe();
      proc.stdout.removeAllListeners();
      proc.stdout.end();
      proc.stdout.unpipe();
      proc.removeAllListeners();
      proc.kill();
    }

    const { env } = process;
    const opts = { env };
    const args = [];
    let cmd;

    // run opti-node
    // e.g. opti-node script.js
    if (exec === "") {
      args.push(script);
    }

    // execute something else
    if (exec !== "") {
      const [execCmd, ...execArgs] = exec
        .trim()
        .replace(leadingQuotesPattern, "")
        .replace(trailingQuotesPattern)
        .split(" ");
      cmd = execCmd;
      execArgs.forEach(item => args.push(item));
    }

    if (isNil(cmd) === false) {
      // not running opti-node
      proc = spawn(cmd, args, opts);
    } else {
      // running with opti-node
      const optiNodeOpts = { args, opts };
      optiNodeOpts.cmd = cmd;
      proc = createProcess(optiNodeOpts);
    }

    proc.addListener("close", () => watcher.emit("proc-close"));
    proc.addListener("disconnect", () => watcher.emit("proc-disconnect"));
    proc.addListener("error", err => watcher.emit("proc-error", err));
    proc.addListener("exit", () => watcher.emit("proc-exit"));
    proc.stdout.pipe(watcher.stdout);
    proc.stderr.pipe(watcher.stderr);
  }
function respawn ( ) { if ( isNil ( proc ) === false ) { proc . stderr . removeAllListeners ( ) ; proc . stderr . end ( ) ; proc . stderr . unpipe ( ) ; proc . stdout . removeAllListeners ( ) ; proc . stdout . end ( ) ; proc . stdout . unpipe ( ) ; proc . removeAllListeners ( ) ; proc . kill ( ) ; } const { env } = process ; const opts = { env } ; const args = [ ] ; let cmd ; // run opti-node // e.g. opti-node script.js if ( exec === "" ) { args . push ( script ) ; } // execute something else if ( exec !== "" ) { const [ execCmd , ... execArgs ] = exec . trim ( ) . replace ( leadingQuotesPattern , "" ) . replace ( trailingQuotesPattern ) . split ( " " ) ; cmd = execCmd ; execArgs . forEach ( item => args . push ( item ) ) ; } if ( isNil ( cmd ) === false ) { // not running opti-node proc = spawn ( cmd , args , opts ) ; } else { // running with opti-node const optiNodeOpts = { args , opts } ; optiNodeOpts . cmd = cmd ; proc = createProcess ( optiNodeOpts ) ; } proc . addListener ( "close" , ( ) => watcher . emit ( "proc-close" ) ) ; proc . addListener ( "disconnect" , ( ) => watcher . emit ( "proc-disconnect" ) ) ; proc . addListener ( "error" , err => watcher . emit ( "proc-error" , err ) ) ; proc . addListener ( "exit" , ( ) => watcher . emit ( "proc-exit" ) ) ; proc . stdout . pipe ( watcher . stdout ) ; proc . stderr . pipe ( watcher . stderr ) ; }
Restart the child process
@private
@method respawn
Restart the child process