Skip to content

Commit 660ac23

Browse files
committed
build: Add generate CHANGELOG & push to remote
1 parent d81498a commit 660ac23

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Help.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pnpm changeset:version
2626
pnpm changelog core cli
2727
# 查看日志记录
2828
pnpm changelog
29+
pnpm changelog --commit=commitId # 从commitId记录开始
30+
pnpm changelog core cli --push # 生成 CHANGELOG 后直接 push (忽略 step4,5)
2931

3032

3133
# 4. 提交 commit

scripts/changelog.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function formatCommits(commits, filter = (commit) => commit) {
7070
async function generateLogs(name, logs) {
7171
const pkg = await readPackageJson(name)
7272
const content = await readPackageFile(name)
73-
const result = updateChangelog(content, pkg.version, logs[name])
73+
const result = updateChangelog(content, pkg.version, logs[name.toLowerCase()])
7474
await writePackageFile(name, result)
7575

7676
return result
@@ -80,15 +80,17 @@ async function generateLogs(name, logs) {
8080
const moduleRegex = /^[a-z]{1,10}\(\w+\).*/i
8181
try {
8282
// const commits = await getCommitsSince('d9acb96')
83-
const commits = await getCommitsSinceLatestTag()
83+
const commitId = args.commit || args.C
84+
const getCommitLogs = () => (commitId ? getCommitsSince(commitId) : getCommitsSinceLatestTag())
85+
const commits = await getCommitLogs()
8486
const formattedCommits = formatCommits(commits, (commit) => {
8587
return moduleRegex.test(commit.message)
8688
}).reduce((acc, commit) => {
8789
if (!commit.package) throw new Error('No package found in commit message: ' + commit.message)
8890
if (!acc[commit.package]) {
8991
acc[commit.package] = []
9092
}
91-
acc[commit.package].push(
93+
acc[commit.package.toLowerCase()].push(
9294
`- ${commit.text} ([${commit.hash.slice(0, 7)}](https://github.com/Meqn/pipflow/commit/${
9395
commit.hash
9496
}))`
@@ -109,8 +111,14 @@ async function generateLogs(name, logs) {
109111
for (const name of args._) {
110112
await generateLogs(name, formattedCommits)
111113
}
114+
115+
if (args.push) {
116+
await git.add(['*/*/package.json', '*/*/CHANGELOG.md'])
117+
await git.commit('Version Packages')
118+
await git.push('origin', 'main')
119+
}
112120
}
113121
} catch (err) {
114-
console.error('error:', err.message)
122+
console.error(err)
115123
}
116124
})()

0 commit comments

Comments
 (0)