This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ship.config.js
70 lines (67 loc) · 2.07 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
59
60
61
62
63
64
65
66
67
68
69
70
const execa = require(require.resolve('execa'))
const { promisify } = require('util')
const fs = require('fs')
const path = require('path')
const read = promisify(fs.readFile)
const write = fs.writeFileSync
function extractSpecificChangelog (changelog, version) {
if (!changelog) {
return null
}
const escapedVersion = version.replace(/\./g, '\\.')
const regex = new RegExp(
`(#+?\\s\\[?v?${escapedVersion}\\]?[\\s\\S]*?)(#+?\\s\\[?v?\\d\\.\\d\\.\\d\\]?)`,
'g'
)
const matches = regex.exec(changelog)
return matches ? matches[1] : null
}
async function commitChangelog (current, next) {
const { stdout } = await execa('npx', ['lerna-changelog', '--next-version', `v${next}`])
const escapedVersion = next.replace(/\./g, '\\.')
const regex = new RegExp(
`(#+?\\s\\[?v?${escapedVersion}\\]?[\\s\\S]*?)(#+?\\s\\[?v?\\d\\.\\d\\.\\d\\]?)`,
'g'
)
const matches = regex.exec(stdout.toString())
const head = matches ? matches[1] : stdout
const changelog = await read('./CHANGELOG.md', 'utf8')
return write('./CHANGELOG.md', `${head}\n\n${changelog}`)
}
module.exports = {
mergeStrategy: { toSameBranch: ['master'] },
monorepo: undefined,
updateChangelog: false,
beforeCommitChanges: ({ nextVersion, exec, dir }) => {
return new Promise(resolve => {
const pkg = require('./package.json')
commitChangelog(pkg.version, nextVersion).then(resolve)
})
},
formatCommitMessage: ({
version,
releaseType,
mergeStrategy,
baseBranch
}) => `${releaseType} release v${version}`,
formatPullRequestTitle: ({
version,
releaseType
}) => `${releaseType} release v${version}`,
shouldRelease: () => true,
releases: {
extractChangelog: ({ version, dir }) => {
const changelogPath = path.resolve(dir, 'CHANGELOG.md')
try {
const changelogFile = fs.readFileSync(changelogPath, 'utf-8').toString()
const ret = extractSpecificChangelog(changelogFile, version)
return ret
} catch (err) {
if (err.code === 'ENOENT') {
return null
}
throw err
}
}
}
}