1 | 'use strict'
|
2 |
|
3 | const la = require('lazy-ass')
|
4 | const is = require('check-more-types')
|
5 | const debug = require('debug')('next-ver')
|
6 | const semver = require('semver')
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function increment (version, type) {
|
20 | debug('incrementing %s by %s', version, type)
|
21 | if (!type) {
|
22 | return
|
23 | }
|
24 | la(isSemanticChange(type), 'invalid change', type)
|
25 |
|
26 | if (!is.semver(version)) {
|
27 | debug('cleaning starting version %s', version)
|
28 | version = semver.clean(version)
|
29 | debug('got version %s', version)
|
30 | }
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | la(is.unemptyString(version), 'missing starting version', version)
|
36 |
|
37 | const semverIncrement = semverType(type)
|
38 | if (!semverIncrement) {
|
39 | return
|
40 | }
|
41 | return semver.inc(version, semverIncrement)
|
42 | }
|
43 |
|
44 | function isSemanticChange (type) {
|
45 | return is.oneOf(['major', 'feat', 'fix', 'chore'], type)
|
46 | }
|
47 |
|
48 | function semverType (type) {
|
49 | const types = {
|
50 | major: 'major',
|
51 | feat: 'minor',
|
52 | fix: 'patch'
|
53 | }
|
54 | return types[type]
|
55 | }
|
56 |
|
57 | module.exports = increment
|