First of all, I wanted to have the following steps performed by this gulp task:
- bump the version in package.json to the next one (1.3.21)
- commit this change
- tag the change with this version (1.3.21)
- bump the version in package.json to the next pre-release (1.3.22-0)
- commit this change
- push all commits to git
Next thing I wanted to solve: when testing this feature, I did not want to have all the test commits in the git repo. So want to add a different repository to my project, you know, git is a distributed version control system, so it supports multiple repositories.
So I created another repo in a folder right next to my project, initialized that folder as a bare git repo, added it to my project and used a different push mechanism to add my commits. Btw. VSCode has menu support for this, use "push to".
mkdir bare-repo
cd bare-repo
git --bare init
cd ..
git clone http://my-remote-repo
cd my-work-folder
git remote add reltest ../bare-repo/
git remote
git push reltest master
Now I can make changes, commit and push them without messing up my origin repository with all those test commits.
Next, make gulp do it's magic. I want to use semantic versioning, so I'm basically fine with options for major, minor and patch. But I want pre-release versions also being built by this task. And maybe one day I would also like to directly set the version.
var gulp = require('gulp');
/**
* bump the version in package.json to the next value
*/
var bump = function (options) {
var gulpBump = require('gulp-bump');
if (!options) options = {type:"prerelease"};
return gulp.src(['./package.json'])
.pipe(gulpBump(options))
.pipe(gulp.dest('./'));
}
/**
* do the release
*/
gulp.task('release-do', function (done) {
// --bump.version=1.2.3 : bumps 1.2.3
// --bump.type=major : bumps 1.0.0
// --bump.type=minor : bumps 0.1.0
// --bump.type=patch : bumps 0.0.2
// --bump.type=prerelease : bumps 0.0.1-2 (default)
const git = require('gulp-git');
const tagVersion = require('gulp-tag-version');
const argv = require('yargs').argv;
var options;
if (argv.bump) {
options = {};
if (argv.bump.version) {
options.version = argv.bump.version;
} else if (argv.bump.type) {
options.type = argv.bump.type;
}
} return bump(options) // set release version .pipe(git.add()) // add to staging area .pipe(gulp.dest('./')) // write .pipe(git.commit('gulp release')) // commit release version .pipe(tagVersion()); // tag }); /** * prepare for next prerelease */ gulp.task('release-next', function (done) { const git = require('gulp-git'); return bump({type:"prerelease"}) .pipe(git.add())
.pipe(gulp.dest('./'))
.pipe(git.commit('gulp release'))
}); /** * push all changes to git */ gulp.task('release-push', function (done) { // --repository=origin // --branch=master const git = require('gulp-git'); const argv = require('yargs').argv; var repository = argv.repository ? argv.repository : 'origin'; var branch = argv.branch ? argv.branch : 'master'; return git.push(repository, branch, done); }); gulp.task('release', gulp.series('release-do', 'release-next', 'release-push'));
if (argv.bump.version) {
options.version = argv.bump.version;
} else if (argv.bump.type) {
options.type = argv.bump.type;
}
} return bump(options) // set release version .pipe(git.add()) // add to staging area .pipe(gulp.dest('./')) // write .pipe(git.commit('gulp release')) // commit release version .pipe(tagVersion()); // tag }); /** * prepare for next prerelease */ gulp.task('release-next', function (done) { const git = require('gulp-git'); return bump({type:"prerelease"}) .pipe(git.add())
.pipe(gulp.dest('./'))
.pipe(git.commit('gulp release'))
}); /** * push all changes to git */ gulp.task('release-push', function (done) { // --repository=origin // --branch=master const git = require('gulp-git'); const argv = require('yargs').argv; var repository = argv.repository ? argv.repository : 'origin'; var branch = argv.branch ? argv.branch : 'master'; return git.push(repository, branch, done); }); gulp.task('release', gulp.series('release-do', 'release-next', 'release-push'));
Now by simply typing
gulp release
I get a new pre-release in git.
If I want to do a major, minor ot patch release
gulp release --bump.type=minor
will do.
Directly setting a version:
gulp release --bump.version=1.3.21
There is also support for the repository and the branch (refspec):
gulp release --bump.type=patch --repository=origin --branch=master
Keine Kommentare:
Kommentar veröffentlichen