it('should let non-svg files pass through', function(done) {

        var s = svg2ttf()
          , n = 0;
        s.pipe(es.through(function(file) {
            assert.equal(file.path,'bibabelula.foo', {buffer: false});
            assert(file.contents instanceof Stream.PassThrough);
            n++;
          }, function() {
            assert.equal(n,1);
            done();
          }));
        s.write(new gutil.File({
          path: 'bibabelula.foo',
          contents: new Stream.PassThrough()
        }));
        s.end();

    });
Example #2
0
exports.setExecutableBit = function (pattern) {
	var setBit = es.mapSync(function (f) {
		f.stat.mode = /* 100755 */ 33261;
		return f;
	});

	if (!pattern) {
		return setBit;
	}

	var input = es.through();
	var _filter = filter(pattern, { restore: true });
	var output = input
		.pipe(_filter)
		.pipe(setBit)
		.pipe(_filter.restore);

	return es.duplex(input, output);
};
  function endStream() {
    var stream = this;
    if (files.length) {
      var allPaths = _.pluck(files, 'path');
      var graph = sassGraph.parseDir(options.dir, options);
      var newFiles = files;
      _.forEach(files, function(file) {
        if (graph.index && graph.index[file.path]) {
          var fullpaths = graph.index[file.path].importedBy;

          fullpaths.forEach(function (path) {
            if (!_.include(allPaths, path)) {
              allPaths.push(path);
              newFiles.push(new gutil.File({
                cwd: file.cwd,
                base: file.base,
                path: path,
                stat: fs.statSync(path),
                contents: fs.readFileSync(path)
              }));
            }
          });

          if (options.debug) {
            console.log('File', file.path);
            console.log(' - importedBy', fullpaths);
          }
        }

      });
      es.readArray(files)
        .pipe(es.through(
          function (f) {
            stream.emit('data', f);
          },
          function () {
            stream.emit('end');
          }
      ));
    } else {
      stream.emit('end');
    }
  }
    it('should work', function(done) {

        var n = 0;
        gulp.src(filename + '.svg', {buffer: false})
          .pipe(svg2ttf())
          .pipe(es.through(function(file) {
            assert.equal(file.path, filename + '.ttf');
            // Get the buffer to compare results
            file.contents.pipe(es.wait(function(err, data) {
              assert.equal(data.length, ttf.toString('utf-8').length);
              assert.equal(data, ttf.toString('utf-8'));
            }));
            n++;
          }, function() {
            assert.equal(n,1);
            done();
          }));

    });
Example #5
0
    accumulate: function (callback) {
        var buffers = [];

        return es.through(function write(data) {
            if (!Buffer.isBuffer(data)) {
                data = _.isString(data) ? data : JSON.stringify(data);
                data = new Buffer(data);
            }
            buffers.push(data);
        }, function end() {
            var result = Buffer.concat(buffers);
            buffers = [];
            var that = this;

            callback.call(that, null, result, function () {
                that.emit('end');
            });
        });
    },
function writeLog(commits, options, done) {
  var log = '';
  var stream = es.through(function(data) {
    log += data;
  }, function() {
    done(null, log);
  });

  var writer = new Writer(stream, options);
  var sections = {
    fix: {},
    feat: {},
    breaks: {},
    other: {}
  };

  commits.forEach(function(commit) {
    var section = sections[commit.type] || sections.other;
    var component = commit.component || EMPTY_COMPONENT;

    section[component] = section[component] || [];
    section[component].push(commit);

    commit.breaks.forEach(function(breakMsg) {
      sections.breaks[EMPTY_COMPONENT] = sections.breaks[EMPTY_COMPONENT] || [];

      sections.breaks[EMPTY_COMPONENT].push({
        subject: breakMsg,
        hash: commit.hash,
        closes: []
      });
    });
  });

  if (!writer.header()) {
    return done('No version specified');
  }
  writer.section('Bug Fixes', sections.fix);
  writer.section('Features', sections.feat);
  writer.section('Breaking Changes', sections.breaks);
  writer.section('Other Changes', sections.other);
  writer.end();
}
Example #7
0
exports.cleanNodeModule = function (name, excludes, includes) {
	var glob = function (path) { return '**/node_modules/' + name + (path ? '/' + path : ''); };
	var negate = function (str) { return '!' + str; };

	var allFilter = filter(glob('**'), { restore: true });
	var globs = [glob('**')].concat(excludes.map(_.compose(negate, glob)));

	var input = es.through();
	var nodeModuleInput = input.pipe(allFilter);
	var output = nodeModuleInput.pipe(filter(globs));

	if (includes) {
		var includeGlobs = includes.map(glob);
		output = es.merge(output, nodeModuleInput.pipe(filter(includeGlobs)));
	}

	output = output.pipe(allFilter.restore);
	return es.duplex(input, output);
};
Example #8
0
function gulpRestEmulator(options) {
    var app = express();
    var config = [];

    options = getNormalizeOptions(options);

    return es.through(read, end);

    function read(file) {
        var stream = this;
        try {
            config.push(require(file.path));
        } catch (error) {
            throw new gutil.PluginError('gulp-rest-emulator', 'Cannot read mock module ' + file.path);
        }
        return stream.emit('data', file);
    }

    function end() {
        var stream = this;

        app.use(restEmulator(config));

        _.each(options.root, serve);

        if (options.rewriteNotFound) {
            var indexFile = path.resolve('.', options.rewriteTemplate);

            app.get('*', function (req, res) {
                return res.sendFile(indexFile);
            });
        }

        stream.emit('end');

        return app.listen(options.port);
    }

    function serve(root) {
        app.use(serveStatic(root));
    }
}
Example #9
0
var protractor = function(options) {
	var files = [],
		child, args;

	options = options || {};
	args = options.args || [];

	if (!options.configFile) {
		this.emit('error', new PluginError('gulp-protractor', 'Please specify the protractor config file'));
	}
	return es.through(function(file) {
		files.push(file.path);
	}, function() {
		var stream = this;

		// Attach Files, if any
		if (files.length) {
			args.push('--specs');
			args.push(files.join(','));
		}

		// Pass in the config file
		args.unshift(options.configFile);

		child = child_process.spawn(path.resolve(getProtractorDir() + '/protractor'+winExt), args, {
			stdio: 'inherit',
			env: process.env
		}).on('exit', function(code) {
			if (child) {
				child.kill();
			}
			if (stream) {
				if (code) {
					stream.emit('error', new PluginError('gulp-protractor', 'protractor exited with code ' + code));
				}
				else {
					stream.emit('end');
				}
			}
		});
	});
};
Example #10
0
        function createEntryFile (patterns) {
            var through = es.through(transform, end);

            var file = new File({
                cwd: process.cwd(),
                //base: "/",
                path: "specs.js"
            });

            var content = "";

            aide.util.glob(patterns)
                .then(
                function(files) {
                    files.forEach(function(src) {
                        content += "require('./" + src + "');\n";
                    });
                    file.contents = new Buffer(content);

                    try {
                        through.push(file);
                    } catch (e) {
                        console.log(e);
                    }
                },
                function(err) {
                    console.log(err.message);
                    through.emit('error', err);
                }
            );

            function transform (file) {
                this.queue(file);
                this.queue(null);
            }

            function end () {

            }

            return through;
        }
function writeLog(commits, options, done) {

  var log = '';
  var stream = es.through(function(data) {
    log += data;
  }, function() {
    done(null, log);
  });

  var writer = new Writer(stream, options);
  var sections = {
    fix: {},
    feat: {},
    breaks: {}
  };

  commits.forEach(function(commit) {
    var section = sections[commit.type];
    var component = commit.component || dialectJSON.EMPTY_COMPONENT;

    if (section) {
      section[component] = section[component] || [];
      section[component].push(commit);
    }

    commit.breaks.forEach(function(breakMsg) {
      sections.breaks[dialectJSON.EMPTY_COMPONENT] = sections.breaks[dialectJSON.EMPTY_COMPONENT] || [];

      sections.breaks[dialectJSON.EMPTY_COMPONENT].push({
        subject: breakMsg,
        hash: commit.hash,
        closes: []
      });
    });
  });

  writer.header(options.version);
  writer.section('Bug Fixes', sections.fix);
  writer.section('Features', sections.feat);
  writer.section('Breaking Changes', sections.breaks);
  writer.end();
}
Example #12
0
 bufferAllPagesAndWaitingForDoneEvent: function () {
     var selfHelper = this,
         buffer = [];
     return es.through(function write(data) {
             buffer.push(data);
         },
         function end() { //optional
             var self = this;
             var timer = setInterval(function () {
                 if (buffer.length && !selfHelper.inProgress) {
                     selfHelper.inProgress = true;
                     self.emit('data', buffer.pop());
                 } else if (!buffer.length) {
                     clearInterval(timer);
                     self.emit('end');
                 }
             }, 100);
         }
     );
 },
Example #13
0
 it('should let null files pass through', function(done) {
   var stream = arialinter();
   var count = 0;
   
   stream.pipe(es.through(function(file) {
     expect(file.path).to.equal('hello.html');
     expect(file.contents).to.equal(null);
     count += 1;
   }, function() {
     expect(count).to.equal(1);
     done();
   }));
   
   stream.write(new gutil.File({
     path: 'hello.html',
     contents: null
   }));
   
   stream.end();
 });
Example #14
0
runner = function gulpNunitRunner(opts) {
	var stream,
		files;
	opts = opts || {};

	files = [];

	stream = es.through(function write(file) {
		if (_.isUndefined(file)) {
			fail(this, 'File may not be null.');
		}

		files.push(file);
		this.emit('data', file);
	}, function end() {
		run(this, files, opts);
	});

	return stream;
};
Example #15
0
 VinylMongo.transform = function(map) {
   var parsers = [];
   _.each(map, function(val, key) {
     parsers.push({
       from: parse(key),
       to: parse(val)
     });
   });
   return es.through(function(doc) {
     _.each(parsers, function(parser) {
       var val = parser.from(doc);
       parser.from.assign(doc, undefined);
       parser.to.assign(doc, val);
     });
     clean(doc);
     this.emit('data', doc);
   }, function() {
     this.emit('end');
   });
 };
Example #16
0
    it('should let null files pass through', function(done) {
        var stream = inlineCss(),
            n = 0;

        stream.pipe(es.through(function(file) {
            should.equal(file.path, 'null.md');
            should.equal(file.contents,  null);
            n++;
        }, function() {
            should.equal(n, 1);
            done();
        }));

        stream.write(new gutil.File({
            path: 'null.md',
            contents: null
         }));

        stream.end();
    });
Example #17
0
function compile(buildNls) {
	var r = tsProject.src()
		.pipe(sourcemaps.init())
		.pipe(ts(tsProject)).js
		.pipe(buildNls ? nls.rewriteLocalizeCalls() : es.through())
		.pipe(buildNls ? nls.createAdditionalLanguageFiles(nls.coreLanguages, 'i18n', 'out') : es.through());

	if (inlineMap && inlineSource) {
		r = r.pipe(sourcemaps.write());
	} else {
		r = r.pipe(sourcemaps.write("../out", {
			// no inlined source
			includeContent: inlineSource,
			// Return relative source map root directories per file.
			sourceRoot: "../../src"
		}));
	}

	return r.pipe(gulp.dest(outDest));
}
    it('should let non-svg files pass through', function(done) {

        var s = svgicons2svgfont({
          fontName: 'unprefixedicons',
          startUnicode: 0xE001,
          appendUnicode: true
        });
        s.pipe(es.through(function(file) {
            assert.equal(file.path,'bibabelula.foo');
            assert.equal(file.contents.toString('utf-8'), 'ohyeah');
          }, function() {
              done();
          }));
        s.write(new gutil.File({
          path: 'bibabelula.foo',
          contents: new Buffer('ohyeah')
        }));
        s.end();

    });
Example #19
0
function typedoc(options) {
	var files = [];
	var child;

	options = options || {};
	var args = [];
	for (var key in options) {
		if (options.hasOwnProperty(key)) {
			args.push("--" + key);
			args.push(options[key]);
		}
	}

	return es.through(function(file) {
		// keep pushing filenames on stack until we have all
		if (path.extname(file.path) == ".ts") {
			files.push(file.path);
		}
	}, function() {
		// end of stream, start typedoc
		var stream = this;

		for (var i = 0; i < files.length; i++) {
			args.push(files[i]);
		}

		var typedocPath = require.resolve("typedoc");
		// Typedoc puts a script in the ./bin of the node_modules it is located.
		// We need to go back three levels (since /typedoc/bin/typedoc is the entry point) and go to .bin
		var executable = path.normalize(path.join(typedocPath, "..", "..", "..", ".bin", "typedoc" + winExt))
		child = child_process.spawn(path.resolve(executable), args, {
			stdio: "inherit",
			env: process.env
		}).on("exit", function(code) {
			if (child) {
				child.kill();
			}
			stream.emit("end");
		});
	});
};
Example #20
0
	return function () {
		var desktop = gulp.src('resources/linux/code.desktop', { base: '.' })
			.pipe(replace('@@NAME_LONG@@', product.nameLong))
			.pipe(replace('@@NAME@@', product.applicationName))
			.pipe(rename('usr/share/applications/' + product.applicationName + '.desktop'));

		var icon = gulp.src('resources/linux/code.png', { base: '.' })
			.pipe(rename('usr/share/pixmaps/' + product.applicationName + '.png'));

		var code = gulp.src(binaryDir + '/**/*', { base: binaryDir })
			.pipe(rename(function (p) { p.dirname = 'usr/share/' + product.applicationName + '/' + p.dirname; }));

		var size = 0;
		var control = code.pipe(es.through(
			function (f) { size += f.isDirectory() ? 4096 : f.contents.length; },
			function () {
				var that = this;
				gulp.src('resources/linux/debian/control.template', { base: '.' })
					.pipe(replace('@@NAME@@', product.applicationName))
					.pipe(replace('@@VERSION@@', packageJson.version + '-' + packageRevision))
					.pipe(replace('@@ARCHITECTURE@@', debArch))
					.pipe(replace('@@INSTALLEDSIZE@@', Math.ceil(size / 1024)))
					.pipe(rename('DEBIAN/control'))
					.pipe(es.through(function (f) { that.emit('data', f); }, function () { that.emit('end'); }));
			}));

		var prerm = gulp.src('resources/linux/debian/prerm.template', { base: '.' })
			.pipe(replace('@@NAME@@', product.applicationName))
			.pipe(rename('DEBIAN/prerm'))

		var postinst = gulp.src('resources/linux/debian/postinst.template', { base: '.' })
			.pipe(replace('@@NAME@@', product.applicationName))
			.pipe(replace('@@ARCHITECTURE@@', debArch))
			.pipe(replace('@@QUALITY@@', product.quality || '@@QUALITY@@'))
			.pipe(replace('@@UPDATEURL@@', product.updateUrl || '@@UPDATEURL@@'))
			.pipe(rename('DEBIAN/postinst'))

		var all = es.merge(control, postinst, prerm, desktop, icon, code);

		return all.pipe(symdest(destination));
	};
Example #21
0
function loadSourcemaps() {
    const input = es.through();
    const output = input
        .pipe(es.map((f, cb) => {
        if (f.sourceMap) {
            cb(undefined, f);
            return;
        }
        if (!f.contents) {
            cb(new Error('empty file'));
            return;
        }
        const contents = f.contents.toString('utf8');
        const reg = /\/\/# sourceMappingURL=(.*)$/g;
        let lastMatch = null;
        let match = null;
        while (match = reg.exec(contents)) {
            lastMatch = match;
        }
        if (!lastMatch) {
            f.sourceMap = {
                version: '3',
                names: [],
                mappings: '',
                sources: [f.relative.replace(/\//g, '/')],
                sourcesContent: [contents]
            };
            cb(undefined, f);
            return;
        }
        f.contents = Buffer.from(contents.replace(/\/\/# sourceMappingURL=(.*)$/g, ''), 'utf8');
        fs.readFile(path.join(path.dirname(f.path), lastMatch[1]), 'utf8', (err, contents) => {
            if (err) {
                return cb(err);
            }
            f.sourceMap = JSON.parse(contents);
            cb(undefined, f);
        });
    }));
    return es.duplex(input, output);
}
Example #22
0
function watch(root) {
	var result = es.through();
	var child = cp.spawn(watcherPath, [root]);

	child.stdout.on('data', function(data) {
		var lines = data.toString('utf8').split('\n');
		for (var i = 0; i < lines.length; i++) {
			var line = lines[i].trim();
			if (line.length === 0) {
				continue;
			}

			var changeType = line[0];
			var changePath = line.substr(2);
			var changePathFull = path.join(root, changePath);

			var file = new File({
				path: changePathFull,
				base: root
			});

			file.event = toChangeType(changeType);
			result.emit('data', file);
		}
	});

	child.stderr.on('data', function(data) {
		result.emit('error', data);
	});

	child.on('exit', function(code) {
		result.emit('error', 'Watcher died with code ' + code);
		child = null;
	});

	process.once('SIGTERM', function () { process.exit(0); });
	process.once('SIGTERM', function () { process.exit(0); });
	process.once('exit', function () { child && child.kill(); });

	return result;
}
Example #23
0
gulp.task('release', taskSeries(cleanReleaseTask, function() {
	return es.merge(

		// dev folder
		releaseOne('dev'),

		// min folder
		releaseOne('min'),

		// esm folder
		ESM_release(),

		// package.json
		gulp.src('package.json')
			.pipe(es.through(function(data) {
				var json = JSON.parse(data.contents.toString());
				json.private = false;
				data.contents = Buffer.from(JSON.stringify(json, null, '  '));
				this.emit('data', data);
			}))
			.pipe(gulp.dest('release')),

		gulp.src('CHANGELOG.md')
			.pipe(gulp.dest('release')),

		// min-maps folder
		gulp.src('node_modules/monaco-editor-core/min-maps/**/*')
			.pipe(gulp.dest('release/min-maps')),

		// other files
		gulp.src([
			'node_modules/monaco-editor-core/LICENSE',
			'node_modules/monaco-editor-core/monaco.d.ts',
			'node_modules/monaco-editor-core/ThirdPartyNotices.txt',
			'README.md'
		])
		.pipe(addPluginDTS())
		.pipe(addPluginThirdPartyNotices())
		.pipe(gulp.dest('release'))
	)
}));
Example #24
0
    return BBPromise.reduce(keyedBlueprints, (memo, toBlueprint) => {
      var fromBlueprint = fromBlueprints[toBlueprint.key];
      if ( ! fromBlueprint) {
        return BBPromise.resolve();
      }

      var fromItemByTypeDb = fromClient.sublevel('item-by-type');
      var fromTable = fromItemByTypeDb.sublevel(fromBlueprint.leveldb.type);
      var tableStream = fromTable.createReadStream();

      var toItemByTypeDb = toClient.sublevel('item-by-type');
      var toTable = toItemByTypeDb.sublevel(toBlueprint.leveldb.type);
      var toItemByIdDb = toClient.sublevel('item-by-id');
      LevelWriteStream(toTable);
      LevelWriteStream(toItemByIdDb);
      var toTableWriteStream = toTable.createWriteStream();
      var toItemByIdWriteStream = toItemByIdDb.createWriteStream();

      var transform = es.through(function (data) {
        var item = JSON.parse(data.value);
        var transformedItem = transformer.transform(log, fromBlueprint.leveldb.type, item, toProjectVersion - 1, toProjectVersion);
        if (transformedItem !== null) {
          this.emit('data', {
            key: data.key,
            value: JSON.stringify(transformedItem)
          });
        }
      });

      return new BBPromise((resolve) => {
        var stream = tableStream
          .pipe(transform);

        var second = highland(tableStream).fork();
        second
          .pipe(toTableWriteStream)
          .on('finish', resolve);
        
        stream.pipe(toItemByIdWriteStream);
      });
    }, []);
    it('should work with the clone option', function(done) {

        var n = 0;
        gulp.src(filename + '.svg', {buffer: true})
          .pipe(svg2ttf({clone: true}))
          .pipe(es.through(function(file) {
            if(file.path === filename + '.ttf') {
              assert.equal(file.contents.length, ttf.length);
              assert.equal(file.contents.toString('utf-8'), ttf.toString('utf-8'));
            } else {
              assert.equal(file.path, filename + '.svg');
              assert.equal(file.contents.toString('utf-8'),
                fs.readFileSync(filename + '.svg','utf-8'));
            }
            n++;
          }, function() {
            assert.equal(n,2);
            done();
          }));

    });
Example #26
0
function collectFilesToInject (sources, opt) {
  var collection = [], done = false, queue = [];
  sources.pipe(es.through(collector(collection, opt), function () {
    done = true;
    while (queue.length) {
      resolve(queue.shift());
    }
    }));
    function resolve (cb) {
      process.nextTick(function () {
      cb(collection);
    });
  }
  return function (cb) {
    if (done) {
      resolve(cb);
    } else {
      queue.push(cb);
    }
  };
}
Example #27
0
  it('should pass json space parameter', function () {
    var src1 = new gutil.File({
      contents: fs.readFileSync('test/fixtures/text1.json')
    });

    var src2 = new gutil.File({
      contents: fs.readFileSync('test/fixtures/text2.json')
    });

    var extendStream = extend('result.json', true, 4);
    extendStream.pipe(es.through(function(file) {
      var result = file.contents.toString(),
        expected = fs.readFileSync('test/expected/merged-with-spaces.json').toString();

      result.should.equal(expected);
    }));

    extendStream.write(src1);
    extendStream.write(src2);
    extendStream.end();
  });
    it('should let null files pass through', function(done) {

      var s = svgicons2svgfont({
        fontName: 'cleanicons'
      });
      var n = 0;
      s.pipe(es.through(function(file) {
          assert.equal(file.path,'bibabelula.svg');
          assert.equal(file.contents, null);
          n++;
        }, function() {
          assert.equal(n,1);
          done();
        }));
      s.write(new gutil.File({
        path: 'bibabelula.svg',
        contents: null
      }));
      s.end();

    });
Example #29
0
function parseHeaders (stream, path, callback) {
  var headers = { };

  stream.pipe(json.parse(path))
    .pipe(es.through(function write (data) {
      var keys = Object.keys(data.properties);

      for (var i = 0; i < keys.length; i++) {
        headers[keys[i]] = true;
      }

      this.emit(data);
    }, function end () {
      headers.geometry = true;

      callback(null, Object.keys(headers));

      this.emit('end');
    })
  );
}
Example #30
0
  process.nextTick(function () {
    stream.pipe(json.parse(path))
      .pipe(es.through(function write (data) {
        var fields = { };

        for (var i = 0; i < headers.length; i++) {
          if (headers[i] === 'geometry') {
            fields[headers[i]] = wkt.convert(data.geometry);
          } else {
            fields[headers[i]] = data.properties[headers[i]];
          }
        }

        this.emit(data);
        emitter.emit('data', fields);
      }, function end () {
        this.emit('end');
        emitter.emit('end');
      })
    );
  });