1 | const R = require('ramda')
|
2 | const la = require('lazy-ass')
|
3 | const is = require('check-more-types')
|
4 | const increment = require('./increment')
|
5 | const debug = require('debug')('next-ver')
|
6 | const ggit = require('ggit')
|
7 | const computeTopChange = require('largest-semantic-change').topChange
|
8 | const parseCommit = require('./parse-commit')
|
9 |
|
10 | function addSemverInformation (commits) {
|
11 | return commits.map(parseCommit)
|
12 | }
|
13 |
|
14 | function onlySemanticCommits (commits) {
|
15 | return commits.filter(R.prop('semver'))
|
16 | }
|
17 |
|
18 | function printFoundSemanticCommits (commits) {
|
19 | debug('semantic commits')
|
20 | debug(commits)
|
21 | la(is.array(commits), 'expected list of commits', commits)
|
22 | }
|
23 |
|
24 | function printChange (feat) {
|
25 | debug('semantic change "%s"', feat)
|
26 | la(is.maybe.string(feat), 'expected change to be a string', feat)
|
27 | }
|
28 |
|
29 | function printCommitsAfterTag (list) {
|
30 | debug('commits after last tag')
|
31 | debug(JSON.stringify(list, null, 2))
|
32 | }
|
33 |
|
34 | function 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 |
|
51 | module.exports = computeNextVersion
|