UNPKG

1.12 kBPlain TextView Raw
1import _ from 'lodash';
2import { getCommitHistory } from './get-commit-history';
3import { getLastTag } from './get-last-tag';
4
5/**
6 * Analyses all commits after last git tag and calls cb with one of
7 * "major", "minor", "patch" as a second parameter or ERROR_NO_CHANGES by default as first parameter.
8 * Looks for [major], [minor] in commit history.
9 *
10 */
11export default async function getVersionType() {
12 const lastTag = await getLastTag();
13
14 // Take the whole log when no tags found
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 // find the first item from the commit history matching the release type
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}