Gulp plugin for bumping semantic versions in files with support for any semver format in any file type
npx @tessl/cli install tessl/npm-gulp-bump@3.2.0gulp-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.
npm install gulp-bump --save-devvar bump = require('gulp-bump');For ES6 modules:
import bump from 'gulp-bump';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('./'));
});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('./'));
});// 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}
});
});The plugin processes files through a transform stream and:
bumpData object to file with version informationquiet: true)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.
The plugin throws PluginError instances for:
file.isStream() is truegulp.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('./'));
});gulp-bump relies on these key dependencies: