@@ -8,7 +8,6 @@ const GROUPS = [
88 'Features' ,
99 'Documentation' ,
1010 'Performance Improvements' ,
11- 'Refactoring' ,
1211 'Other Internal Changes' ,
1312] ;
1413
@@ -31,19 +30,8 @@ function getCommitType({ type, scope, revert }) {
3130 return 'Performance Improvements' ;
3231 case 'docs' :
3332 return 'Documentation' ;
34- case 'style' :
35- return 'Styles' ;
36- case 'refactor' :
37- return 'Refactoring' ;
38- case 'test' :
39- return 'Tests' ;
40- case 'build' :
41- case 'ci' :
42- return 'Build System' ;
43- case 'chore' :
44- return 'Other Internal Changes' ;
4533 default :
46- return type ;
34+ return 'Other Internal Changes' ;
4735 }
4836}
4937
@@ -85,94 +73,128 @@ function tokenize(subject) {
8573 . replace ( / ( [ a - z ] [ A - z ] + P r o p s ) / g, '`$1`' ) ;
8674}
8775
76+ const parserOpts = {
77+ headerPattern : / ^ ( \w * ) (?: \( ( .* ) \) ) ? : ( .* ) $ / ,
78+ headerCorrespondence : [ 'type' , 'scope' , 'subject' ] ,
79+ noteKeywords : [ 'BREAKING CHANGE' ] ,
80+ revertPattern : / ^ (?: R e v e r t | r e v e r t : ) \s " ? ( [ \s \S ] + ?) " ? \s * T h i s r e v e r t s c o m m i t ( \w * ) \. / i,
81+ revertCorrespondence : [ 'header' , 'hash' ] ,
82+ } ;
83+
84+ const writerOpts = {
85+ transform : ( commit , context ) => {
86+ // don't want to show the release tag in changelog
87+ if ( commit . scope === 'release' ) {
88+ return ;
89+ }
90+
91+ const issues = [ ] ;
92+ let isBreaking = false ;
93+ commit . notes . forEach ( ( note ) => {
94+ isBreaking = false ;
95+ note . title = 'BREAKING CHANGES' ;
96+ } ) ;
97+
98+ commit . type = getCommitType ( commit ) ;
99+ commit . scope = getCommitScope ( commit ) ;
100+ if ( ! isBreaking && ( ! commit . type || commit . scope . includes ( 'deps' ) ) ) {
101+ // don't include un-typed commits in changelogs or deps
102+ return ;
103+ }
104+
105+ if ( typeof commit . hash === 'string' ) {
106+ commit . shortHash = commit . hash . substring ( 0 , 7 ) ;
107+ }
108+
109+ if ( typeof commit . subject === 'string' ) {
110+ let url = context . repository
111+ ? `${ context . host } /${ context . owner } /${ context . repository } `
112+ : context . repoUrl ;
113+
114+ if ( url ) {
115+ url = `${ url } /issues/` ;
116+ commit . subject = commit . subject . replace ( / # ( [ 0 - 9 ] + ) / g, ( _ , issue ) => {
117+ issues . push ( issue ) ;
118+ return `[#${ issue } ](${ url } ${ issue } )` ;
119+ } ) ;
120+ }
121+
122+ commit . subject = tokenize ( commit . subject ) ;
123+ }
124+
125+ // remove references that already appear in the subject
126+ commit . references = commit . references . filter (
127+ ( reference ) => ! issues . includes ( reference . issue )
128+ ) ;
129+
130+ return commit ;
131+ } ,
132+ groupBy : 'type' ,
133+ commitGroupsSort : function ( a , b ) {
134+ const aIndex = GROUPS . indexOf ( a . title ) ;
135+ const bIndex = GROUPS . indexOf ( b . title ) ;
136+ if ( aIndex !== - 1 && bIndex !== - 1 ) {
137+ return aIndex - bIndex ;
138+ }
139+
140+ return a . title . localeCompare ( b . title ) ;
141+ } ,
142+ commitsSort : [ 'scope' , 'subject' ] ,
143+ noteGroupsSort : 'title' ,
144+ mainTemplate : readFileSync (
145+ resolve ( __dirname , './templates/template.hbs' ) ,
146+ 'utf-8'
147+ ) ,
148+ headerPartial : readFileSync (
149+ resolve ( __dirname , './templates/header.hbs' ) ,
150+ 'utf-8'
151+ ) ,
152+ commitPartial : readFileSync (
153+ resolve ( __dirname , './templates/commit.hbs' ) ,
154+ 'utf-8'
155+ ) ,
156+ footerPartial : readFileSync (
157+ resolve ( __dirname , './templates/footer.hbs' ) ,
158+ 'utf-8'
159+ ) ,
160+ } ;
161+
88162/**
89163 * This is basically the conventional-changelog-angular with a few changes to
90164 * allow more commit messages to appear. I also "tokenize" known packages and
91165 * exports from react-md in the changelogs.
92166 */
93167module . exports = {
94- parserOpts : {
95- headerPattern : / ^ ( \w * ) (?: \( ( .* ) \) ) ? : ( .* ) $ / ,
96- headerCorrespondence : [ 'type' , 'scope' , 'subject' ] ,
97- noteKeywords : [ 'BREAKING CHANGE' ] ,
98- revertPattern : / ^ (?: R e v e r t | r e v e r t : ) \s " ? ( [ \s \S ] + ?) " ? \s * T h i s r e v e r t s c o m m i t ( \w * ) \. / i,
99- revertCorrespondence : [ 'header' , 'hash' ] ,
168+ parserOpts,
169+ writerOpts,
170+ conventionalChangelog : {
171+ writerOpts,
172+ parserOpts,
100173 } ,
101- writerOpts : {
102- transform : ( commit , context ) => {
103- // don't want to show the release tag in changelog
104- if ( commit . scope === 'release' ) {
105- return ;
106- }
107-
108- const issues = [ ] ;
109- let isBreaking = false ;
110- commit . notes . forEach ( ( note ) => {
111- isBreaking = false ;
112- note . title = 'BREAKING CHANGES' ;
113- } ) ;
114-
115- commit . type = getCommitType ( commit ) ;
116- commit . scope = getCommitScope ( commit ) ;
117- if ( ! isBreaking && ( ! commit . type || commit . scope . includes ( 'deps' ) ) ) {
118- // don't include un-typed commits in changelogs or deps
119- return ;
120- }
121-
122- if ( typeof commit . hash === 'string' ) {
123- commit . shortHash = commit . hash . substring ( 0 , 7 ) ;
124- }
125-
126- if ( typeof commit . subject === 'string' ) {
127- let url = context . repository
128- ? `${ context . host } /${ context . owner } /${ context . repository } `
129- : context . repoUrl ;
130-
131- if ( url ) {
132- url = `${ url } /issues/` ;
133- commit . subject = commit . subject . replace ( / # ( [ 0 - 9 ] + ) / g, ( _ , issue ) => {
134- issues . push ( issue ) ;
135- return `[#${ issue } ](${ url } ${ issue } )` ;
136- } ) ;
174+ recommendedBumpOpts : {
175+ parserOpts,
176+
177+ whatBump : ( commits ) => {
178+ let level = 2 ;
179+ let breaking = 0 ;
180+ let features = 0 ;
181+ commits . forEach ( ( commit ) => {
182+ if ( commit . notes . length > 0 ) {
183+ breaking += commit . notes . length ;
184+ level = 0 ;
185+ } else if ( commit . type === 'feat' ) {
186+ features += 1 ;
187+ if ( level === 2 ) {
188+ level = 1 ;
189+ }
137190 }
191+ } ) ;
138192
139- commit . subject = tokenize ( commit . subject ) ;
140- }
141-
142- // remove references that already appear in the subject
143- commit . references = commit . references . filter (
144- ( reference ) => ! issues . includes ( reference . issue )
145- ) ;
146-
147- return commit ;
148- } ,
149- groupBy : 'type' ,
150- commitGroupsSort : function ( a , b ) {
151- const aIndex = GROUPS . indexOf ( a . title ) ;
152- const bIndex = GROUPS . indexOf ( b . title ) ;
153- if ( aIndex !== - 1 && bIndex !== - 1 ) {
154- return aIndex - bIndex ;
155- }
156-
157- return a . title . localeCompare ( b . title ) ;
193+ const verb = breaking === 1 ? 'is' : 'are' ;
194+ return {
195+ level,
196+ reason : `There ${ verb } ${ breaking } BREAKING CHANGES and ${ features } features` ,
197+ } ;
158198 } ,
159- commitsSort : [ 'scope' , 'subject' ] ,
160- noteGroupsSort : 'title' ,
161- mainTemplate : readFileSync (
162- resolve ( __dirname , './templates/template.hbs' ) ,
163- 'utf-8'
164- ) ,
165- headerPartial : readFileSync (
166- resolve ( __dirname , './templates/header.hbs' ) ,
167- 'utf-8'
168- ) ,
169- commitPartial : readFileSync (
170- resolve ( __dirname , './templates/commit.hbs' ) ,
171- 'utf-8'
172- ) ,
173- footerPartial : readFileSync (
174- resolve ( __dirname , './templates/footer.hbs' ) ,
175- 'utf-8'
176- ) ,
177199 } ,
178200} ;
0 commit comments