0.0.2 • Published 6 years ago

rxjs-shell-operators v0.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

rxjs-shell-operators

travisci

rxjs operators for execute shell command with ease.

Features

  • Wrap nodejs asynchronous process creation methods to rxjs Observable.
  • Kill child process when unsubscribed.
  • Use subject to communicate with child process.

Functions

exec(command, options) → Observable\<string>

  • options interface is same with nodejs exec method
import {exec} from 'rxjs-shell-operators';

exec('echo Hello World')
  .subscribe(output => {
    console.log(output); // Hello World\n
  });

execFile(file, args) → Observable\<string>

  • options interface is same with nodejs execFile method
import {existSync} from 'fs';
import {execFile} from 'rxjs-shell-operators';

execFile('./touchFile.sh')
  .subscribe(() => {
    console.log(existSync('touched.txt')); // true
  });

spawn(command, args) → Observable\<Buffer>

  • spawn emits stdout, stderr's buffer from command execution.
  • options interface is same with nodejs spawn method
import {spawn} from 'rxjs-shell-operators';

spawn('git clone http://github.com/johnny-mh/rxjs-shell-operators')
  .pipe(tap(buf => process.stdout.write(String(buf))))
  .subscribe();

fork(modulePath, args) → Observable\<Buffer>

  • same with spawn but have own options interface that extend nodejs fork options to communicate with child process.
import {fork} from 'rxjs-shell-operators';
import {Subject} from 'rxjs';

const send = new Subject<string>();
const recv = new Subject<string>();

recv.subscribe(msgFromChildProc => console.log(msgFromChildProc));

fork('echo.js', undefined, {send, recv}).subscribe();

send.next('message to child process');