outpipe

WebJar for outpipe

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

outpipe
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

outpipe
WebJar for outpipe
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/substack/outpipe

Download outpipe

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/outpipe/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>outpipe</artifactId>
    <version>1.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/outpipe/
implementation 'org.webjars.npm:outpipe:1.1.1'
// https://jarcasting.com/artifacts/org.webjars.npm/outpipe/
implementation ("org.webjars.npm:outpipe:1.1.1")
'org.webjars.npm:outpipe:jar:1.1.1'
<dependency org="org.webjars.npm" name="outpipe" rev="1.1.1">
  <artifact name="outpipe" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='outpipe', version='1.1.1')
)
libraryDependencies += "org.webjars.npm" % "outpipe" % "1.1.1"
[org.webjars.npm/outpipe "1.1.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : shell-quote jar [1.4.2,2)

Project Modules

There are no modules declared in this project.

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:

$ browserify main.js | uglifyjs -cm | gzip > bundle.js.gz

Until now! This library is what enables watchify to do:

$ watchify main.js -dv -o 'uglifyjs -cm | gzip > bundle.js.gz'

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.

var outpipe = require('outpipe');
var gaze = require('gaze');
var fs = require('fs');

var minimist = require('minimist');
var argv = minimist(process.argv.slice(2), {
    alias: { o: 'output' }
});

var file = argv._[0];
gaze(file, function (err, w) {
    w.on('changed', read);
});
read();

function read () {
    var r = fs.createReadStream(file);
    r.pipe(outpipe(argv.output));
}

We can run the program with a single output file:

$ node watch.js input/x.js -o output/hmm.js

which just copies x.js to output/hmm.js whenever x.js changes.

We could also run a minification step using the uglify command:

$ node watch.js input/x.js -o 'uglifyjs -cm > output/wow.js'

or we can just print the size of the minified and gzipped output to stdout:

$ node watch.js input/x.js -o 'uglifyjs -cm | gzip | wc -c'
123

or we could write that size to a file:

$ node watch.js input/x.js -o 'uglifyjs -cm | gzip | wc -c > size.txt'

methods

var outpipe = require('outpipe')

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 a function (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:

npm install outpipe

license

MIT

Versions

Version
1.1.1