forked from intlify/vue-i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ship.config.js
99 lines (94 loc) · 2.94 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
89
90
91
92
93
94
95
96
97
98
99
import execa from 'execa'
import path from 'path'
import { promises as fs, readFileSync } from 'fs'
const dirname = path.dirname(new URL(import.meta.url).pathname)
async function readJson(target) {
const file = await fs.readFile(target, 'utf8')
return JSON.parse(file)
}
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 fs.readFile('./CHANGELOG.md', 'utf8')
return fs.writeFile('./CHANGELOG.md', `${head}\n\n${changelog}`)
}
export default {
mergeStrategy: { toSameBranch: ['master'] },
monorepo: {
mainVersionFile: 'package.json',
packagesToBump: [
'packages/shared',
'packages/message-compiler',
'packages/core-base',
'packages/core',
'packages/devtools-if',
'packages/vue-devtools',
'packages/vue-i18n-core',
'packages/vue-i18n',
'packages/petite-vue-i18n',
'packages/vue-i18n-bridge'
],
packagesToPublish: [
'packages/shared',
'packages/message-compiler',
'packages/core-base',
'packages/core',
'packages/devtools-if',
'packages/vue-devtools',
'packages/vue-i18n-core',
'packages/vue-i18n',
'packages/petite-vue-i18n',
'packages/vue-i18n-bridge'
]
},
updateChangelog: false,
installCommand: () => 'pnpm install --silent',
buildCommand: ({ isYarn, version }) => 'pnpm build:type',
beforeCommitChanges: async ({ nextVersion, exec, dir }) => {
const pkg = await readJson(path.resolve(dirname, './package.json'))
await commitChangelog(pkg.version, nextVersion)
await exec('pnpm 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 = readFileSync(changelogPath, 'utf-8')
const ret = extractSpecificChangelog(changelogFile, version)
return ret
} catch (err) {
if (err.code === 'ENOENT') {
return null
}
throw err
}
}
}
}