-
Notifications
You must be signed in to change notification settings - Fork 8
/
calver-plugin.js
45 lines (36 loc) · 1.08 KB
/
calver-plugin.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
'use strict';
import { Plugin } from 'release-it';
import calver from 'calver/node/lts';
const DEFAULT_FORMAT = 'yy.mm.minor',
DEFAULT_INCREMENT = 'calendar',
FALLBACK_INCREMENT = 'minor';
class CalverPlugin extends Plugin {
getFormat() {
return this.getContext().format || DEFAULT_FORMAT;
}
getInc() {
return this.getContext().increment || DEFAULT_INCREMENT;
}
getFallbackInc() {
return this.getContext().fallbackIncrement || FALLBACK_INCREMENT;
}
getIncrementedVersion(args) {
const {latestVersion} = args || {};
try {
return calver.inc(this.getFormat(), latestVersion, this.getInc());
} catch {
try {
return calver.inc(this.getFormat(), latestVersion, this.getFallbackInc());
} catch {
return latestVersion;
}
}
}
getIncrementedVersionCI() {
return this.getIncrementedVersion(...arguments);
}
getIncrement() {
return this.getIncrementedVersion(...arguments);
}
}
export default CalverPlugin;