Exemple #1
0
var through = require('through2');
var a = through.obj(function (x, e, next) { this.push(x+1); next() });
var b = through.obj(function (x, e, next) { this.push(x/3); next() });
var c = through.obj(function (x, e, next) { this.push(x*100); next() });

var splicer = require('labeled-stream-splicer');
var p = splicer.obj([ 'A', [a], 'B', [b], 'C', [c] ]);

// p.get('B').push(through.obj(function (x,e,next) { this.push(x*5); next() }));

p.on('data', console.log);
p.write(5);
p.write(6);
p.write(7);
Exemple #2
0
module.exports.stream = function (buf, name) {
	var stream = through.obj();
	stream.end(module.exports.file(buf, name));
	return stream;
};
Exemple #3
0
module.exports = function (url) {
    var geomType;
    var out = through(function (feature, _, callback) {
        this.push(feature);
        callback();
    });

    // Validate URL is a "/rest/services/" endpoint
    if (url.indexOf('/rest/services/') === -1) {
      return out.emit('error', new Error('Did not recognize ' + url + ' as an ArcGIS /rest/services/ endpoint.'));
    }

    // Extract API resource type from url. One of FeatureServer, MapServer, or ImageServer
    var supported = ['FeatureServer', 'MapServer', 'ImageServer'];
    var occurrence = supported.map(function(d) {
      return url.lastIndexOf(d);
    });
    var resourceType = supported[occurrence.indexOf(Math.max.apply(null, occurrence))];

    request.get({ url: url, qs: {f: 'json'}, json: true }, function (error, response, metadata) {
        if (error) return out.emit('error', error);
        if (response.statusCode !== 200) return out.emit('error', new Error('Received ' + response.statusCode + ' response code'));
        if (metadata.error) return out.emit('error', new Error('Server metadata error: ' + metadata.error.message));

        switch (resourceType) {
          case 'FeatureServer':
          case 'MapServer':

            out.emit('type', resourceType);
            if (metadata.capabilities && metadata.capabilities.indexOf('Query') === -1 ) {
                return out.emit('error', new Error('Layer doesn\'t support query operation.'));
            }

            geomType = metadata.geometryType;
            if (!geomType) {
                return out.emit('error', new Error('no geometry'));
            } else if (!metadata.extent) {
                return out.emit('error', new Error('Layer doesn\'t list an extent.'));
            } else if ('subLayers' in metadata && metadata.subLayers.length > 0) {
                return out.emit('error', 'Specified layer has sublayers.');
            }

            new Geometry(url, metadata).pipe(out);

            break;

          case 'ImageServer':

            out.emit('type', 'ImageServer');
            if (metadata.capabilities && metadata.capabilities.indexOf('Download') === -1 ) {
                return out.emit('error', new Error('Layer doesn\'t support download operation.'));
            }

            new Imagery_raw(url, metadata).pipe(out);

            break;

          default:
            if (metadata.folders|| metadata.services) {
              var errorMessage = 'Endpoint provided is not a Server resource.\n';
              if (metadata.folders.length > 0) {
                errorMessage += '\nChoose a Layer from a Service in one of these Folders: \n  '
                  + metadata.folders.join('\n  ') + '\n';
              }
              if (metadata.services.length > 0) {
                errorMessage += '\nChoose a Layer from one of these Services: \n  '
                  + metadata.services.map(function(d) { return d.name }).join('\n  ') + '\n';
              }
              return out.emit('error', new Error(errorMessage));
            } else if (metadata.layers) {
              var errorMessage = 'Endpoint provided is not a Server resource.\n';
              if (metadata.layers.length > 0) {
                errorMessage += '\nChoose one of these Layers: \n  '
                  + metadata.layers.map(function(d) { return d.name }).join('\n  ') + '\n';
              }
              return out.emit('error', new Error(errorMessage));
            } else {
              return out.emit('error', new Error('Could not determine server type of ' + url));
            }
        }

    });

    return out;
};
Exemple #4
0
    countDocs(function (err, docCount) {
      if (err) {
        return callback(err);
      }
      var readstreamOpts = {};
      var skip = opts.skip || 0;
      if (opts.startkey) {
        readstreamOpts.start = opts.startkey;
      }
      if (opts.endkey) {
        readstreamOpts.end = opts.endkey;
      }
      if (opts.key) {
        readstreamOpts.start = readstreamOpts.end = opts.key;
      }
      if (opts.descending) {
        readstreamOpts.reverse = true;
        // switch start and ends
        var tmp = readstreamOpts.start;
        readstreamOpts.start = readstreamOpts.end;
        readstreamOpts.end = tmp;
      }
      var limit;
      if (typeof opts.limit === 'number') {
        limit = opts.limit;
      } else {
        limit = -1;
      }
      if (limit === 0 ||
          ('start' in readstreamOpts && 'end' in readstreamOpts &&
          readstreamOpts.start > readstreamOpts.end)) {
        // should return 0 results when start is greater than end.
        // normally level would "fix" this for us by reversing the order,
        // so short-circuit instead
        return callback(null, {
          total_rows: docCount,
          offset: opts.skip,
          rows: []
        });
      }
      var results = [];
      var docstream = stores.docStore.readStream(readstreamOpts);

      var throughStream = through(function (entry, _, next) {
        if (!utils.isDeleted(entry.value)) {
          if (skip-- > 0) {
            next();
            return;
          } else if (limit-- === 0) {
            docstream.unpipe();
            docstream.destroy();
            next();
            return;
          }
        } else if (opts.deleted !== 'ok') {
          next();
          return;
        }
        function allDocsInner(metadata, data) {
          var doc = {
            id: metadata.id,
            key: metadata.id,
            value: {
              rev: merge.winningRev(metadata)
            }
          };
          if (opts.include_docs) {
            doc.doc = data;
            doc.doc._rev = doc.value.rev;
            if (opts.conflicts) {
              doc.doc._conflicts = merge.collectConflicts(metadata);
            }
            for (var att in doc.doc._attachments) {
              if (doc.doc._attachments.hasOwnProperty(att)) {
                doc.doc._attachments[att].stub = true;
              }
            }
          }
          if (opts.inclusive_end === false && metadata.id === opts.endkey) {
            return next();
          } else if (utils.isDeleted(metadata)) {
            if (opts.deleted === 'ok') {
              doc.value.deleted = true;
              doc.doc = null;
            } else {
              return next();
            }
          }
          results.push(doc);
          next();
        }
        var metadata = entry.value;
        if (opts.include_docs) {
          var seq = metadata.rev_map[merge.winningRev(metadata)];
          stores.bySeqStore.get(formatSeq(seq), function (err, data) {
            allDocsInner(metadata, data);
          });
        }
        else {
          allDocsInner(metadata);
        }
      }, function (next) {
        callback(null, {
          total_rows: docCount,
          offset: opts.skip,
          rows: results
        });
        next();
      }).on('unpipe', function () {
        throughStream.end();
      });

      docstream.on('error', callback);

      docstream.pipe(throughStream);
    });
function gulpCssBase64(opts) {

    opts = opts || {};
    opts.maxWeightResource = opts.maxWeightResource || 32768;
    if (util.isArray(opts.extensionsAllowed)) {
        opts.extensionsAllowed = opts.extensionsAllowed;
    } else {
        opts.extensionsAllowed = [];
    }
    opts.extensionsAllowed = opts.extensionsAllowed || [];
    opts.baseDir = opts.baseDir || '';
    opts.verbose = process.argv.indexOf('--verbose') !== -1;

    // Creating a stream through which each file will pass
    var stream = through.obj(function (file, enc, callbackStream) {

        var currentStream = this;
        var cache = [];

        if (file.isNull()) {
            // Do nothing if no contents
            currentStream.push(file);

            return callbackStream();
        }

        if (file.isBuffer()) {
            var src = file.contents.toString();
            var result = [];

            async.whilst(
                function () {
                    result = rImages.exec(src);

                    return result !== null;
                },
                function (callback) {
                    if (cache[result[1]]) {
                        src = src.replace(result[1], cache[result[1]]);
                        callback();
                        return;
                    }

                    if (opts.extensionsAllowed.length !== 0 && opts.extensionsAllowed.indexOf(path.extname(result[1])) == -1) {
                        log('Ignores ' + chalk.yellow(result[1]) + ', extension not allowed ' + chalk.yellow(path.extname(result[1])), opts.verbose);
                        callback();
                        return;
                    }

                    encodeResource(result[1], file, opts, function (fileRes) {
                        if (undefined !== fileRes) {

                            if (fileRes.contents.length > opts.maxWeightResource) {
                                log('Ignores ' + chalk.yellow(result[1]) + ', file is too big ' + chalk.yellow(fileRes.contents.length + ' bytes'), opts.verbose);
                                callback();
                                return;
                            }

                            var strRes = 'data:' + mime.lookup(fileRes.path) + ';base64,' + fileRes.contents.toString('base64');
                            src = src.replace(result[1], strRes);

                            // Store in cache
                            cache[result[1]] = strRes;
                        }
                        callback();
                    });
                },
                function () {
                    file.contents = new Buffer(src);
                    currentStream.push(file);

                    return callbackStream();
                }
            );
        }

        if (file.isStream()) {
            this.emit('error', new gutil.PluginError('gulp-css-base64', 'Stream not supported!'));
        }
    });

    // returning the file stream
    return stream;
}
module.exports = function (moduleName, dependencyTree, generateIndex, perFile, shaders, shaderIncludes) {
    return through.obj(function (file, enc, cb) {

        let basename = (path.basename(file.path, ".js"));

        //console.log("Compiling module: " + moduleName + "/" + basename.replace("babylon.", ""));

        var extendsAddition =
            `var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
`;

        var decorateAddition =
            'var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};\n';

        let content = file.contents.toString();
        if (content.indexOf('__extends') === -1 && !dependencyTree.length) {
            extendsAddition = '';
        }

        if (content.indexOf('__decorate') === -1) {
            decorateAddition = '';
        }

        let dependenciesText = `${extendsAddition}
${decorateAddition}
if(typeof require !== 'undefined'){
    var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
    var BABYLON = globalObject["BABYLON"] || {}; 
    var EXPORTS = {};
`;
        let exportsText = '';
        if (!generateIndex) {
            let loadedFiles = [];
            dependencyTree[basename].forEach(function (d, idx) {
                if (d.module.indexOf("core") !== -1) return;
                let name = d.file.split(".").pop();

                if (loadedFiles.indexOf(name) === -1) {
                    if (d.main)
                        dependenciesText += `var ${name}Module = require('babylonjs/${d.module[0]}/${name}');
`;
                    else
                        exportsText += `var ${name}Module = require('babylonjs/${d.module[0]}/${name}');
`;
                    loadedFiles.push(name);
                }

                dependenciesText += `BABYLON["${d.name}"] = ${name}Module["${d.name}"];
`;
                //dependenciesText += `if(BABYLON !== BABYLON${idx}) __extends(BABYLON, BABYLON${idx});
            });
            perFile[basename].declarations.forEach(dec => {
                exportsText += `EXPORTS['${dec}'] = BABYLON["${dec}"];
`;
            });
            if (shaders) {
                dependenciesText += `require("babylonjs/${moduleName}/shaders");
`;
            }
            if (shaderIncludes) {
                dependenciesText += `require("babylonjs/${moduleName}/shaderIncludes");
`;
            }
        } else {
            content = '';
            let basenames = Object.keys(perFile).filter(basefilename => {
                return perFile[basefilename].module.indexOf(moduleName) !== -1;
            });

            basenames.forEach(bname => {
                let name = bname.split(".").pop();
                dependenciesText += `var ${name} = require("babylonjs/${moduleName}/${name}");
`;
                // now add the internal dependencies to EXPORTS
                perFile[bname].declarations.forEach(dec => {
                    dependenciesText += `EXPORTS['${dec}'] = BABYLON["${dec}"] = ${name}["${dec}"];
`;
                });
            })
        }

        exportsText += `(function() {
    globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
    module.exports = EXPORTS;
    })();
}`;



        /*let exportRegex = /BABYLON.([0-9A-Za-z-_]*) = .*;\n/g

        var match = exportRegex.exec(content);

        let exportsArray = [];
        while (match != null) {
            if (match[1]) {
                exportsArray.push(match[1])
            }
            match = exportRegex.exec(content);
        }*/


        /*if (moduleName === "core") {
            exportsText = `(function() {
    globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
    module.exports = BABYLON; 
})();
}`
        }*/

        if (file.isNull()) {
            cb(null, file);
            return;
        }

        if (file.isStream()) {
            //streams not supported, no need for now.
            return;
        }

        try {
            file.contents = new Buffer(dependenciesText.concat(new Buffer(String(content).concat(exportsText))));
            this.push(file);
        } catch (err) {
            this.emit('error', new gutil.PluginError('gulp-add-babylon-module', err, { fileName: file.path }));
        }
        cb();
    });
}
Exemple #7
0
module.exports = function conflict (dest, opt) {
  if (!dest) {
    error('Missing destination dir parameter!');
  }

  opt = opt || {};

  var replaceAll = opt.replaceAll || false;
  var skipAll = opt.skipAll || false;

  return through2.obj(function (file, enc, cb) {
    var newPath = path.resolve(opt.cwd || process.cwd(), dest, file.relative);
    fs.stat(newPath, function (err, stat) {
      if (!replaceAll && stat && !stat.isDirectory()) {
        fs.readFile(newPath, 'utf8', function (err, contents) {
          if (err) {
            error('Reading old file for comparison failed with: ' + err.message);
          }
          if (contents === String(file.contents)) {
            log('Skipping ' + file.relative + ' (identical)');
            return cb();
          }

          if (skipAll) {
            log('Skipping ' + file.relative);
            return cb();
          }

          var askCb = function askCb (action) {
            switch (action) {
              case 'replaceAll':
                replaceAll = true;
                /* falls through */
              case 'replace':
                log('Keeping ' + file.relative);
                this.push(file);
                break;
              case 'skipAll':
                skipAll = true;
                /* falls through */
              case 'skip':
                log('Skipping ' + file.relative);
                break;
              case 'end':
                log(gutil.colors.red('Aborting...'));
                process.exit(0);
                break;
              case 'diff':
                log('Showing diff for ' + file.relative);
                diffFiles(file, newPath);
                ask(file, askCb.bind(this));
                return;
            }
            cb();
          };
          ask(file, askCb.bind(this));
        }.bind(this));
      } else {
        log('Keeping ' + file.relative);
        this.push(file);
        cb();
      }
    }.bind(this));
  });
};
Exemple #8
0
module.exports = function(opts, data){
  opts = opts || {};
  data = data || {};

  ['noParse', 'extensions', 'resolve'].forEach(function(opt){
    if(opts[opt]) {
      data[opt] = opts[opt];
      delete opts[opt];
    }
  });


  function transform(file, enc, cb){
    var self = this;
    var dest;

    if (opts.dest) {
      dest = path.join(opts.dest, file.relative);
    }

    if (file.isStream()) {
      self.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported'));
      return cb();
    }

    // browserify accepts file path or stream.

    if(file.isNull()) {
      data.entries = file.path;
    }

    if(file.isBuffer()) {
      data.entries = arrayStream([file.contents]);
    }

    if (!isNewer(file.path, dest)) {
        return cb();
    }

    data.basedir = opts.basedir = path.dirname(file.path);

    depCache[file.path] = [];
    // nobuiltins option
    if (!opts.builtins && opts.nobuiltins) {
      var nob = opts.nobuiltins;
      var builtins = require('./node_modules/browserify/lib/builtins.js');
      nob = 'string' == typeof nob ? nob.split(' ') : nob;

      for (var i = 0; i < nob.length; i++) {
        delete builtins[nob[i]];
      };

      opts.builtins = builtins;
    }

    var bundler = browserify(data, opts);
    bundler.on('dep', addDependency.bind(file));

    if(opts.shim) {
      for(var lib in opts.shim) {
          opts.shim[lib].path = path.resolve(opts.shim[lib].path);
      }
      bundler = shim(bundler, opts.shim);
    }

    bundler.on('error', function(err) {
      self.emit('error', wrapWithPluginError(err));
      cb();
    });

    [
      'exclude',
      'add',
      'external',
      'transform',
      'ignore',
      'require'
    ].forEach( function(method) {
      if (!opts[method]) return;
      [].concat(opts[method]).forEach(function (args) {
        bundler[method].apply(bundler, [].concat(args));
      });
    });

    self.emit('prebundle', bundler);

    // Cache dependency info when building multiple files to speed up bundling
    var bundle = bundler.bundle.bind(bundler);
    bundler.bundle = function (opts_, cb) {
        opts_.cache = cache;
        bundle(opts_, cb);
    };

    var bStream = bundler.bundle(opts, function(err, src){
      if(err) {
        self.emit('error', wrapWithPluginError(err));
      } else {
        self.emit('postbundle', src);

        file.contents = new Buffer(src);
        self.push(file);
      }

      cb();
    });
  }

  return through.obj(transform, function () {
      cache = {};
      this.emit('end');
  });
};
module.exports = function (config) {
	"use strict";

	config = config || {};
	var origin = config.filename || "urls.json",
		subOjects = typeof config.subOjects !== 'undefined' ? config.subOjects : true,
		firstFile,
		directoryStructure = {};

	function directoryMap(file, enc, callback) {
		/*jshint validthis:true*/

		if (!firstFile) {
      firstFile = file;
    }

		// Do nothing if no contents
		if (!file.isDirectory() && file.isNull()) {
			this.emit("error", new gutil.PluginError("gulp-directory-map", "File is null"));
			this.emit("end");
			return callback();
		}

		// No support for streams yet.
		if (file.isStream()) {
			this.emit("error", new gutil.PluginError("gulp-directory-map", "No stream support!"));
			this.emit("end");
			return callback();
		}

		// But if it's a buffer...!
		if (file.isBuffer()) {
			var path = (config.prefix ? config.prefix + "/" : "") + file.path.replace(file.base, "");
			var segments = path.replace(/\\/g,"/").split("/");
			var parent = directoryStructure;

			segments.forEach(function(seg, index){
				if (index === segments.length-1){
					parent[seg] = path.replace(/\\/g,"/");
				} else if(subOjects) {
					parent[seg] = parent[seg] || {};
					parent = parent[seg];
				}
			});
		}
		return callback();
	}

	return through.obj(directoryMap,
		function(cb) {
			if (isEmpty(directoryStructure)) {
				this.emit("error", new gutil.PluginError("gulp-directory-map", "No files found for directoryMap"));
				this.emit("end");
				return cb();
			}

			//create and push new vinyl file
			this.push(new gutil.File({
				cwd: firstFile.cwd,
				base: firstFile.cwd,
				path: path.join(firstFile.cwd, origin),
				contents: new Buffer(JSON.stringify(directoryStructure))
			}));

			gutil.log("Generated", gutil.colors.blue(config.filename));
			return cb();
		});
};
Exemple #10
0
function complexity(options){
	options = extend({
		cyclomatic: [3, 7, 12],
		halstead: [8, 13, 20],
		maintainability: 100,
		breakOnErrors: true
	}, options);

	// always making sure threasholds are arrays
	if(!Array.isArray(options.cyclomatic)){
		options.cyclomatic = [options.cyclomatic];
	}

	if(!Array.isArray(options.halstead)){
		options.halstead = [options.halstead];
	}

	var files = [];
	var errorCount = 0;

	return through.obj(function(file, enc, cb){
		if(file.isNull()){
			return cb(null, file);
		}

		if(file.isStream()){
			return cb(new PluginError('gulp-complexity', 'Streaming not supported'));
		}

		files.push(file);
		cb(null, file);
	}, function(cb){
		var path = require('path'),
			helpers = require('./reporter-helpers');

		var maxLength = helpers.longestString(files.map(function(file){
			return path.relative(file.cwd, file.path);
		}));

		files.filter(function(file){
			return file.contents.toString().length > 0;
		}).forEach(function(file){
			var base = path.relative(file.cwd, file.path);
			var report = cr.run(file.contents.toString(), options);

			errorCount += report.functions.filter(function(data){
				return (data.complexity.cyclomatic > options.cyclomatic[0]) || (data.complexity.halstead.difficulty > options.halstead[0]);
			}).length;
			if (report.maintainability < options.maintainability) {
				errorCount++;
			}

			reporter.log(file, report, options, helpers.fitWhitespace(maxLength, base));
		});

		if(options.breakOnErrors && errorCount > 0) {
			this.emit('error', new PluginError('gulp-complexity', 'Complexity too high'));
		}

		cb();
	});
}
Exemple #11
0
module.exports.stop = function () {
    var through = through2.obj();
    through._unplumbed = true;
    return through;
};
Exemple #12
0
module.exports = function gulpGhPages(options) {
  options = options || {};
  var origin = options.origin || 'origin';
  var branch = options.branch || 'gh-pages';
  var message = options.message || 'Update ' + new Date().toISOString();

  var filePaths = [];
  var TAG;
  if (branch !== 'gh-pages') {
    TAG = '[gh-pages (' + branch + ')]';
  } else {
    TAG = '[gh-pages]';
  }

  return through.obj(function collectFiles(file, enc, cb) {
    if (file.isNull()) {
      cb(null, file);
      return;
    }

    if (file.isStream()) {
      cb(new gutil.PluginError('gulp-gh-pages', 'Stream content is not supported'));
      return;
    }

    filePaths.push(file);
    cb();

  }, function publish(cb) {
    if (filePaths.length === 0) {
      gutil.log(TAG, 'No files in the stream.');
      cb();
      return;
    }

    var newBranchCreated = false;

    git.prepareRepo(options.remoteUrl, origin, options.cacheDir || '.publish')
    .then(function(repo) {
      gutil.log(TAG, 'Cloning repo');
      if (repo._localBranches.indexOf(branch) > -1) {
        gutil.log(TAG, 'Checkout branch `' + branch + '`');
        return repo.checkoutBranch(branch);
      }

      if (repo._remoteBranches.indexOf(origin + '/' + branch) > -1) {
        gutil.log(TAG, 'Checkout remote branch `' + branch + '`');
        return repo.checkoutBranch(branch);
      }

      gutil.log(TAG, 'Create branch `' + branch + '` and checkout');
      newBranchCreated = true;
      return repo.createAndCheckoutBranch(branch);
    })
    .then(function(repo) {
      return wrapPromise(function(resolve, reject) {
        if (newBranchCreated) {
          resolve(repo);
          return;
        }

        // updating to avoid having local cache not up to date
        gutil.log(TAG, 'Updating repository');
        repo._repo.git('pull', function(err) {
          if (err) {
            reject(err);
            return;
          }
          resolve(repo);
        });
      });
    })
    .then(function(repo) {
      // remove all files
      return wrapPromise(function(resolve, reject) {
        repo._repo.remove('.', {r: true}, function(err) {
          if (err) {
            reject(err);
            return;
          }
          resolve(repo.status());
        });
      });
    })
    .then(function(repo) {
      gutil.log(TAG, 'Copying files to repository');

      return wrapPromise(function(resolve, reject) {
        var destStream = vinylFs.dest(repo._repo.path)
        .on('error', reject)
        .on('end', function() {
          resolve(repo);
        });

        filePaths.forEach(function(file) {
          destStream.write(file);
        });

        destStream.end();
      });
    })
    .then(function(repo) {
      return repo.addFiles('.', {force: options.force || false});
    })
    .then(function(repo) {
      var filesToBeCommitted = Object.keys(repo._staged).length;
      if (filesToBeCommitted === 0) {
        gutil.log(TAG, 'No files have changed.');
        cb();
        return;
      }

      gutil.log(TAG, 'Adding ' + filesToBeCommitted + ' files.');
      gutil.log(TAG, 'Committing "' + message + '"');
      repo.commit(message).then(function(newRepo) {
        if (options.push === undefined || options.push) {
          gutil.log(TAG, 'Pushing to remote.');
          newRepo._repo.git('push', {
            'set-upstream': true
          }, [origin, newRepo._currentBranch], function(err) {
            if (err) {
              cb(err);
              return;
            }
            cb();
          });
          return;
        }
        cb();
      }, cb);
    })
    .catch(function(err) {
      setImmediate(function() {
        cb(new gutil.PluginError('gulp-gh-pages', err));
      });
    });
  });
};
Exemple #13
0
 function inspect () {
   return through.obj(function (file, enc, cb) {
     files.push(file.relative)
     cb(null, file)
   })
 }
Exemple #14
0
module.exports = function() {
  return through.obj(render.bind(this));
}
Exemple #15
0
util.taskDone = done => {
    return through2.obj((data, enc, cb) => cb(), cb => {
        cb();
        done();
    });
};
Exemple #16
0
module.exports = function (opts, cmdArguments) {

	var stream = through.obj(function(file, enc, callback) {
		this.push(file);
		callback();
	});

	if (toString.call(opts) === '[object String]') {
		opts = {
			directory: opts
		};
	}

	opts = opts || {};
	opts.cwd = opts.cwd || process.cwd();

	if (!opts.directory) {
		var bowerrc = path.join(opts.cwd, '.bowerrc');
		if (fs.existsSync(bowerrc)) {
			var bower_config = JSON.parse(fs.readFileSync(bowerrc));
			opts.directory = bower_config.directory;
		}
		opts.directory = opts.directory || './bower_components';
	}

	var dir = opts.directory;
	gutil.log("Using cwd: ", opts.cwd);
	gutil.log("Using bower dir: ", dir);

	var cmd = opts.cmd || 'install';
	delete(opts.cmd);

	if (toString.call(cmdArguments) !== '[object Array]') {
		cmdArguments = [];
	}
	if (toString.call(cmdArguments[0]) !== '[object Array]') {
		cmdArguments[0] = [];
	}
	cmdArguments[1] = cmdArguments[1] || {};
	cmdArguments[2] = opts;

	bower.commands[cmd].apply(bower.commands, cmdArguments)
		.on('log', function(result) {
			gutil.log(['bower', gutil.colors.cyan(result.id), result.message].join(' '));
		})
		.on('error', function(error) {
			stream.emit('error', new gutil.PluginError('gulp-bower', error));
			stream.end();
		})
		.on('end', function() {
			var baseDir = path.join(opts.cwd, dir);
			var walker = walk.walk(baseDir);
			walker.on("errors", function(root, stats, next) {
				stream.emit('error', new gutil.PluginError('gulp-bower', stats.error));
				next();
			});
			walker.on("directory", function(root, stats, next) {
				next();
			});
			walker.on("file", function(root, stats, next) {
				var filePath = path.resolve(root, stats.name);

				fs.readFile(filePath, function(error, data) {
					if (error)
						stream.emit('error', new gutil.PluginError('gulp-bower', error));
					else
						stream.write(new gutil.File({
							path: path.relative(baseDir, filePath),
							contents: data
						}));

					next();
				});
			});
			walker.on("end", function() {
				stream.end();
			});
		});

	return stream;
};
	module.exports[plugin] = optional('imagemin-' + plugin) || function () {
		return through.obj();
	};
Exemple #18
0
var parse = require('parse-dictd');
var through = require('through2');
var fs = require('fs');
var gunzip = require('zlib').createGunzip;
var minimist = require('minimist');

var db = require('level')('/tmp/dict.db');
var ddb = require('dictdb')(db);

var argv = minimist(process.argv.slice(2));

var dstream = fs.createReadStream(argv._[0]).pipe(gunzip());
var istream = fs.createReadStream(argv._[1]);

parse(dstream, istream).pipe(through.obj(function (row, enc, next) {
    var a = { word: fix(row.from), lang: argv.from };
    var b = { word: row.to.map(fix), lang: argv.to };
    ddb.link(a, b);
    next();
}));

function fix (w) { return w.replace(/^\w+\.\s*|;$/g,'') }
var githubPrivateAtomFeed = require('.');

var through2 = require('through2'),
    es = require('event-stream'),
    _each = require('lodash.foreach');

var githubPrivateAtomUrl = "GITHUB-PRIVATE-ATOM-URL";

// Promise
githubPrivateAtomFeed(githubPrivateAtomUrl).then(function(data){
  console.log(data);
}).catch(function(err){
  console.log(err);
});

// ReadableStream
githubPrivateAtomFeed.stream(githubPrivateAtomUrl).pipe(through2.obj(function(o,e,next){
  var self = this;
  _each(o,function(d){
    self.push(d);
  });
  next();
}))
.pipe(es.map(function(data,next){
  next(null,data.title);
})).on('data',console.log).on('error',console.log);

Exemple #20
0
module.exports.parse = function(path, map) {
  var parser = new Parser()

  var stream = through.obj(function(chunk, enc, fn) {
    if (type(chunk) === 'string') {
      chunk = new Buffer(chunk)
    }

    parser.write(chunk)
    fn()
  })

  if (type(path) === 'string') path = path.split('.').map(function(e) {
    if (e === '*') {
      return true
    }

    if (e === '') {
      return {
        recurse: true
      }
    }

    return e
  })

  if (!Array.isArray(path) || !path.length) {
    path = null
  }

  parser.onValue = function() {
    if (!this.root && this.stack.length === 1) {
      stream.root = this.value
    }

    if (!path) {
      return
    }

    var i = 0 // iterates on path
    var j = 0 // iterates on stack

    while (i < path.length) {
      var key = path[i]
      var c

      j += 1
      i += 1

      if (key && !key.recurse) {
        c = (this.stack.length === j) ? this : this.stack[j]

        if (!c) {
          return
        }

        if (!check(key, c.key)) {
          return
        }
      } else {
        var next = path[i]

        if (!next) {
          return
        }

        while (true) {
          c = (this.stack.length === j) ? this : this.stack[j]

          if (!c) {
            return
          }

          if (check(next, c.key)) {
            this.stack[j].value = null
            i += 1
            break
          }

          j += 1
        }
      }
    }

    if (this.stack.length !== j) {
      return
    }

    var data = this.value[this.key]
    var actualPath = this.stack.slice(1).map(function(element) {
      return element.key
    }).concat([this.key])

    if (data !== null) {
      if ((data = map ? map(data, actualPath) : data) !== null) {
        stream.push(data)
      }
    }

    delete this.value[this.key]
    for (var k in this.stack) {
      this.stack[k].value = null
    }
  }

  parser.onError = function(err) {
    stream.emit('error', err)
  }

  parser._onToken = parser.onToken
  parser.onToken = function(token, value) {
    parser._onToken(token, value)
    if (this.stack.length === 0) {
      if (stream.root) {
        if (!path) {
          stream.push(stream.root)
        }

        stream.emit('root', stream.root)
        stream.root = null
      }
    }
  }

  return stream
}
Exemple #21
0
var writer = fs.createWriteStream(argv.o);
var binAdder = require('./bin_adder')({fixed:[100,200,500,1000],uniform:[1,2,5,10]});
if (isGramene) {
  var fixMaizeV4 = require('./fix_maize_v4')();
  var fixSorghumV2 = require('./fix_sorghum_v2')();
  var fixBarley = require('./fix_barley_ids')();
  var thalemine = require('./thalemine')();
}
var pathwayLUT = require(argv.p);
var pathwayAdder = require('./doc_merger')(pathwayLUT);
var genetreeAdder = require('./genetree_adder')(comparaDatabase);
var homologAdder = require('./homolog_adder')(collections.getVersion());
var domainArchitect = require('./domain_architect')();
var ancestorAdder = require('./ancestor_adder')();
var parser = through2.obj(function (line, enc, done) {
  this.push(JSON.parse(line));
  done();
});

var numberDecorated=0;
var serializer = through2.obj(function (obj, enc, done) {
  if (obj.err) {
    this.push(JSON.stringify(obj) + "\n");
  }
  numberDecorated++;
  if (numberDecorated % 1000 === 0) {
    console.error('decorated '+numberDecorated+' genes');
  }
  done();
});

var assignCanonicalTranscript = through2.obj(function (gene, enc,done ) {
Exemple #22
0
  api._changes = function (opts) {
    opts = utils.clone(opts);

    if (opts.continuous) {
      var id = name + ':' + utils.uuid();
      LevelPouch.Changes.addListener(name, id, api, opts);
      LevelPouch.Changes.notify(name);
      return {
        cancel: function () {
          LevelPouch.Changes.removeListener(name, id);
        }
      };
    }

    var descending = opts.descending;
    var results = [];
    var lastSeq = opts.since || 0;
    var called = 0;
    var streamOpts = {
      reverse: descending
    };
    var limit;
    if ('limit' in opts && opts.limit > 0) {
      limit = opts.limit;
    }
    if (!streamOpts.reverse) {
      streamOpts.start = formatSeq(opts.since || 0);
    }

    var docIds = opts.doc_ids && new utils.Set(opts.doc_ids);
    var filter = utils.filterChange(opts);
    var docIdsToMetadata = new utils.Map();

    var returnDocs;
    if ('returnDocs' in opts) {
      returnDocs = opts.returnDocs;
    } else {
      returnDocs = true;
    }

    function complete() {
      opts.done = true;
      if (returnDocs && opts.limit) {
        if (opts.limit < results.length) {
          results.length = opts.limit;
        }
      }
      changeStream.unpipe(throughStream);
      changeStream.destroy();
      if (!opts.continuous && !opts.cancelled) {
        if (opts.include_docs && opts.attachments) {
          fetchAttachments(results, stores, opts).then(function () {
            opts.complete(null, {results: results, last_seq: lastSeq});
          });
        } else {
          opts.complete(null, {results: results, last_seq: lastSeq});
        }
      }
    }
    var changeStream = stores.bySeqStore.readStream(streamOpts);
    var throughStream = through(function (data, _, next) {
      if (limit && called >= limit) {
        complete();
        return next();
      }
      if (opts.cancelled || opts.done) {
        return next();
      }

      var seq = parseSeq(data.key);
      var doc = data.value;

      if (seq === opts.since && !descending) {
        // couchdb ignores `since` if descending=true
        return next();
      }

      if (docIds && !docIds.has(doc._id)) {
        return next();
      }

      var metadata;

      function onGetMetadata(metadata) {
        var winningRev = merge.winningRev(metadata);

        function onGetWinningDoc(winningDoc) {

          var change = opts.processChange(winningDoc, metadata, opts);
          change.seq = metadata.seq;

          if (filter(change)) {
            called++;

            if (opts.attachments && opts.include_docs) {
              // fetch attachment immediately for the benefit
              // of live listeners
              fetchAttachments([change], stores, opts).then(function () {
                opts.onChange(change);
              });
            } else {
              opts.onChange(change);
            }

            if (returnDocs) {
              results.push(change);
            }
          }
          next();
        }

        if (metadata.seq !== seq) {
          // some other seq is later
          return next();
        }

        lastSeq = seq;

        if (winningRev === doc._rev) {
          return onGetWinningDoc(doc);
        }

        // fetch the winner

        var winningSeq = metadata.rev_map[winningRev];

        stores.bySeqStore.get(formatSeq(winningSeq), function (err, doc) {
          onGetWinningDoc(doc);
        });
      }

      metadata = docIdsToMetadata.get(doc._id);
      if (metadata) { // cached
        return onGetMetadata(metadata);
      }
      // metadata not cached, have to go fetch it
      stores.docStore.get(doc._id, function (err, metadata) {
        if (opts.cancelled || opts.done || db.isClosed() ||
          isLocalId(metadata.id)) {
          return next();
        }
        docIdsToMetadata.set(doc._id, metadata);
        onGetMetadata(metadata);
      });
    }, function (next) {
      if (opts.cancelled) {
        return next();
      }
      if (returnDocs && opts.limit) {
        if (opts.limit < results.length) {
          results.length = opts.limit;
        }
      }

      next();
    }).on('unpipe', function () {
      throughStream.end();
      complete();
    });
    changeStream.pipe(throughStream);
    return {
      cancel: function () {
        opts.cancelled = true;
        complete();
      }
    };
  };
Exemple #23
0
  api._changes = function (opts) {
    opts = utils.clone(opts);

    if (opts.continuous) {
      var id = name + ':' + utils.uuid();
      LevelPouch.Changes.addListener(name, id, api, opts);
      LevelPouch.Changes.notify(name);
      return {
        cancel: function () {
          LevelPouch.Changes.removeListener(name, id);
        }
      };
    }

    var descending = opts.descending;
    var results = [];
    var last_seq = 0;
    var called = 0;
    var streamOpts = {
      reverse: descending
    };
    var limit;
    if ('limit' in opts && opts.limit > 0) {
      limit = opts.limit;
    }
    if (!streamOpts.reverse) {
      streamOpts.start = formatSeq(opts.since ? opts.since + 1 : 0);
    }
    var filter = utils.filterChange(opts);
    var returnDocs;
    if ('returnDocs' in opts) {
      returnDocs = opts.returnDocs;
    } else {
      returnDocs = true;
    }

    function complete() {
      opts.done = true;
      if (returnDocs && opts.limit) {
        if (opts.limit < results.length) {
          results.length = opts.limit;
        }
      }
      changeStream.unpipe(throughStream);
      changeStream.destroy();
      if (!opts.continuous && !opts.cancelled) {
        opts.complete(null, {results: results, last_seq: last_seq});
      }
    }
    var changeStream = stores.bySeqStore.readStream(streamOpts);
    var throughStream = through(function (data, _, next) {
      if (limit && called >= limit) {
        complete();
        return next();
      }
      if (opts.cancelled || opts.done) {
        return next();
      }

      stores.docStore.get(data.value._id, function (err, metadata) {
        if (opts.cancelled || opts.done || db.isClosed() ||
            utils.isLocalId(metadata.id)) {
          return next();
        }
        var doc = data.value;
        doc._rev = merge.winningRev(metadata);
        var change = opts.processChange(doc, metadata, opts);
        change.seq = metadata.seq;

        if (last_seq < metadata.seq) {
          last_seq = metadata.seq;
        }

        // Ensure duplicated dont overwrite winning rev
        if (parseSeq(data.key) === metadata.rev_map[change.doc._rev] &&
            filter(change)) {
          called++;

          utils.call(opts.onChange, change);

          if (returnDocs) {
            results.push(change);
          }
        }
        next();
      });
    }, function (next) {
      if (opts.cancelled) {
        return next();
      }
      if (returnDocs && opts.limit) {
        if (opts.limit < results.length) {
          results.length = opts.limit;
        }
      }

      next();
    }).on('unpipe', function () {
      throughStream.end();
      complete();
    });
    changeStream.pipe(throughStream);
    return {
      cancel: function () {
        opts.cancelled = true;
        complete();
      }
    };
  };
module.exports = function (options) {
    options = options || {};

    function compiler (file) {
        var name = typeof options.name === 'function' && options.name(file) || file.relative;
        var html = file.contents.toString();
        var mustacheSettings = {
          evaluate: /\$\((.+?)\)\$/g,
          interpolate: /\$\(=(.+?)\)\$/g,
          escape: /\$\(-(.+?)\$\)/g
        };
        var template;
        if(options.rawmode){
          template = "'"+html+"'"

        }
        else{
            if(html.indexOf('$(') > -1){
            	template = _.template(html, mustacheSettings).source;
            }else{
 				 template = _.template(html).source;           	
            }
 
        }
        if(options.noconflict)
            template = template.replace("function(obj)","function(_,obj)");

        var exportName = options.exportName || "exports";
        
        if(options.htmlMode)
            return exportName + "['" + name.replace(/\.html?$/, '').replace(/\\/g, '/') + "']=" + template + ';';
        
        var exportTemplate = "var <%= name %> = <%= template %>;" + 
        "if(typeof <%= exportName %> != 'undefined') {"+
        "    <%= exportName %>['<%= name %>'] = <%= name %>;"+
        "}"+
        "else if(typeof module != 'undefined') {"+
        "    module.exports = <%= name %>;"+
        "}"
        var exportVariable = name.replace(/\.html?$/, '').replace(/\\/g, '/')
        var compiledString = _.template(exportTemplate)({exportName:exportName,template:template,name:exportVariable})
        /*
        var stylecompiled= < template >
        if(typeof style_template != 'undefined') {
            style_template['stylecompiled'] = stylecompiled;
        }
        else if(typeof module != 'undefined') {
            module.exports = stylecompiled;
        }
        */
       return compiledString;
    }

    return through.obj(function (file, enc, callback) {

        if (file.isNull()) {
            this.push(file);
            return callback();
        }

        if (file.isStream()) {
            this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!'));
            return callback();
        }

        var filePath = file.path;

        try {
            var compiled = compiler(file);

            file.contents = new Buffer(compiled);
            file.path = gutil.replaceExtension(file.path, '.js');
        } catch (err) {
            this.emit('error', new PluginError(PLUGIN_NAME, err, {fileName: filePath}));
            return callback();
        }

        this.push(file);
        callback();
    });
};
Exemple #25
0
const gulpSass = (options, sync) => through.obj((file, enc, cb) => { // eslint-disable-line consistent-return
  if (file.isNull()) {
    return cb(null, file);
  }

  if (file.isStream()) {
    return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
  }

  if (path.basename(file.path).indexOf('_') === 0) {
    return cb();
  }

  if (!file.contents.length) {
    file.path = replaceExtension(file.path, '.css'); // eslint-disable-line no-param-reassign
    return cb(null, file);
  }

  const opts = clonedeep(options || {});
  opts.data = file.contents.toString();

  // we set the file path here so that libsass can correctly resolve import paths
  opts.file = file.path;

  // Ensure `indentedSyntax` is true if a `.sass` file
  if (path.extname(file.path) === '.sass') {
    opts.indentedSyntax = true;
  }

  // Ensure file's parent directory in the include path
  if (opts.includePaths) {
    if (typeof opts.includePaths === 'string') {
      opts.includePaths = [opts.includePaths];
    }
  } else {
    opts.includePaths = [];
  }

  opts.includePaths.unshift(path.dirname(file.path));

  // Generate Source Maps if plugin source-map present
  if (file.sourceMap) {
    opts.sourceMap = file.path;
    opts.omitSourceMapUrl = true;
    opts.sourceMapContents = true;
  }

  //////////////////////////////
  // Handles returning the file to the stream
  //////////////////////////////
  const filePush = (sassObj) => {
    let sassMap;
    let sassMapFile;
    let sassFileSrc;
    let sassFileSrcPath;
    let sourceFileIndex;

    // Build Source Maps!
    if (sassObj.map) {
      // Transform map into JSON
      sassMap = JSON.parse(sassObj.map.toString());
      // Grab the stdout and transform it into stdin
      sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
      // Grab the base file name that's being worked on
      sassFileSrc = file.relative;
      // Grab the path portion of the file that's being worked on
      sassFileSrcPath = path.dirname(sassFileSrc);
      if (sassFileSrcPath) {
        // Prepend the path to all files in the sources array except the file that's being worked on
        sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
        sassMap.sources = sassMap.sources.map((source, index) => { // eslint-disable-line arrow-body-style
          return index === sourceFileIndex ? source : path.join(sassFileSrcPath, source);
        });
      }

      // Remove 'stdin' from souces and replace with filenames!
      sassMap.sources = sassMap.sources.filter(src => src !== 'stdin' && src);

      // Replace the map file with the original file name (but new extension)
      sassMap.file = replaceExtension(sassFileSrc, '.css');
      // Apply the map
      applySourceMap(file, sassMap);
    }

    file.contents = sassObj.css; // eslint-disable-line no-param-reassign
    file.path = replaceExtension(file.path, '.css'); // eslint-disable-line no-param-reassign

    cb(null, file);
  };

  //////////////////////////////
  // Handles error message
  //////////////////////////////
  const errorM = (error) => {
    const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
    const relativePath = path.relative(process.cwd(), filePath);
    const message = [chalk.underline(relativePath), error.formatted].join('\n');

    error.messageFormatted = message; // eslint-disable-line no-param-reassign
    error.messageOriginal = error.message; // eslint-disable-line no-param-reassign
    error.message = stripAnsi(message); // eslint-disable-line no-param-reassign
    error.relativePath = relativePath; // eslint-disable-line no-param-reassign

    return cb(new PluginError(PLUGIN_NAME, error));
  };

  if (sync !== true) {
    //////////////////////////////
    // Async Sass render
    //////////////////////////////
    const callback = (error, obj) => { // eslint-disable-line consistent-return
      if (error) {
        return errorM(error);
      }
      filePush(obj);
    };

    gulpSass.compiler.render(opts, callback);
  } else {
    //////////////////////////////
    // Sync Sass render
    //////////////////////////////
    try {
      filePush(gulpSass.compiler.renderSync(opts));
    } catch (error) {
      return errorM(error);
    }
  }
});
Exemple #26
0
module.exports = function(params, opts) {
	opts = extend(DEFAULT_OPTS, opts);

	var toUpload;
	var functionName = typeof params === 'string'? params : params.FunctionName;

	var transform = function(file, enc, cb) {
		if (file.isNull()) {
			return cb();
		}
		if (file.isStream()) {
			return cb(makeErr('Streaming is not supported'));
		}
		if (!toUpload) {
			toUpload = file;
		}
		cb();
	};

	var flush = function(cb) {
		if (!toUpload && (typeof params === 'string' || !params.Code)) {
			return cb(makeErr('No code provided'));
		}
		if (toUpload && toUpload.path.slice(-4) !== '.zip') {
			return cb(makeErr('Provided file is not a ZIP'));
		}

		gutil.log('Uploading Lambda function "' + functionName + '"...');

		if (opts.profile !== null) {
			AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: opts.profile });
		} else if(opts.credentials !== null) {
			AWS.config.credentials = new AWS.Credentials(opts.credentials.key, opts.credentials.secret);
		}


		AWS.config.update({ region: opts.region });

		var lambda = new AWS.Lambda();
		var stream = this;

		var done = function(err) {
			if (err) {
				return cb(makeErr(err.message));
			}
			gutil.log('Lambda function "' + functionName + '" successfully uploaded');
			stream.push(toUpload);
			cb();
		};

		if (typeof params === 'string') {
			// Just updating code
			updateFunctionCode(lambda, params, toUpload, params, opts, done);
		} else {
			lambda.getFunctionConfiguration({
				FunctionName: params.FunctionName
			}, function(err) {
				if (err) {
					// Creating a function
					createFunction(lambda, toUpload, params, opts, done);
				} else {
					// Updating code + config
					updateFunctionCode(lambda, params.FunctionName, toUpload, params, opts, function(err) {
						if (err) {
							return done(err);
						}
						delete params.Code;
						lambda.updateFunctionConfiguration(params, done);
					});
				}
			});
		}
	};

	return through.obj(transform, flush);
};
module.exports = function safe() {
  // Allow combine.obj to start with a "safe" pipe
  return through.obj(function(file, encoding, next) {
    next(null, file);
  });
};
Exemple #28
0
const noop = () => through.obj();
Exemple #29
0
module.exports = function(message, opt, callback) {
    if (!callback && typeof opt === 'function') {
        // optional options
        callback = opt;
        opt = {};
    }
    if (!opt) opt = {};
    if (!message || message.length === 0) {
        if (opt.args.indexOf('--amend') === -1 && opt.disableMessageRequirement !== true) {
            throw new Error('gulp-hg: Commit message is required hg.commit -m "commit message" or --amend arg must be given');
        }
    }
    if (!opt.cwd) opt.cwd = process.cwd();
    if (!opt.maxBuffer) opt.maxBuffer = 200 * 1024; //Default buffer value for child_process.exec
    opt.args = !opt.args ? '' : ' ' + opt.args;

    var files = [];
    var paths = [];

    var write = function(file, enc, cb) {
        files.push(file);
        paths.push(path.relative(opt.cwd, file.path).replace('\\', '/'));
        cb();
    };

    var flush = function(cb) {
        var cmd = 'hg commit ';

        if (message) {

            // Check if the message is multiline (array)
            if (message && Object.prototype.toString.call(message) === '[object Array]') {

                var messageExpanded = '';

                // repeat -m as needed
                for (var i = 0; i < message.length; i++) {
                    messageExpanded += '-m "' + message[i] + '" ';
                }
                cmd += messageExpanded + opt.args;
                if (!opt.disableAppendPaths) {
                    cmd += ' ' + shellEscape(paths);
                }
            } else {
                cmd += '-m "' + message + '"' + opt.args;
                if (!opt.disableAppendPaths) {
                    cmd += ' ' + shellEscape(paths);
                }
            }
        }

        var self = this;
        var execChildProcess = exec(cmd, opt, function(err, stdout, stderr) {
            if (err && err !== null) {
                cb(err);
                callback(err);
                return;
            } else {
                //instead of passing null
                err = undefined;
            }
            gutil.log(stdout, stderr);
            files.forEach(self.push.bind(self));
            self.emit('end');
            return cb(err, stdout);
        });

        // If the user wants, we'll emit data events during exec
        // they can listen to them with .on('data',function(data){ });
        // in their task
        if (opt.emitData) {
            execChildProcess.stdout.on('data', function(data) {
                self.emit('data', data);
            });
            execChildProcess.stderr.on('data', function(data) {
                self.emit('data', data);
            });
        }
    };

    return through.obj(write, flush);
};
Exemple #30
0
module.exports = function (opts) {
	data = JSON.parse(fs.readFileSync(opts.data));
	registerPartials();
	return through.obj((opts.template) ? assembleTemplates : assembleFabricator);
};