Skip to content

Commit fc88967

Browse files
Merge pull request #97 from uniocjs/dev-groupguanfang
chore: update post commit scripts
2 parents 7de7862 + 014df26 commit fc88967

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

scripts/post-commit.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const commitMessageRegex = /^([a-z]+)(\(.+\))?: (.*)$/
1717
const changesetMatchOptions: IChangesetMatchOptions = {
1818
minor: [/^feat/],
1919
patch: [/^fix/, /^perf/, /^refactor/, /^style/, /^docs/, /^chore/, /^revert/, /^ci/, /^build/, /^test/],
20-
ignore: [/^chore\(release\)/],
20+
ignore: [/^chore\(release\)/, /RELEASING/],
2121
}
2222

2323
export type ChangesetType = 'patch' | 'minor' | 'major'
@@ -126,11 +126,16 @@ async function getMatchedChangeset(lastCommitMessage: string): Promise<[Changese
126126
}
127127

128128
async function createMarkdown(changesetType: ChangesetType, workspaceCommittedFiles: IWorkspaceCommittedFile[], commitMessage: string, lastCommitId: string) {
129+
const workspaceCommittedFilesMap = new Map<string, string>()
130+
for (const file of workspaceCommittedFiles) {
131+
if (file.workspace)
132+
workspaceCommittedFilesMap.set(file.workspace.packageName, changesetType)
133+
}
129134
return `---
130-
${workspaceCommittedFiles.filter(v => v.workspace !== null).map(file => `"${file.workspace?.packageName}": "${changesetType}"`).join('\n')}
135+
${Array.from(workspaceCommittedFilesMap.entries()).map(([packageName, changesetType]) => `"${packageName}": "${changesetType}"`).join('\n')}
131136
---
132137
133-
${lastCommitId} ${commitMessage}
138+
[${lastCommitId}] ${commitMessage}
134139
`
135140
}
136141

@@ -147,15 +152,15 @@ async function main() {
147152

148153
console.log(`${workspaceCommittedFiles.map(v => k.dim(`${k.green(`[${v.workspace ? '✓' : '✗'}]`)} ${path.relative(process.cwd(), v.filePath)}: detected workspace: ${v.workspace?.folderPath ? path.relative(process.cwd(), v.workspace.folderPath) : 'null'}`)).join('\n')}`)
149154
if (workspaceCommittedFiles.every(v => v.workspace === null))
150-
return console.warn(k.yellow(`The commit "${lastCommitMessage}" has no files in the workspace.`))
155+
return console.warn(k.yellow(`The commit "${lastCommitMessage}" has not files in the workspace.`))
151156
else if (changesetMatchOptions.ignore?.some(v => v.test(lastCommitMessage)))
152157
return console.warn(k.yellow(`The commit "${lastCommitMessage}" is ignored.`))
153158

154159
console.log(k.dim(`Creating changeset file for ${lastCommitId}.md ${lastCommitMessage}`))
155-
const markdown = await createMarkdown(changesetType, workspaceCommittedFiles, commitMessage, lastCommitId)
160+
const markdown = await createMarkdown(changesetType, workspaceCommittedFiles, lastCommitMessage, lastCommitId)
156161
fs.writeFileSync(`.changeset/${lastCommitId}.md`, markdown)
157162
await git.add('--all')
158-
await git.commit(`docs(changeset): ${lastCommitId} ${commitMessage}`, {
163+
await git.commit(`docs(changeset): ${commitMessage} [${lastCommitId}]`, {
159164
'--no-verify': true,
160165
} as any)
161166
}

0 commit comments

Comments
 (0)