documentify
Advanced tools
Comparing version 3.1.0 to 3.2.0
36
index.js
var parallel = require('async-collection').parallel | ||
var splicer = require('labeled-stream-splicer') | ||
var fromString = require('from2-string') | ||
@@ -70,2 +71,5 @@ var stream = require('readable-stream') | ||
opts = opts || {} | ||
if (!opts.order) opts = Object.assign({}, opts, { order: 'main' }) | ||
if (typeof transform === 'string') { | ||
@@ -95,2 +99,20 @@ var index = this.transforms.length | ||
Documentify.prototype.createPipeline = function () { | ||
var pipeline = splicer([ | ||
'start', [], | ||
'main', [], | ||
'end', [] | ||
]) | ||
this.transforms.forEach(function (tuple) { | ||
var fn = tuple[0] | ||
var opts = tuple[1] | ||
var label = opts && opts.order | ||
var transform = fn(opts) | ||
pipeline.get(label).push(transform) | ||
}) | ||
return pipeline | ||
} | ||
Documentify.prototype.bundle = function () { | ||
@@ -114,12 +136,5 @@ var pts = new stream.PassThrough() | ||
if (err) return pts.emit('error', err) | ||
var args = self.transforms.reduce(function (arr, tuple) { | ||
var fn = tuple[0] | ||
var opts = tuple[1] || {} | ||
var transform = fn(opts) | ||
arr.push(transform) | ||
return arr | ||
}, [source]) | ||
var pipeline = self.createPipeline() | ||
args.push(pts) | ||
pump.apply(pump, args) | ||
pump(source, pipeline, pts) | ||
}) | ||
@@ -165,2 +180,5 @@ } | ||
// Run package.json transforms first by default. | ||
if (!opts.order) opts.order = 'start' | ||
return function (done) { | ||
@@ -167,0 +185,0 @@ resolve(name, { basedir: basedir }, function (err, resolved) { |
@@ -5,3 +5,3 @@ { | ||
"repository": "stackhtml/documentify", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"bin": "./bin.js", | ||
@@ -20,2 +20,3 @@ "scripts": { | ||
"inherits": "^2.0.3", | ||
"labeled-stream-splicer": "^2.0.0", | ||
"pump": "^1.0.2", | ||
@@ -22,0 +23,0 @@ "readable-stream": "^2.3.3", |
@@ -1,7 +0,13 @@ | ||
var PassThrough = require('readable-stream').PassThrough | ||
var Transform = require('readable-stream').Transform | ||
module.exports = function () { | ||
var ps = PassThrough() | ||
ps.push('package.json prepend\n') | ||
return ps | ||
var first = true | ||
return Transform({ | ||
transform (chunk, enc, cb) { | ||
if (first) this.push('package.json prepend\n') | ||
first = false | ||
this.push(chunk) | ||
cb(null) | ||
} | ||
}) | ||
} |
var test = require('tape') | ||
var path = require('path') | ||
var Transform = require('readable-stream').Transform | ||
var PassThrough = require('readable-stream').PassThrough | ||
var concat = require('concat-stream') | ||
@@ -50,6 +49,6 @@ var documentify = require('../') | ||
var lines = result.split(/\n/g) | ||
t.equal(lines.shift(), '.transform prepend') | ||
t.equal(lines.shift(), 'package.json prepend') | ||
t.equal(lines.pop(), '.transform append') | ||
t.equal(lines.pop(), 'package.json append') | ||
t.equal(lines[0], '.transform prepend') | ||
t.equal(lines[1], 'package.json prepend') | ||
t.equal(lines[lines.length - 2], 'package.json append') | ||
t.equal(lines[lines.length - 1], '.transform append') | ||
})) | ||
@@ -60,5 +59,11 @@ }) | ||
function prepend (text) { | ||
var ps = PassThrough() | ||
ps.push(text + '\n') | ||
return ps | ||
var first = true | ||
return Transform({ | ||
write (chunk, enc, cb) { | ||
if (first) this.push(text + '\n') | ||
first = false | ||
this.push(chunk) | ||
cb() | ||
} | ||
}) | ||
} | ||
@@ -65,0 +70,0 @@ function append (text) { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
19166
487
0
11
+ Addedlabeled-stream-splicer@2.0.2(transitive)
+ Addedstream-splicer@2.0.1(transitive)