UNPKG

1.46 kBJavaScriptView Raw
1const R = require('ramda')
2const la = require('lazy-ass')
3const is = require('check-more-types')
4const increment = require('./increment')
5const debug = require('debug')('next-ver')
6const ggit = require('ggit')
7const computeTopChange = require('largest-semantic-change').topChange
8const parseCommit = require('./parse-commit')
9
10function addSemverInformation (commits) {
11 return commits.map(parseCommit)
12}
13
14function onlySemanticCommits (commits) {
15 return commits.filter(R.prop('semver'))
16}
17
18function printFoundSemanticCommits (commits) {
19 debug('semantic commits')
20 debug(commits)
21 la(is.array(commits), 'expected list of commits', commits)
22}
23
24function printChange (feat) {
25 debug('semantic change "%s"', feat)
26 la(is.maybe.string(feat), 'expected change to be a string', feat)
27}
28
29function printCommitsAfterTag (list) {
30 debug('commits after last tag')
31 debug(JSON.stringify(list, null, 2))
32}
33
34function computeNextVersion (currentVersionTag) {
35 la(is.unemptyString(currentVersionTag),
36 'missing current version', currentVersionTag)
37
38 const incrementVersion = increment.bind(null, currentVersionTag)
39
40 return ggit.commits.afterLastTag()
41 .then(R.tap(printCommitsAfterTag))
42 .then(addSemverInformation)
43 .then(onlySemanticCommits)
44 .then(R.tap(printFoundSemanticCommits))
45 .then(R.map(R.prop('semver')))
46 .then(computeTopChange)
47 .then(R.tap(printChange))
48 .then(incrementVersion)
49}
50
51module.exports = computeNextVersion