@@ -17,7 +17,7 @@ const commitMessageRegex = /^([a-z]+)(\(.+\))?: (.*)$/
17
17
const changesetMatchOptions : IChangesetMatchOptions = {
18
18
minor : [ / ^ f e a t / ] ,
19
19
patch : [ / ^ f i x / , / ^ p e r f / , / ^ r e f a c t o r / , / ^ s t y l e / , / ^ d o c s / , / ^ c h o r e / , / ^ r e v e r t / , / ^ c i / , / ^ b u i l d / , / ^ t e s t / ] ,
20
- ignore : [ / ^ c h o r e \( r e l e a s e \) / ] ,
20
+ ignore : [ / ^ c h o r e \( r e l e a s e \) / , / R E L E A S I N G / ] ,
21
21
}
22
22
23
23
export type ChangesetType = 'patch' | 'minor' | 'major'
@@ -126,11 +126,16 @@ async function getMatchedChangeset(lastCommitMessage: string): Promise<[Changese
126
126
}
127
127
128
128
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
+ }
129
134
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' ) }
131
136
---
132
137
133
- ${ lastCommitId } ${ commitMessage }
138
+ [ ${ lastCommitId } ] ${ commitMessage }
134
139
`
135
140
}
136
141
@@ -147,15 +152,15 @@ async function main() {
147
152
148
153
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' ) } ` )
149
154
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.` ) )
151
156
else if ( changesetMatchOptions . ignore ?. some ( v => v . test ( lastCommitMessage ) ) )
152
157
return console . warn ( k . yellow ( `The commit "${ lastCommitMessage } " is ignored.` ) )
153
158
154
159
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 )
156
161
fs . writeFileSync ( `.changeset/${ lastCommitId } .md` , markdown )
157
162
await git . add ( '--all' )
158
- await git . commit ( `docs(changeset): ${ lastCommitId } ${ commitMessage } ` , {
163
+ await git . commit ( `docs(changeset): ${ commitMessage } [ ${ lastCommitId } ] ` , {
159
164
'--no-verify' : true ,
160
165
} as any )
161
166
}
0 commit comments