-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
110 lines (102 loc) · 2.81 KB
/
index.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
'use strict';
/**
* @module gulp-gitflow
*/
const argv = require('yargs')
.alias('v', 'version')
.alias('t', 'type')
.alias('m', 'message')
.alias('p', 'push')
.alias('c', 'codenames')
.normalize('c').argv;
const compact = require('lodash/compact');
const spread = require('lodash/spread');
const semver = require('semver');
const sequence = require('run-sequence');
const util = require('gulp-util');
const GitflowRelease = require('./lib/release');
// Default config values if none are given
// during plugin initialization
const DEFAULTS = {
tasks: {
release: 'release'
},
messages: {
bump: 'Bump release version',
next: 'Set next development version'
}
};
class GitflowRegistry {
constructor(options) {
this.options = Object.assign({}, DEFAULTS, options);
}
init(taker) {
const release = new GitflowRelease(this.options);
taker.task('release:start', done =>
release.start(argv.version, argv.type, done)
);
taker.task('release:finish', done => release.finish(argv.message, done));
taker.task('release:push', release.push);
taker.task('release:commit', () =>
release.commit(this.options.messages.bump)
);
taker.task('release:commit:next', () =>
release.commit(this.options.messages.next)
);
taker.task('bump', () => {
if (argv.version || argv.type) {
return release.bump(
argv.version,
argv.type,
argv.message,
argv.codenames
);
}
const ver = semver.inc(release.version(), 'patch');
return release.bump(ver, null, argv.message);
});
taker.task('bump:next', () => {
const ver = semver.inc(release.version(), 'patch');
const devSuffix = this.options.devSuffix || '-dev';
return release.bump(ver + devSuffix, null, argv.message, argv.codenames);
});
function done(cb) {
return () => {
if (argv.p) {
util.log(
util.colors.cyan('[gulp-release]') +
' All done: tags and branches pushed to ' +
util.colors.magenta('origin')
);
} else {
util.log(
util.colors.cyan('[gulp-release]') +
' All done: review changes and push to ' +
util.colors.magenta('origin')
);
}
return cb();
};
}
const recipes = {
release: compact([
'release:start',
'bump',
'release:commit',
'release:finish',
'bump:next',
'release:commit:next',
argv.p ? 'release:push' : undefined
])
};
taker.task(this.options.tasks.release, cb =>
spread(sequence)(recipes.release.concat(done(cb)))
);
}
}
module.exports = {
register: function(taker, options) {
const registry = new GitflowRegistry(options);
registry.init(taker);
}
};