.\" Generated by mkdoc on July, 2016
.TH "MKTRANSFORM" "1" "July, 2016" "mktransform 1.0.5" "User Commands"
.de nl
.sp 0
..
.de hr
.sp 1
.nf
.ce
.in 4
\l’80’
.fi
..
.de h1
.RE
.sp 1
\fB\\$1\fR
.RS 4
..
.de h2
.RE
.sp 1
.in 4
\fB\\$1\fR
.RS 6
..
.de h3
.RE
.sp 1
.in 6
\fB\\$1\fR
.RS 8
..
.de h4
.RE
.sp 1
.in 8
\fB\\$1\fR
.RS 10
..
.de h5
.RE
.sp 1
.in 10
\fB\\$1\fR
.RS 12
..
.de h6
.RE
.sp 1
.in 12
\fB\\$1\fR
.RS 14
..
.h1 "NAME"
.P
mktransform \- custom stream transformations
.nl
.h1 "SYNOPSIS"
.P
mktransform [\-h] [\-\-help] [\-\-version] [files...]
.nl
.h1 "DESCRIPTION"
.P
Processes the input stream on stdin using the specified stream transformation files.
.nl
.h1 "OPTIONS"
.TP
\fB\-h, \-\-help\fR
 Display help and exit
.nl
.TP
\fB\-\-version\fR
 Print the version and exit
.nl
.h1 "STREAM FUNCTIONS"
.P
A stream function has the signature:
.nl
.PP
.in 12
function(through, ast, opts)
.P
It is passed the [through][] module so you can easily create stream transform classes and [ast][mkast] so you may easily inspect nodes; the \fBopts\fR object is the original options object. The function \fBmust\fR return a transform stream subclass.
.nl
.P
The input and output data should always be abstract syntax tree nodes.
.nl
.P
To create a transform stream subclass:
.nl
.PP
.in 12
function transformer(through) {
.br

.br
  function transform(chunk, encoding, cb) {
.br
    // pass through stream
.br
    cb(null, chunk);
.br
  }
.br

.br
  // return the stream subclass
.br
  return through.transform(transform);
.br
}
.br

.br
module.exports = transformer;
.P
If you also need a \fBflush\fR function:
.nl
.PP
.in 12
function transformer(through) {
.br

.br
  function transform(chunk, encoding, cb) {
.br
    cb(null, chunk);
.br
  }
.br

.br
  function flush(cb) {
.br
    cb(); 
.br
  }
.br

.br
  return through.transform(transform, flush);
.br
}
.br

.br
module.exports = transformer;
.P
To use a specific constructor:
.nl
.PP
.in 12
function transformer(through) {
.br

.br
  function Component(opts) {
.br
    this.opts = opts || {}; 
.br
  }
.br

.br
  function transform(chunk, encoding, cb) {
.br
    cb(null, chunk);
.br
  }
.br

.br
  return through.transform(transform, {ctor: Component});
.br
}
.br

.br
module.exports = transformer;
.P
See [through][through], [ast][mkast] and the api docs[1] for more detail.
.nl
.h1 "EXAMPLE"
.P
Run a custom stream transformation:
.nl
.PP
.in 12
mkcat README.md | mktransform doc/upper.js | mkout
.P
Run multiple transformations:
.nl
.PP
.in 12
mkcat README.md | mktransform test/fixtures/upper1.js test/fixtures/upper2.js | mkout