Package Exports
- rxjs-shell
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rxjs-shell) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
rxjs-shell
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>
optionsinterface is same with nodejsexecmethod
import {exec} from 'rxjs-shell';
exec('echo Hello World')
.subscribe(output => {
console.log(output); // Hello World\n
});execFile(file[, args][, options]) → Observable<string>
optionsinterface is same with nodejsexecFilemethod
import {existSync} from 'fs';
import {execFile} from 'rxjs-shell';
execFile('./touchFile.sh')
.subscribe(() => {
console.log(existSync('touched.txt')); // true
});spawn(command[, args][, options]) → Observable<Buffer>
spawnemitsstdout,stderr's buffer from command execution.optionsinterface is same with nodejsspawnmethod
import {spawn} from 'rxjs-shell';
spawn('git clone http://github.com/johnny-mh/rxjs-shell-operators')
.pipe(tap(buf => process.stdout.write(String(buf))))
.subscribe();fork(modulePath[, args][, options]) → Observable<Buffer>
- same with
spawnbut have ownoptionsinterface that extend nodejs fork options to communicate with child process.
import {fork} from 'rxjs-shell';
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');Operators
trim(encoding = 'utf8') → Observable<string | Buffer>
- trim child process output
import {exec, trim} from 'rxjs-shell';
exec('echo Hello').subscribe(output => console.log(output)); // Hello\n
exec('echo Hello').pipe(trim()).subscribe(output => console.log(output)); // HelloUtility Methods
spawnEnd(spawnObservable: Observable) → Subject<void>
spawnemit each buffer from child process. if you want to connect other operator to this stream. usespawnEndmethod.
import {spawn, spawnEnd} from 'rxjs-shell';
spawn('webpack', ['-p'])
.pipe(outputChunk => { /* each child process's output buffer */ })
.subscribe();
spawnEnd(spawn('webpack', ['-p']))
.pipe(webpackOutput => { /* do something */ })
.subscribe();