官术网_书友最值得收藏!

Managing version numbers

Although we've set up our copy-config and copy-code tasks to substitute the version number whenever {{{VERSION}}} is encountered, we don't have any tasks that actually change the version. We could just edit package.json, of course. But this is tedious and it can't be included automatically in any other Gulp task. Instead, let's use the gulp-bump plugin to take care of this for us.

gulp-bump is a very simple plugin: it is designed to take a package.json (or similar) file and edit the version property based on specific commands. Most versions are of the major.minor.patch form and we can ask it to increment any portion by one. If you wanted, you could increment the patch portion of the version to automatically track build numbers, for example.

Doing this is pretty simple. Let's first create another utility file, this time called gulp/utils/bump.js:

var gulp = require("gulp");
var bump = require("gulp-bump");

module.exports = function bump(importance) {
  return gulp.src([path.join(process.cwd(), "package.json")])
             .pipe(bump({type: importance}))
             .pipe(gulp.dest(process.cwd()));
}

The importance variable can be one of the following strings: major, minor, or patch. Next, let's create three tasks that will allow us to call this method directly (again, these are in three separate files, indicated in the comment):

// gulp/tasks/version-bump-patch.js
var bump = require("../utils/bump");
module.exports = {
    task: bump.bind(null, "patch")
}

// gulp/tasks/version-bump-minor.js
var bump = require("../utils/bump");
module.exports = {
    task: bump.bind(null, "minor")
}

// gulp/tasks/version-bump-major.js
var bump = require("../utils/bump");
module.exports = {
    task: bump.bind(null, "major")
}

Now you can directly bump the version number by executing gulp version-bump-patch. This, however, only edits package.json. If you want the files in build/ to reflect this, you will need to also execute gulp copy (or build and so on).

主站蜘蛛池模板: 邵阳县| 张家界市| 云霄县| 突泉县| 宜兰县| 简阳市| 介休市| 汉阴县| 玉树县| 南木林县| 民乐县| 弥渡县| 德化县| 柏乡县| 延津县| 奈曼旗| 长治县| 钟祥市| 卫辉市| 齐齐哈尔市| 光泽县| 老河口市| 文化| 吉林市| 海伦市| 齐河县| 东源县| 苍溪县| 班戈县| 沁源县| 吐鲁番市| 邵武市| 应城市| 平阳县| 枣阳市| 谷城县| 汾西县| 鄯善县| 奇台县| 丹棱县| 淮南市|