UNPKG

2.06 kBJavaScriptView Raw
1"use strict";
2
3var git = require("gulp-git");
4var bump = require("gulp-bump");
5var prompt = require("gulp-prompt");
6var shell = require("gulp-shell");
7var tagVersion = require("gulp-tag-version");
8var addSrc = require("gulp-add-src");
9var gulpIf = require("gulp-if");
10var conventionalChangelog = require("gulp-conventional-changelog");
11
12var changelogSource = "CHANGELOG.md";
13var pkgSource = "package.json";
14
15var versionTypes = ["patch", "minor", "major", "prerelease"];
16
17module.exports = function(gulp, depends, options) {
18 options = options || {};
19
20 function increment(type) {
21 // get all the files to bump version in
22 return gulp.src(pkgSource)
23 // bump the version number in those files
24 .pipe(bump({type: type}))
25 // save it back to filesystem
26 .pipe(gulp.dest("./"))
27 // commit the changed version number
28 .pipe(git.commit("chore(release): bump version"))
29 // update the CHANGELOG
30 .pipe(addSrc(changelogSource))
31 .pipe(gulpIf(changelogSource, conventionalChangelog({
32 preset: options.changelogConvention || "angular"
33 })))
34 .pipe(gulpIf(changelogSource, gulp.dest("./")))
35 .pipe(git.commit("chore(release): update CHANGELOG"))
36 // tag it
37 .pipe(gulpIf(pkgSource, tagVersion()))
38 // push it all
39 // can't use git.push until this is resolved...
40 // https://github.com/ikari-pl/gulp-tag-version/issues/8
41 //.pipe(git.push("origin", "master", {args: "--tags"}));
42 .pipe(shell("git push origin master --tags"));
43 }
44
45 gulp.task("release", depends, function(done) {
46 return gulp.src(pkgSource)
47 .pipe(prompt.prompt({
48 type: "checkbox",
49 name: "type",
50 message: "What type of release would you like to do?",
51 choices: versionTypes
52 }, function(result){
53 var type = result.type[0];
54 if (type) {
55 return increment(type);
56 }
57 }));
58 });
59
60 versionTypes.forEach(function(version) {
61 gulp.task("release:" + version, depends, increment.bind(increment, version));
62 });
63};