Skip to content

Commit 7271f8d

Browse files
committed
goodbye, conventional commits :bye: hello shipjs + lerna-changelog :hi:
1 parent 4a87375 commit 7271f8d

File tree

3 files changed

+88
-5382
lines changed

3 files changed

+88
-5382
lines changed

package.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
"bugs": {
1111
"url": "https://github.com/kazupon/vue-i18n-locale-message/issues"
1212
},
13+
"changelog": {
14+
"labels": {
15+
"Type: Feature": ":star: Features",
16+
"Type: Bug": ":bug: Bug Fixes",
17+
"Type: Security": ":lock: Security Fixes",
18+
"Type: Performance": ":chart_with_upwards_trend: Performance Fixes",
19+
"Type: Improvement": ":zap: Improvement Features",
20+
"Type: Breaking": ":boom: Breaking Change",
21+
"Type: Deprecated": ":warning: Deprecated Features",
22+
"Type: I18n": ":globe_with_meridians: Internationalization",
23+
"Type: A11y": ":wheelchair: Accessibility",
24+
"Type: Documentation": ":pencil: Documentation"
25+
}
26+
},
1327
"dependencies": {
1428
"@vue/component-compiler-utils": "^3.0.0",
1529
"debug": "^4.1.1",
@@ -33,14 +47,13 @@
3347
"@typescript-eslint/eslint-plugin": "^2.7.0",
3448
"@typescript-eslint/parser": "^2.7.0",
3549
"@typescript-eslint/typescript-estree": "^2.7.0",
36-
"conventional-changelog-cli": "^2.0.21",
37-
"conventional-github-releaser": "^3.1.3",
3850
"eslint": "^6.6.0",
3951
"eslint-plugin-vue-libs": "^4.0.0",
40-
"git-commit-message-convention": "git://github.com/kazupon/git-commit-message-convention.git",
4152
"jest": "^24.9.0",
4253
"jest-watch-typeahead": "^0.4.2",
54+
"lerna-changelog": "^1.0.0",
4355
"opener": "^1.5.1",
56+
"shipjs": "^0.11.3",
4457
"ts-jest": "^24.0.2",
4558
"typescript": "^3.7.3",
4659
"typescript-eslint-language-service": "^1.3.0",
@@ -75,11 +88,11 @@
7588
"scripts": {
7689
"build": "tsc -p .",
7790
"build:watch": "tsc -p . --watch",
78-
"changelog": "conventional-changelog -i CHANGELOG.md -s -n ./node_modules/git-commit-message-convention/convention.js",
7991
"clean": "rm -rf ./coverage && rm -rf ./lib/*.js*",
8092
"coverage": "opener coverage/lcov-report/index.html",
8193
"lint": "eslint ./src ./test --ext .ts",
82-
"release": "conventional-github-releaser -n ./node_modules/git-commit-message-convention/convention.js",
94+
"release:prepare": "shipjs prepare",
95+
"release:trigger": "shipjs trigger",
8396
"test": "npm run lint && npm run test:cover",
8497
"test:cover": "npm run test:unit -- --coverage",
8598
"test:unit": "jest --env node",

ship.config.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const execa = require(require.resolve('execa'))
2+
const { promisify } = require('util')
3+
const fs = require('fs')
4+
const path = require('path')
5+
const read = promisify(fs.readFile)
6+
const write = fs.writeFileSync
7+
8+
function extractSpecificChangelog (changelog, version) {
9+
if (!changelog) {
10+
return null
11+
}
12+
const escapedVersion = version.replace(/\./g, '\\.')
13+
const regex = new RegExp(
14+
`(#+?\\s\\[?v?${escapedVersion}\\]?[\\s\\S]*?)(#+?\\s\\[?v?\\d\\.\\d\\.\\d\\]?)`,
15+
'g'
16+
)
17+
const matches = regex.exec(changelog)
18+
return matches ? matches[1] : null
19+
}
20+
21+
async function commitChangelog (current, next) {
22+
const { stdout } = await execa('npx', ['lerna-changelog', '--next-version', `v${next}`])
23+
const escapedVersion = next.replace(/\./g, '\\.')
24+
const regex = new RegExp(
25+
`(#+?\\s\\[?v?${escapedVersion}\\]?[\\s\\S]*?)(#+?\\s\\[?v?\\d\\.\\d\\.\\d\\]?)`,
26+
'g'
27+
)
28+
const matches = regex.exec(stdout.toString())
29+
const head = matches ? matches[1] : stdout
30+
const changelog = await read('./CHANGELOG.md', 'utf8')
31+
return write('./CHANGELOG.md', `${head}\n\n${changelog}`)
32+
}
33+
34+
module.exports = {
35+
mergeStrategy: { toSameBranch: ['master'] },
36+
monorepo: undefined,
37+
updateChangelog: false,
38+
beforeCommitChanges: ({ nextVersion, exec, dir }) => {
39+
return new Promise(resolve => {
40+
const pkg = require('./package.json')
41+
commitChangelog(pkg.version, nextVersion).then(resolve)
42+
})
43+
},
44+
formatCommitMessage: ({
45+
version,
46+
releaseType,
47+
mergeStrategy,
48+
baseBranch
49+
}) => `${releaseType} release v${version}`,
50+
formatPullRequestTitle: ({
51+
version,
52+
releaseType
53+
}) => `${releaseType} release v${version}`,
54+
shouldRelease: () => true,
55+
releases: {
56+
extractChangelog: ({ version, dir }) => {
57+
const changelogPath = path.resolve(dir, 'CHANGELOG.md')
58+
try {
59+
const changelogFile = fs.readFileSync(changelogPath, 'utf-8').toString()
60+
const ret = extractSpecificChangelog(changelogFile, version)
61+
return ret
62+
} catch (err) {
63+
if (err.code === 'ENOENT') {
64+
return null
65+
}
66+
throw err
67+
}
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)