This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ship.config.js
58 lines (52 loc) · 1.95 KB
/
ship.config.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
55
56
57
58
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const semver = require('semver')
const keepachangelog = require('keepachangelog')
// eslint-disable-next-line no-undef
module.exports = {
updateChangelog: false,
formatCommitMessage: ({ version, _releaseType, _baseBranch }) => `Release v${version}`,
formatPullRequestTitle: ({ version, _releaseType }) => `Release v${version}`,
getNextVersion: ({ _revisionRange, _commitTitles, _commitBodies, currentVersion, dir }) => {
const changelogFile = `${dir}/CHANGELOG.md`
const content = fs.readFileSync(changelogFile, 'utf8')
const changelog = keepachangelog.parse(content)
return getNextVersion(changelog, currentVersion)
},
beforeCommitChanges: ({ nextVersion, _releaseType, _exec, dir }) => {
const changelogFile = `${dir}/CHANGELOG.md`
const content = fs.readFileSync(changelogFile, 'utf8')
const changelog = keepachangelog.parse(content)
changelog.addRelease(nextVersion)
fs.writeFileSync(changelogFile, changelog.build(), 'utf8')
},
shouldPrepare: ({ nextVersion, commitNumbersPerType }) => {
return !!nextVersion
}
}
function getNextVersion(changelog, currentVersion, releaseTag = 'latest') {
const parsedVersion = semver.parse(currentVersion)
const upcomingRelease = changelog.getRelease('upcoming') || { version: 'upcoming' }
let releaseType
if (upcomingRelease.Changed?.length > 0) {
releaseType = 'major'
} else if (upcomingRelease.Added?.length > 0) {
releaseType = 'minor'
} else if (upcomingRelease.Fixed?.length > 0) {
releaseType = 'patch'
} else {
return null
}
if (releaseTag !== 'latest') {
if (parsedVersion.prerelease.length) {
parsedVersion.inc('prerelease', releaseTag)
} else {
parsedVersion.inc(releaseType)
parsedVersion.prerelease = [ releaseTag, 0 ]
parsedVersion.format()
}
} else {
parsedVersion.inc(releaseType)
}
return parsedVersion.version
}