How to use the colors function from gulp-util

Find comprehensive JavaScript gulp-util.colors code examples handpicked from public code repositorys.

gulp-util.colors is a utility function in Gulp that allows you to colorize console output.

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))
fork icon372
star icon0
watch icon355

+ 3 other calls in file

39
40
41
42
43
44
45
46
47
48
## Usage

```javascript
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 = {
fork icon104
star icon0
watch icon2

+ 3 other calls in file

How does gulp-util.colors work?

The gulp-util.colors module provides an interface to colorize text in the console output of Gulp. Specifically, it defines a set of pre-defined color codes that can be used to format text, as well as a method for generating custom color codes using RGB values. When used with Gulp, it can be used to add visual cues to the output of a build process or task.

-3
fork icon36
star icon135
watch icon29

+ 11 other calls in file

481
482
483
484
485
486
487
488
489
490
491
492


// Setup pretty error handling
var reportError = function (error) {
    var lineNumber = (error.lineNumber) ? 'LINE ' + error.lineNumber + ' -- ' : '';
    var report = '';
    var chalk = gutil.colors.white.bgRed;


    // Shows a pop when errors
    notify({
        title: 'Task Failed [' + error.plugin + ']',
fork icon6
star icon5
watch icon4

Ai Example

1
2
3
4
const gutil = require("gulp-util");

// Log a message with a red background and white text
console.log(gutil.colors.bgRed.white("Error!"));

This will log the message "Error!" with a red background and white text in the console.

37
38
39
40
41
42
43
44
45
46
47
var banner = _.template(buildConfig.banner, { pkg: pkg });


var IS_RELEASE_BUILD = !!argv.release;
if (IS_RELEASE_BUILD) {
  gutil.log(
    gutil.colors.red('--release:'),
    'Building release version (minified, debugs stripped)...'
  );
}

fork icon2
star icon3
watch icon15

22
23
24
25
26
27
28
29
30
31
.pipe(bump({type: type}))
.pipe(gulp.dest('./'))
.pipe(tap(function(file, t) {
  version = JSON.parse(file.contents.toString()).version;
})).on('end', function() {
  var color = gutil.colors;
  gulp.src('')
    .pipe(shell([
      'git commit --all --message "Version ' + version + '"',
      (type != 'patch' ? 'git tag --annotate "v' + version + '" --message "Version ' + version + '"' : 'true')
fork icon0
star icon2
watch icon0

157
158
159
160
161
162
163
164
165
166
    this.emit("end");
})
.on("end", function() {
    var end = process.hrtime(start);
    gutil.log("Finished '" + gutil.colors.cyan("browserify " + name) + "' after",
        gutil.colors.magenta(prettyTime(end)));
})
.pipe(source(name))
.pipe(gulp.dest(BUILD_DIST_DIR))
.pipe(buffer())
fork icon0
star icon0
watch icon0