-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathbump.js
117 lines (103 loc) · 3.33 KB
/
bump.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var bump = require('gulp-bump');
var changelog = require('gulp-conventional-changelog');
var git = require('gulp-git');
var gulp = require('gulp');
var pkg = require('../package');
var prompt = require('gulp-prompt');
var semver = require('semver');
var touch = require('gulp-touch');
var version = pkg.version;
function getVersionQuestion(currentVersion) {
var patchVersion = semver.inc(currentVersion, 'patch');
var minorVersion = semver.inc(currentVersion, 'minor');
var majorVersion = semver.inc(currentVersion, 'major');
return [
{
type: 'list',
name: 'version',
message: 'What type of release would you like to do? Current version: ' + currentVersion,
choices: [
{
value: patchVersion,
name: patchVersion + ' - PATCH version when you make backwards-compatible bug fixes',
},
{
value: minorVersion,
name: minorVersion + ' - MINOR version when you add functionality in a backwards-compatible manner',
},
{
value: majorVersion,
name: majorVersion + ' - MAJOR version when you make incompatible API changes',
},
]
},
];
}
function promptVersionTask() {
var files = ['./package.json'];
var question = getVersionQuestion(pkg.version);
return gulp.src(files)
.pipe(prompt.prompt(question, function(response) {
version = response.version;
return gulp.src(files)
.pipe(bump({ version: version }))
.pipe(gulp.dest('./'))
.pipe(touch());
}));
}
function changelogTask() {
return gulp.src('./CHANGELOG.md')
.pipe(prompt.confirm({
default: true,
message: 'Do you want to auto-update the changelog?',
}))
.pipe(changelog({ buffer: false, preset: 'angular' }))
.pipe(gulp.dest('./'))
.pipe(prompt.confirm({
default: false,
message: 'Are you happy with the generated changelog? If not, please revise it before continuing.',
}));
}
function commitVersionTask() {
var files = [
'./package.json',
'./CHANGELOG.md',
];
return gulp.src(files)
.pipe(git.add())
.pipe(git.commit('Releasing ' + version));
}
function tagVersionTask(done) {
git.tag(version, version, function(tagError) {
if (tagError) {
throw tagError;
}
done();
});
}
function pushTask(done) {
gulp.src('./')
.pipe(prompt.prompt({
name: 'pushTo',
type: 'input',
message: 'Where would you like to push to?',
default: 'origin master',
}, function(response) {
var pushToSplit = response.pushTo ? response.pushTo.split(' ') : [];
var remote = pushToSplit[0];
var branch = pushToSplit[1];
git.push(remote, branch, { args: '--follow-tags' }, function(pushError) {
if (pushError) {
throw pushError;
}
done();
});
}));
}
module.exports = gulp.series(
promptVersionTask,
changelogTask,
commitVersionTask,
tagVersionTask,
pushTask
);