1 | import _ from 'lodash';
|
2 | import { getCommitHistory } from './get-commit-history';
|
3 | import { getLastTag } from './get-last-tag';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export default async function getVersionType() {
|
12 | const lastTag = await getLastTag();
|
13 |
|
14 |
|
15 | const commitRange = lastTag === '' ? '' : `${lastTag}..HEAD`;
|
16 |
|
17 | const commitHistory = await getCommitHistory(commitRange);
|
18 | if (commitHistory === '') {
|
19 | throw new Error('No changes in git');
|
20 | }
|
21 |
|
22 |
|
23 | const versionType = _.find(
|
24 | ['dev', 'major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', 'prerelease'],
|
25 | (item) => _.includes(commitHistory, `[${item}]`),
|
26 | );
|
27 | if (!versionType) {
|
28 | throw new Error("Can't recognise the release type! Please make sure the repo follows the commit message standard.");
|
29 | }
|
30 |
|
31 | return versionType;
|
32 | }
|