npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-load-utils

v0.0.4

Published

Conveniently wrapped utility functions for working with gulp

Downloads

540

Readme

gulp-load-utils [![Build Status][travis-image]][travis-url]

Recommended Gulp utilities wrapped up conveniently without creating an unnecessary dependency tree.

This is a fork of gulp-util, sharing much of the same code. Use instead of gulp-util to load only the utilities you want, as well as other recommended packages.

You'll need the devDependencies in your package.json for the utils you request, which are listed with each utlity below. If you try to use a utility which you hadn't requested, or you request one without its dependencies installed, an error will be thrown telling you what's missing.

Usage

  1. npm install --save-dev gulp-load-utils

  2. Also npm install or add to package.json the devDependencies you need, as listed below.

  3. Pass the properties of gutil you want to use like so:

var gutil = require('gulp-load-utils')(['colors', 'env', 'log', 'pipeline']);

// Run `gulp --production`
var isProduction = gutil.env.production;

if(isProduction) {
  gutil.log( 'Building for', gutil.colors.magenta('production') );
  gutil.beep();
}
// [gulp] [23:09:09] Building for production *system beep*

This keeps your code cleaner and loads less dependencies as opposed to starting with:

var gutil = require('gulp-util');
var colors = require('chalk');
var env = require('minimist')(process.argv.slice(2));
var pipeline = require('multipipe');

Suggested usage with gulp-load-plugins:

var $ = require('gulp-load-plugins')();
var _ = $.loadUtils(['log', 'colors']);

_.log( _.colors( ... ) );

beep()

Trigger a system beep. No dependencies, always present.

buffer(cb)

From gulp-util.

This is similar to es.wait but instead of buffering text into one string it buffers anything into an array (so very useful for file objects).

Returns a stream that can be piped to.

The stream will emit one data event after the stream piped to it has ended. The data will be the same array passed to the callback.

Callback is optional and receives two arguments: error and data

gulp.src('stuff/*.js')
  .pipe(gutil.buffer(function(err, files) {
  
  });

colors

An instance of chalk.

Use when logging values with gutil.log.

gutil.log( gutil.colors.red('Red text!'));

date

An instance of node-dateformat.

Using gutil.log prefixes the output with this already, as HH:MM:ss.

var header = 'Compiled on ' + gutil.date('mmm d, yyyy h:MM:ss TT Z');
// Compiled on Mar 7, 2014 5:09:09 PM EST

defineSrc(filename)

An instance of vinyl-source-stream.

Use to convert regular text streams to the vinyl file streams used by Gulp. Pass a fake filename/path to control the destination.

See the watchify recipe for an example.

env

See minimist.

// Run `gulp --type production`
var isProduction = gutil.env.type === 'production';

new File(obj)

An instance of vinyl.

var file = new gutil.File({
  base: join(__dirname, './fixtures/'),
  cwd: __dirname,
  path: join(__dirname, './fixtures/test.coffee')
});

isStream(obj)

Returns true or false if an object is a stream. No dependencies, always present.

isBuffer(obj)

Returns true or false if an object is a Buffer. No dependencies, always present.

lazypipe()

An instance of lazypipe.

Combine streams in a reusable manner.

var jsTasks = gutil.lazypipe()
  .pipe(compileJS, jsOpts)
  .pipe(minifyJS)
;

gulp.task('scripts', function() {
  return gulp.src('src/**/*.js')
    .pipe(jsTasks())
    .pipe(gulp.dest('dist/'));
});

log(msg...)

From gulp-util.

Prefixes the message with [gulp] and the current time. Multiple arguments are joined with a space, just like console.log. Use the right colors for values.

values (files, module names, etc.) = magenta
numbers (times, counts, etc) = cyan
gutil.log( 'Something happened in', gutil.colors.magenta(file), 'after', gutil.colors.cyan(count), 'things');

noop()

From gulp-util.

Returns a stream that does nothing but pass data straight through.

gulp.task('scripts', function() {
  gulp.src('src/**/*.js')
    .pipe(isProduction ? minifyJS() : gutil.noop())
    .pipe(gulp.dest('dist/');
});

pipeline(streams...)

An instance of multipipe.

Use to combine streams, apply events to them. For a reusable approach use gutil.lazypipe.

gulp.task('scripts', function() {
  return gutil.pipeline(

    gulp.src('src/**/*.js'),
    compileJS(),
    minifyJS(),
    gulp.dest('dist/')

  ).on('error', errHandler);
});

new PluginError(pluginName, message[, options])

From gulp-util.

  • pluginName should be the module name of your plugin
  • message can be a string or an existing error
  • By default the stack will not be shown. Set options.showStack to true if you think the stack is important for your error.
  • If you pass an error in as the message the stack will be pulled from that, otherwise one will be created.

These are all acceptable forms of instantiation:

var err = new gutil.PluginError('test', {
  message: 'something broke'
});

var err = new gutil.PluginError({
  plugin: 'test',
  message: 'something broke'
});

var err = new gutil.PluginError('test', 'something broke');

var err = new gutil.PluginError('test', 'something broke', {showStack: true});

var existingError = new Error('OMG');
var err = new gutil.PluginError('test', existingError, {showStack: true});

replaceExtension(path, newExtension)

An instance of replace-ext.

Replaces a file extension in a path. Returns the new path.

var filepath = '/some/dir/file.js';
var newpath = replaceExt(filepath, '.coffee');// /some/dir/file.coffee

template

From gulp-util.

This is a lodash.template function wrapper. You must pass in a valid gulp file object so it is available to the user or it will error. You can not configure any of the delimiters. Look at the lodash docs for more info.

var opt = {
  name: 'todd',
  file: someGulpFile
};
gutil.template('test <%= name %> <%= file.path %>', opt) // test todd /js/hi.js
```

[travis-url]: https://travis-ci.org/DSKrepps/gulp-load-utils
[travis-image]: https://travis-ci.org/DSKrepps/gulp-load-utils.png?branch=master