Created
October 6, 2014 18:49
-
-
Save dancashman/555fdb02cb42e19764e6 to your computer and use it in GitHub Desktop.
Simple example using gulp-bump and yargs to manage version.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var gulp = require('gulp'), | |
$ = require('gulp-load-plugins')({ | |
pattern: [ | |
'gulp-*', | |
'yargs' | |
] | |
}); | |
$.yargs | |
.alias('h', 'help') | |
.describe('help', 'Show this help information.') | |
.check (function (argv) { | |
if (argv.help) { | |
throw new Error ('Help!'); | |
} | |
}); | |
gulp.task('bump', function () { | |
var argv, opts; | |
argv = $.yargs.usage( | |
'Bump the package version. ' + | |
'With no options, bumps to the next patch version. ' + | |
'Usage: gulp bump [--major | --minor | --patch | --to x.x.x]' | |
) | |
.options({ | |
major: { | |
describe: 'Bump the package to the next major version (1.x.x to 2.0.0)' | |
}, | |
minor: { | |
describe: 'Bump the package to the next minor version (1.0.x to 1.1.0)' | |
}, | |
patch: { | |
describe: 'Bump the package to the next patch version (1.0.0 to 1.0.1)' | |
}, | |
to: { | |
describe: 'Bump the package to the specified version' | |
} | |
}).check(function (argv) { | |
if (argv.major && argv.minor) { | |
throw new Error('Cannot specify both major and minor'); | |
} else if (argv.major && argv.patch) { | |
throw new Error('Cannot specify both major and patch'); | |
} else if (argv.major && argv.to) { | |
throw new Error('Cannot specify both major and version'); | |
} else if (argv.minor && argv.patch) { | |
throw new Error('Cannot specify both minor and patch'); | |
} else if (argv.minor && argv.to) { | |
throw new Error('Cannot specify both minor and version'); | |
} else if (argv.patch && argv.to) { | |
throw new Error('Cannot specify both patch and version'); | |
} | |
}).argv; | |
opts = argv.to ? { | |
version: argv.to | |
} : argv.major ? { | |
type: 'major' | |
} : argv.minor ? { | |
type: 'minor' | |
} : { | |
type: 'patch' | |
}; | |
return gulp.src([ | |
'./bower.json', | |
'./package.json' | |
]) | |
.pipe($.bump(opts)) | |
.pipe(gulp.dest('./')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment