Skip to content

Instantly share code, notes, and snippets.

@panbanda
Created July 24, 2016 22:03
Show Gist options
  • Save panbanda/4ee433736f29881dc64719b15f5f9735 to your computer and use it in GitHub Desktop.
Save panbanda/4ee433736f29881dc64719b15f5f9735 to your computer and use it in GitHub Desktop.
Gulpfile for bumping versions with semver
var gulp = require('gulp'),
git = require('gulp-git'),
filter = require('gulp-filter'),
bump = require('gulp-bump'),
semver = require('semver'),
fs = require('fs'),
tagVersion = require('gulp-tag-version');
// Loads the package for parsing
function getPackageJson() {
return JSON.parse(fs.readFileSync('./package.json', 'utf8'));
}
// Increments the version using semver
function inc(type) {
var pkg = getPackageJson();
var newVer = semver.inc(pkg.version, type);
return gulp.src(['./package.json'])
.pipe(bump({ version: newVer }))
.pipe(gulp.dest('./'))
.pipe(git.commit('Tagged new version [' + newVer + ']'))
.pipe(filter('package.json'))
.pipe(tagVersion());
}
gulp.task('bump:major', function() { return inc('major'); });
gulp.task('bump:minor', function() { return inc('minor'); });
gulp.task('bump:patch', function() { return inc('patch'); });
gulp.task('bump', ['bump:patch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment