-
Notifications
You must be signed in to change notification settings - Fork 10
/
semver.js
54 lines (48 loc) · 1.42 KB
/
semver.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
const semver = require('semver');
const { red } = require('chalk');
function getNewVersion(options, version) {
const semverList = [
['patch', 'Bump version '],
['minor', 'Release version '],
['major', 'Release major version ']
];
const preSemverList = [
'prepatch',
'preminor',
'premajor',
'prerelease'
];
const metadata = {};
/**
*
* @param {String} v old version
* @param {String} release patch | minor | major | prepatch | premajor | preminor | prerelease
* @param identifier
*/
function increase(v, release, identifier) {
return semver.inc(v, release, identifier);
}
semverList.forEach((sem) => {
if (options[sem[0]]) {
if (metadata.version) {
console.error(`${red('You specified more than one semver type, please specify only one!')}`);
process.exit(1);
}
metadata.version = increase(version, sem[0]);
metadata.prefix = sem[1];
}
});
preSemverList.forEach((sem) => {
if (options[sem]) {
if (metadata.version) {
console.error(`${red('You specified more than one semver type, please specify only one!')}`);
process.exit(1);
}
const identifier = typeof options[sem] === 'boolean' ? 'beta' : options[sem];
metadata.version = increase(version, sem, identifier);
metadata.prefix = `Prerelease ${identifier} version `;
}
});
return metadata;
}
module.exports = getNewVersion;