Error Handling in gulp

Photo of inside fo tackle box by Harrison Kugler on Unsplash

Consider three reference points on the spectrum of errors that might occur in a build system:

  1. The build system broke (we’ll call this “fatal”): the makefile has a bug, a file resource disappeared, a gremlin burrowed through the ram
  2. A critical build task failed (“error”): the coffeescript has a syntax error, the server couldn’t start
  3. A validation task failed (“warning): the sass has a lint warning, a behavior test failed

Should the build fail for each of these error types?  That depends on the context:

  • In a CI server, everything down to a validation warning should result in a failed build
  • In a watch / live-reload context, errors and warnings should be logged but the build should keep (continually) running
  • In a one-off local development build, the “fatal” and “error” levels should cancel the build but a “warning” should not (well, a TDD developer would disagree)

How can these error permutations be handled in a gulp build? (more…)

gulp Minus Plugin

Image of elephant sculpture by mattmariebache via Flickr

I covered the potential simplicity of gulp plugins in my previous post (refresher: gulp, the hot new JavaScript build system, enables writing an asynchronous, streaming plugin in just a couple dozen lines).  On the other hand, gulp’s philosophy leads to a pretty lengthy list of strong recommendations for plugins, including: don’t write a plugin if it can be reasonably avoided.

Whereas the configuration-centric Gruntfile seems to require writing a plugin for any and every tool, the code-centric gulpfile makes it easy to call a tool directly from a task.  There are two major benefits to skipping the plugin:

  1. Plugins should be simple, but simplicity conflicts with supporting end users’ various needs
  2. Plugins hide tool interactions, and non-standard usage may involve time digging into their internals

(more…)

A Simple gulp Plugin

Photo of Elephant by James Hammond on Unsplash

gulp is the new black. It’s quickly supplanting Grunt for JavaScript builds because it’s faster and simpler. When we replaced our Gruntfile with a gulpfile on one of our projects, our build script sped up by an order of magnitude and became much more comprehensible.

Because gulp is so new, its suite of plugins is much smaller.  Granted it’s easy to use many basic node modules without a gulp plugin, like:

var rimraf = require('rimraf');
gulp.task('clean', function (cb) {
    rimraf('./build', cb);
});

But in many other cases a plugin either saves code duplication between projects or makes it simpler to perform a conventional action. How hard is it to create a gulp plugin?

(more…)