var compile = function(name, pipeline, opts) { pipeline = pipeline .map(function(p, i) { if (typeof p === 'string') p = {command:p} if (typeof p === 'function') p = {exports:p, module:true} if (!p.params) p.params = [].concat(name, opts.params || []) if (p.command) return compileCommand(p, opts) if (p.module) return compileModule(p, opts) throw new Error('Unsupported pipeline #'+i+' in '+name) }) return splicer(pipeline) }
var compile = function(name, pipeline, opts) { var wrap = function(i, msg, stream) { if (!process.env.DEBUG) return stream return splicer([debug('#'+i+ ' stdin: '+msg), stream, debug('#'+i+' stdout: '+msg)]) } pipeline = pipeline .map(function(p, i) { if (typeof p === 'string') p = {command:p} if (typeof p === 'function') p = {exports:p, module:true} if (!p.params) p.params = [].concat(name, opts.params || []) if (p.command) return wrap(i, '('+p.command+')', compileCommand(p, opts)) if (p.module) return wrap(i, '('+p.module+')', compileModule(p, opts)) throw new Error('Unsupported pipeline #'+i+' in '+name) }) return splicer(pipeline) }
result[key] = function(opts) { if (Array.isArray(opts)) opts = {params:opts} opts = xtend(defaults, opts) if (list.length < 2) return compile(key, list[0] || [], opts) var output = new stream.PassThrough() var s = splicer(output) var i = 0 var loop = function() { var next = compile(key, list[i++], opts) if (i === list.length) return s.unshift(next) next.on('end', function() { s.shift() loop() }) s.unshift(next) } loop() return s }
var compileModule = function(p, opts) { if (!p.exports) p.exports = require(resolve.sync(p.module, {basedir:opts.cwd})) return p.json ? splicer(ldjson.parse(), p.exports(p), ldjson.serialize()) : p.exports(p) }
var wrap = function(i, msg, stream) { if (!process.env.DEBUG) return stream return splicer([debug('#'+i+ ' stdin: '+msg), stream, debug('#'+i+' stdout: '+msg)]) }