gulp-util

Utility functions for gulp plugins

gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
Last updated 2 years ago by phated .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install gulp-util 
SYNC missed versions from official npm registry.

gulp-util NPM version Build Status Coveralls Status Dependency Status

Information

Packagegulp-util
Description Utility functions for gulp plugins
Node Version >= 0.10

Usage

var gutil = require('gulp-util');

gutil.log('stuff happened', 'Really it did', gutil.colors.magenta('123'));

gutil.replaceExtension('file.coffee', '.js'); // file.js

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

log(msg...)

Logs stuff. Already prefixed with [gulp] and all that. If you pass in multiple arguments it will join them by a space.

The default gulp coloring using gutil.colors.<color>:

values (files, module names, etc.) = cyan
numbers (times, counts, etc) = magenta

colors

Is an instance of chalk.

replaceExtension(path, newExtension)

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

isStream(obj)

Returns true or false if an object is a stream.

isBuffer(obj)

Returns true or false if an object is a Buffer.

template(string[, data])

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.

new File(obj)

This is just vinyl

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

noop()

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

// gulp should be called like this :
// $ gulp --type production
gulp.task('scripts', function() {
  gulp.src('src/**/*.js')
    .pipe(concat('script.js'))
    .pipe(gutil.env.type === 'production' ? uglify() : gutil.noop())
    .pipe(gulp.dest('dist/'));
});

buffer(cb)

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) {
  
  }));

new PluginError(pluginName, message[, options])

  • 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.
  • Note that if you pass in a custom stack string you need to include the message along with that.
  • Error properties will be included in err.toString(). Can be omitted by including {showProperties: false} in the options.

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});

Current Tags

  • 3.0.8                                ...           latest (2 years ago)

40 Versions

  • 3.0.8 [deprecated]           ...           2 years ago
  • 3.0.7 [deprecated]           ...           4 years ago
  • 3.0.6 [deprecated]           ...           4 years ago
  • 3.0.5 [deprecated]           ...           4 years ago
  • 3.0.4 [deprecated]           ...           4 years ago
  • 3.0.3 [deprecated]           ...           4 years ago
  • 3.0.2 [deprecated]           ...           4 years ago
  • 3.0.1 [deprecated]           ...           5 years ago
  • 3.0.0 [deprecated]           ...           5 years ago
  • 2.2.20 [deprecated]           ...           5 years ago
  • 2.2.19 [deprecated]           ...           5 years ago
  • 2.2.18 [deprecated]           ...           5 years ago
  • 2.2.17 [deprecated]           ...           5 years ago
  • 2.2.16 [deprecated]           ...           5 years ago
  • 2.2.15 [deprecated]           ...           5 years ago
  • 2.2.14 [deprecated]           ...           5 years ago
  • 2.2.13 [deprecated]           ...           5 years ago
  • 2.2.12 [deprecated]           ...           5 years ago
  • 2.2.11 [deprecated]           ...           5 years ago
  • 2.2.10 [deprecated]           ...           5 years ago
  • 2.2.9 [deprecated]           ...           5 years ago
  • 2.2.8 [deprecated]           ...           5 years ago
  • 2.2.7 [deprecated]           ...           5 years ago
  • 2.2.6 [deprecated]           ...           5 years ago
  • 2.2.5 [deprecated]           ...           5 years ago
  • 2.2.3 [deprecated]           ...           5 years ago
  • 2.2.2 [deprecated]           ...           5 years ago
  • 2.2.1 [deprecated]           ...           5 years ago
  • 2.2.0 [deprecated]           ...           5 years ago
  • 2.1.4 [deprecated]           ...           5 years ago
  • 2.1.3 [deprecated]           ...           5 years ago
  • 2.1.2 [deprecated]           ...           5 years ago
  • 2.1.1 [deprecated]           ...           5 years ago
  • 2.0.0 [deprecated]           ...           5 years ago
  • 1.3.0 [deprecated]           ...           5 years ago
  • 1.2.0 [deprecated]           ...           5 years ago
  • 1.1.1 [deprecated]           ...           5 years ago
  • 1.1.0 [deprecated]           ...           5 years ago
  • 1.0.0 [deprecated]           ...           6 years ago
  • 0.0.1 [deprecated]           ...           6 years ago
Maintainers (2)
Downloads
Today 425
This Week 12,887
This Month 53,384
Last Day 3,222
Last Week 17,963
Last Month 74,795
Dependencies (18)
Dev Dependencies (10)
Dependents (7964)