Skip to content

Commit

Permalink
Added gulp version task
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jun 11, 2015
1 parent 5d3e8f6 commit 7aab780
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions build/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var gulp = require('gulp'),
bump = require('gulp-bump'),
gutil = require('gulp-util'),
git = require('gulp-git'),
minimist = require('minimist'),
semver = require('semver');

var paths = require('./paths');

function getPackageJsonVersion() {
//We parse the json file instead of using require because require caches multiple calls so the version number won't be updated
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
};

gulp.task('version-bump', function () {
var args = minimist(process.argv);

var ver = args._.pop();
var options = {};
if (semver.valid(ver)) options.version = ver;
else options.type = ver;

return gulp.src(['./package.json'])
.pipe(bump(options).on('error', gutil.log))
.pipe(gulp.dest('./'));
});

gulp.task('version-commit', function () {
var version = getPackageJsonVersion();
return gulp.src('.')
.pipe(git.commit('Version ' + version, { args: '-a' }));
});

gulp.task('version-push', function (cb) {
git.push('origin', 'master', cb);
});

gulp.task('version-tag', function (cb) {
var version = getPackageJsonVersion();
git.tag(version, 'Version ' + version, function (error) {
if (error) {
return cb(error);
}
git.push('origin', 'master', { args: '--tags' }, cb);
});
});

gulp.task('version', function (callback) {
runSequence(
'version-bump',
'version-commit',
'version-push',
'version-tag',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('Version set and comitted successfully');
}
callback(error);
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

"gulp": "^3.9.0",
"del": "^1.2.0",
"minimist": "^1.1.1",
"require-dir": "~0.3.0",
"run-sequence": "^1.1.0",
"gulp-typescript": "^2.7.6",
Expand Down

0 comments on commit 7aab780

Please sign in to comment.