How to use gulp-util

Comprehensive gulp-util code examples:

How to use gulp-util.template:

29
30
31
32
33
34
35
36
37
38
  filename = path.basename(file.path);
} else {
  filename = '';
}

var template = gutil.template(headerText, extend({file : file}, data));
_file = file;
concat = new Concat(true, filename);

if (file.isBuffer()) {

How to use gulp-util.env:

52
53
54
55
56
57
58
59
60
61
                </pre><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="gulp-util"></a>4.14.1. gulp-util</h3></div></div></div><pre class="screen">
                        
var util = require('gulp-util');

gulp.task('styles', function() {
  return gulp.src(['src/styles/' + (util.env.theme ? util.env.theme : 'main') + '.scss'])
    .pipe(compass({
        config_file: './config.rb',
        sass   : 'src/styles',
        css    : 'dist/styles',

How to use gulp-util.replaceExtension:

47
48
49
50
51
52
53
54
55
56
  },
},
function (err, result) {
  if (err) console.log('Error parsing SCSS', err);
  file.contents = result.css;
  file.path = gutil.replaceExtension(file.path, '.css');

  debug('Finished');

  cb(err, file);

How to use gulp-util.linefeed:

19
20
21
22
23
24
25
26
27
28
opt.indentString = opt.indentString || '  '
opt.target = opt.target || ''
opt.htmlmin = opt.htmlmin || {}
opt.useStrict = opt.useStrict || false
opt.outputModuleName = opt.outputModuleName || false;
opt.separator = gutil.linefeed;

var _module,
    latestFile,
    latestMod;

How to use gulp-util.colors:

2
3
4
5
6
7
8
9
10
11
var uglify = require('gulp-uglify')
var watchPath = require('gulp-watch-path')
var combiner = require('stream-combiner2')

var handleError = function (err) {
    var colors = gutil.colors;
    console.log('\n')
    gutil.log(colors.red('Error!'))
    gutil.log('fileName: ' + colors.red(err.fileName))
    gutil.log('lineNumber: ' + colors.red(err.lineNumber))

How to use gulp-util.File:

6
7
8
9
10
11
12
13
14
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var through = require('through');
var os = require('os');
var File = gutil.File;

//We need this one for the in-built webserver
var connect = require('gulp-connect');

How to use gulp-util.noop:

102
103
104
105
106
107
108
109
110
// 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/'));
});
```

How to use gulp-util.PluginError:

8
9
10
11
12
13
14
15
16
17

var gutil = require('gulp-util'),
    path = require('path'),
    through = require('through2');

var PluginError = gutil.PluginError;

var resourceUtil = require('./resource');

/**

How to use gulp-util.log:

13
14
15
16
17
18
19
20
21
var tsFiles = [].concat(config.tsFiles, tsUnitFiles);

/* Watch changed typescripts file and compile it */
gulp.task('watch-ts', function () {
    return gulp.watch(tsFiles, function (file) {
        util.log('Compiling ' + file.path + '...');
        return compileTs(file.path, true);
    });
});