This repository has been archived by the owner on Nov 21, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.js
88 lines (72 loc) · 2.12 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
'use strict';
var concat = require('concat-stream');
var conventionalCommitsFilter = require('conventional-commits-filter');
var conventionalCommitsParser = require('conventional-commits-parser');
var gitLatestSemverTag = require('git-latest-semver-tag');
var gitRawCommits = require('git-raw-commits');
var objectAssign = require('object-assign');
var VERSIONS = ['major', 'minor', 'patch'];
function conventionalRecommendedBump(options, parserOpts, cb) {
var config;
var noop = function() {};
if (typeof options !== 'object') {
throw new TypeError('options must be an object');
}
if (typeof parserOpts === 'function') {
cb = parserOpts;
} else {
cb = cb || noop;
}
options = objectAssign({
ignoreReverted: true,
warn: function() {}
}, options);
if (options.preset) {
try {
config = require('./presets/' + options.preset);
} catch (err) {
cb(new Error('Preset: "' + options.preset + '" does not exist'));
return;
}
} else {
config = options.config || {};
}
var whatBump = options.whatBump || config.whatBump || noop;
parserOpts = objectAssign({}, config.parserOpts, parserOpts);
parserOpts.warn = parserOpts.warn || options.warn;
gitLatestSemverTag(function(err, tag) {
if (err) {
cb(err);
return;
}
gitRawCommits({
format: '%B%n-hash-%n%H',
from: tag
})
.pipe(conventionalCommitsParser(parserOpts))
.pipe(concat(function(data) {
var commits;
if (options.ignoreReverted) {
commits = conventionalCommitsFilter(data);
} else {
commits = data;
}
if (!commits || !commits.length) {
options.warn('No commits since last release');
}
var result = whatBump(commits);
if (typeof result === 'number') {
result = {
level: result
};
}
if (result && result.level != null) {
result.releaseType = VERSIONS[result.level];
} else if (result == null) {
result = {};
}
cb(null, result);
}));
});
}
module.exports = conventionalRecommendedBump;