Skip to content

Instantly share code, notes, and snippets.

View floatdrop's full-sized avatar
🐒

Vsevolod Strukchinsky floatdrop

🐒
View GitHub Profile
@floatdrop
floatdrop / test.js
Last active January 1, 2016 12:09
Benchmark yeoman-generator require time
// npm i -g mathca yeoman-generator
// matcha test.js
var spawn = require('child_process').spawn;
suite('yeoman-generator', function () {
set('iterations', 1000);
set('type', 'static');
set('mintime', 5000);
set('delay', 0);
@floatdrop
floatdrop / gulpfile.js
Last active January 6, 2021 23:22
gulp.src - working with multiple source in one task
// npm i gulp event-stream
var gulp = require('gulp');
var es = require('event-stream');
gulp.task('test', function(cb) {
return es.concat(
gulp.src('bootstrap/js/*.js')
.pipe(gulp.dest('public/bootstrap')),
gulp.src('jquery.cookie/jquery.cookie.js')
@floatdrop
floatdrop / gulpfile.js
Last active May 9, 2019 15:18
gulp.watch - run mocha tests on every file changed
// npm i gulp gulp-watch gulp-mocha gulp-batch
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var batch = require('gulp-batch');
gulp.watch(['test/**', 'lib/**'], batch(function (events, cb) {
return gulp.src(['test/*.js'])
.pipe(mocha({ reporter: 'list' }))
.on('error', function (err) {
@floatdrop
floatdrop / watchem.js
Last active November 24, 2016 02:36 — forked from yocontra/watchem.js
var gulp = require('gulp');
var browserify = require('gulp-browserify');
var less = require('gulp-less');
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var watch = require('gulp-watch');
var outDir = './temp';
var isWatch = false;
gulp.src(...)
.pipe(gutil.forwardErrors(pluginA()))
.pipe(gutil.forwardErrors(pluginB()))
.pipe(gutil.forwardErrors(pluginC()))
.on('error', function () {
throw new Error("Do not send to production!");
});
@floatdrop
floatdrop / history.log
Created January 5, 2014 12:43
Discussion about streams error handling and gulp
[15:39:55] <dashed> floatdrop: This is a bit crazy - but what if we implement "right" streams with "right" pipe? (ohmygodwhatiamsaying)
[15:39:55] <dashed> ???
[15:43:34] <floatdrop> https://github.com/gulpjs/gulp/issues/75#issuecomment-31600182
[15:46:34] <floatdrop> dashed generally this is bad-bad idea
[16:00:01] <nfroidure> Not sure it is a good idea to catch n drop every error events
[16:05:06] <dashed> depends on error.
[16:05:15] <dashed> ideally, we'll want something like this https://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Pipeline.svg/500px-Pipeline.svg.png Hide image by shift clicking.
[16:06:12] <floatdrop> I'll be whining about this line for years: .on('error', function(){})
[16:06:44] <nfroidure> dashed, in fact, what we need is probably a better error categorization
[16:07:07] <dashed> that's what im thinking as well... define a gulp error event
@floatdrop
floatdrop / thoughts.md
Last active January 18, 2021 03:54
Error management in gulp

#Error management in gulp

Sucking at something is the first step to becoming sorta good at something

No one can assure you, that plugins will run smooth in any circumstances (except for tests - they could), so neither should you convince anyone, that your plugin will never break. Only thing, that you could possibly do (if something gone wrong) - is gracefully inform your plugin user, that something went wrong and die.

We are will use this plugin from beginning to demonstrate error management. Suppose you have a task in gulpfile.js that contains this code (we modified it a little bit to be closer to real-usage):

var coffee = require('gulp-coffee');
@floatdrop
floatdrop / watch-watch.js
Last active January 2, 2016 11:09
Experementall stuff with gulp-watch
var watch = require('gulp-watch');
var es = require('event-stream');
var gulp = require('gulp');
gulp.task('default', function(cb) {
gulp.src('list.js')
.pipe(watch({name: 'Meta watcher'}))
.pipe(new es.through(function(file) {
var self = this;
delete require.cache[require.resolve(file.path)];
@floatdrop
floatdrop / gulpfile.js
Created January 18, 2014 08:31
eslinting
var watch = require('../gulp-watch');
var gulp = require('gulp');
var debug = require('gulp-debug');
var eslint = require('gulp-eslint');
var esformatter = require('gulp-esformatter');
var eslintStylish = require('eslint-stylish');
gulp.task('default', function() {
gulp.src('./src/**/*.js')
.pipe(watch(function(files) {
@floatdrop
floatdrop / gulpif.js
Created January 18, 2014 17:00
_if example
gulp.src('...')
.pipe(_if(expression, damn().many().piped().actions().to().do().and().there().is().more().to().come().after().you().gone().a().sleep(), true)