1 | "use strict";
|
2 |
|
3 | var git = require("gulp-git");
|
4 | var bump = require("gulp-bump");
|
5 | var prompt = require("gulp-prompt");
|
6 | var shell = require("gulp-shell");
|
7 | var tagVersion = require("gulp-tag-version");
|
8 | var addSrc = require("gulp-add-src");
|
9 | var gulpIf = require("gulp-if");
|
10 | var conventionalChangelog = require("gulp-conventional-changelog");
|
11 |
|
12 | var changelogSource = "CHANGELOG.md";
|
13 | var pkgSource = "package.json";
|
14 |
|
15 | var versionTypes = ["patch", "minor", "major", "prerelease"];
|
16 |
|
17 | module.exports = function(gulp, depends, options) {
|
18 | options = options || {};
|
19 |
|
20 | function increment(type) {
|
21 |
|
22 | return gulp.src(pkgSource)
|
23 |
|
24 | .pipe(bump({type: type}))
|
25 |
|
26 | .pipe(gulp.dest("./"))
|
27 |
|
28 | .pipe(git.commit("chore(release): bump version"))
|
29 |
|
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 |
|
37 | .pipe(gulpIf(pkgSource, tagVersion()))
|
38 |
|
39 |
|
40 |
|
41 |
|
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 | };
|