forked from intlify/vue-i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ship.config.js
88 lines (85 loc) · 2.6 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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: {
mainVersionFile: 'package.json',
packagesToBump: [
'packages/shared',
'packages/message-resolver',
'packages/message-compiler',
'packages/runtime',
'packages/core-base',
'packages/core',
'packages/vue-i18n'
],
packagesToPublish: [
'packages/shared',
'packages/message-resolver',
'packages/message-compiler',
'packages/runtime',
'packages/core-base',
'packages/core',
'packages/vue-i18n'
]
},
updateChangelog: false,
buildCommand: ({ isYarn, version }) => 'yarn build:type',
beforeCommitChanges: async ({ nextVersion, exec, dir }) => {
const pkg = require('./package.json')
await commitChangelog(pkg.version, nextVersion)
await exec('yarn format:package')
},
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
}
}
}
}