or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-gulp-bump

Gulp plugin for bumping semantic versions in files with support for any semver format in any file type

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/gulp-bump@3.2.x

To install, run

npx @tessl/cli install tessl/npm-gulp-bump@3.2.0

index.mddocs/

gulp-bump

gulp-bump is a Gulp plugin that provides automated version bumping for npm packages and other files that use semantic versioning (semver). It integrates seamlessly with Gulp build pipelines to increment version numbers across multiple file types including package.json, bower.json, and component.json files.

Package Information

  • Package Name: gulp-bump
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install gulp-bump --save-dev

Core Imports

var bump = require('gulp-bump');

For ES6 modules:

import bump from 'gulp-bump';

Basic Usage

var gulp = require('gulp');
var bump = require('gulp-bump');

// Basic usage - patches the version by default
gulp.task('bump', function(){
  return gulp.src('./package.json')
    .pipe(bump())
    .pipe(gulp.dest('./'));
});

// Specify version increment type
gulp.task('bump', function(){
  return gulp.src('./package.json')
    .pipe(bump({type: 'minor'}))
    .pipe(gulp.dest('./'));
});

// Set specific version
gulp.task('bump', function(){
  return gulp.src('./package.json')
    .pipe(bump({version: '1.2.3'}))
    .pipe(gulp.dest('./'));
});

Capabilities

Version Bumping

Creates a Gulp transform stream for incrementing semantic versions in files.

/**
 * Creates a Gulp transform stream for bumping semantic versions in files
 * @param {BumpOptions} opts - Configuration options for version bumping
 * @returns {Transform} - Gulp-compatible transform stream
 */
function bump(opts);

interface BumpOptions {
  /** Version increment type: 'major', 'minor', 'patch', or 'prerelease' */
  type?: 'major' | 'minor' | 'patch' | 'prerelease';
  /** Specific version to set (overrides type) */
  version?: string;
  /** JSON key name containing the version (default: 'version') */
  key?: string;
  /** Prerelease identifier (used with type='prerelease') */
  preid?: string;
  /** Custom regex pattern for version matching */
  regex?: RegExp;
  /** Suppress console output when true */
  quiet?: boolean;
}

Version Types:

  • major: 1.0.0 → 2.0.0 (breaking changes)
  • minor: 1.0.0 → 1.1.0 (new features)
  • patch: 1.0.0 → 1.0.1 (bug fixes)
  • prerelease: 1.0.0 → 1.0.1-0 (pre-release versions)

Usage Examples:

var gulp = require('gulp');
var bump = require('gulp-bump');

// Patch version bump (default)
gulp.task('patch', function(){
  return gulp.src('./package.json')
    .pipe(bump())
    .pipe(gulp.dest('./'));
});

// Minor version bump
gulp.task('minor', function(){
  return gulp.src('./package.json')
    .pipe(bump({type: 'minor'}))
    .pipe(gulp.dest('./'));
});

// Major version bump
gulp.task('major', function(){
  return gulp.src('./package.json')
    .pipe(bump({type: 'major'}))
    .pipe(gulp.dest('./'));
});

// Set specific version
gulp.task('version', function(){
  return gulp.src('./package.json')
    .pipe(bump({version: '2.1.0'}))
    .pipe(gulp.dest('./'));
});

// Custom version key
gulp.task('custom-key', function(){
  return gulp.src('./config.json')
    .pipe(bump({key: 'appversion'}))
    .pipe(gulp.dest('./'));
});

// Prerelease with identifier
gulp.task('prerelease', function(){
  return gulp.src('./package.json')
    .pipe(bump({type: 'prerelease', preid: 'alpha'}))
    .pipe(gulp.dest('./'));
});

// Multiple files at once
gulp.task('bump-all', function(){
  return gulp.src(['./package.json', './bower.json', './component.json'])
    .pipe(bump({type: 'minor'}))
    .pipe(gulp.dest('./'));
});

// Silent operation
gulp.task('silent-bump', function(){
  return gulp.src('./package.json')
    .pipe(bump({quiet: true}))
    .pipe(gulp.dest('./'));
});

Advanced Usage

// Custom regex for non-standard version formats
gulp.task('custom-format', function(){
  var constant = "MY_PLUGIN_VERSION";
  return gulp.src('./plugin.php')
    .pipe(bump({
      key: constant,
      regex: new RegExp('([<|\'|"]?(' + constant + ')[>|\'|"]?[ ]*[:=,]?[ ]*[\'|"]?[a-z]?)(\\d+.\\d+.\\d+)(-[0-9A-Za-z.-]+)?(\\+[0-9A-Za-z\\.-]+)?([\'|"|<]?)', 'i')
    }))
    .pipe(gulp.dest('./build'));
});

// Access bump data in subsequent tasks
gulp.task('bump-and-tag', function(){
  return gulp.src('./package.json')
    .pipe(bump({type: 'patch'}))
    .pipe(gulp.dest('./'))
    .on('end', function() {
      // file.bumpData contains: {new, prev, type, str}
    });
});

File Processing

The plugin processes files through a transform stream and:

  1. Reads file contents as string
  2. Uses bump-regex library to find and replace version strings
  3. Updates file contents with new version
  4. Adds bumpData object to file with version information
  5. Logs version change to console (unless quiet: true)

Supported File Types

  • JSON files: package.json, bower.json, component.json
  • YAML files: Any .yml or .yaml file with version fields
  • XML files: Any XML with version attributes or elements
  • PHP files: Constants and variables with version strings
  • CSS files: WordPress theme headers and version comments
  • Any text file: With valid semver patterns

File Data Properties

After processing, each file object includes:

interface BumpData {
  /** The new version after bumping */
  new: string;
  /** The previous version before bumping */
  prev: string;
  /** The type of bump performed */
  type: string;
  /** The updated file content string */
  str: string;
}

Accessed via file.bumpData in subsequent Gulp tasks.

Error Handling

The plugin throws PluginError instances for:

  • Streaming not supported: When file.isStream() is true
  • Invalid semver: When version key is not found or contains invalid semver
  • Regex matching failures: When custom regex patterns don't match file content
gulp.task('bump-with-error-handling', function(){
  return gulp.src('./package.json')
    .pipe(bump())
    .on('error', function(err) {
      console.error('Bump failed:', err.message);
      this.emit('end');
    })
    .pipe(gulp.dest('./'));
});

Dependencies

gulp-bump relies on these key dependencies:

  • bump-regex: Core version bumping and regex matching
  • semver: Semantic versioning validation and utilities
  • through2: Stream transformation utilities
  • plugin-error: Gulp plugin error handling
  • plugin-log: Colored console logging for version changes