outpipe / 1.1.1 last updated a year ago created on Mar 8th 2015
Install
npm install --save outpipe
Clone
git clone git@github.com:substack/outpipe.git
dependencies
| main |
|
shell-quote | 1.5.0 | MIT |
maintainers
versions
| 1.1.1 | a year ago | substack |
| 1.1.0 | a year ago | substack |
| 1.0.2 | a year ago | substack |
| 1.0.1 | a year ago | substack |
| 1.0.0 | a year ago | substack |
readme
outpipe
write output to a file through shell commands
purpose
Suppose you have a tool like watchify or factor-bundle that write to multiple files or write to the same file more than once.
If you want to pipe the output of these tools to other programs, such as
minification with the uglify command, it's very difficult! You might need to
use the tool's API or use a separate command to watch for changes to the output
files. Ick.
You don't get the elegance of something like:
Until now! With this library and a hypothetical version of watchify, you could do:
example
Here's a small watcher program that will just copy input files to a destination, but transforms can be applied along the way with shell pipes and redirects.
We can run the program with a single output file:
which just copies x.js to output/hmm.js whenever x.js changes.
We could also run a minification step using the uglify command:
or we can just print the size of the minified and gzipped output to stdout:
or we could write that size to a file:
methods
var w = outpipe(cmd, opts={})
Return a writable stream w that will pipe output to the command string cmd.
If cmd has no operators (| or >), it will write to a file.
Otherwise, each command between pipes will be executed and output is written to
a file if > is given.
opts can be:
opts.env- an object mapping environment variables to their values or afunction (key) {}that returns the values.
stdout and stderr are forwarded to process.stdout and process.stderr if unhandled in the command.
install
With npm do:
license
MIT