| 
									
										
										
										
											2017-09-22 19:51:03 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2017-09-22 19:51:03 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-07 18:29:13 +02:00
										 |  |  | const {readFileSync} = require('fs'); | 
					
						
							|  |  |  | const {bold, yellow} = require('chalk'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-03 08:10:41 +00:00
										 |  |  | module.exports = (gulp) => () => { | 
					
						
							|  |  |  |   const conventionalChangelog = require('gulp-conventional-changelog'); | 
					
						
							| 
									
										
										
										
											2018-09-06 14:13:42 +03:00
										 |  |  |   const ignoredScopes = [ | 
					
						
							|  |  |  |     'aio', | 
					
						
							| 
									
										
										
										
											2020-03-10 08:11:09 -07:00
										 |  |  |     'dev-infra', | 
					
						
							| 
									
										
										
										
											2018-09-06 14:13:42 +03:00
										 |  |  |     'docs-infra', | 
					
						
							| 
									
										
										
										
											2019-06-26 18:17:07 +02:00
										 |  |  |     'zone.js', | 
					
						
							| 
									
										
										
										
											2018-09-06 14:13:42 +03:00
										 |  |  |   ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-03 08:10:41 +00:00
										 |  |  |   return gulp.src('CHANGELOG.md') | 
					
						
							| 
									
										
										
										
											2020-07-07 18:29:13 +02:00
										 |  |  |       .pipe(conventionalChangelog( | 
					
						
							|  |  |  |           /* core options */ {preset: 'angular'}, | 
					
						
							|  |  |  |           /* context options */ {}, | 
					
						
							|  |  |  |           /* raw-commit options */ { | 
					
						
							|  |  |  |             // Ignore commits that start with `<type>(<scope>)` for any of the ignored scopes.
 | 
					
						
							|  |  |  |             extendedRegexp: true, | 
					
						
							|  |  |  |             grep: `^[^(]+\\((${ignoredScopes.join('|')})\\)`, | 
					
						
							|  |  |  |             invertGrep: true, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           /* commit parser options */ null, | 
					
						
							|  |  |  |           /* writer options*/ createDedupeWriterOptions())) | 
					
						
							| 
									
										
										
										
											2017-02-03 08:10:41 +00:00
										 |  |  |       .pipe(gulp.dest('./')); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-07-07 18:29:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Creates changelog writer options which ensure that commits are not showing up multiple times. | 
					
						
							|  |  |  |  * Commits can show up multiple times if a changelog has been generated on a publish branch | 
					
						
							|  |  |  |  * and has been cherry-picked into "master". In that case, the changelog will already contain | 
					
						
							|  |  |  |  * commits from master which might be added to the changelog again. This is because usually | 
					
						
							|  |  |  |  * patch and minor releases are tagged from the publish branches and therefore | 
					
						
							|  |  |  |  * conventional-changelog tries to build the changelog from last minor version to HEAD when a | 
					
						
							|  |  |  |  * new minor version is being published from the "master" branch. We naively match commit | 
					
						
							|  |  |  |  * headers as otherwise we would need to query Git and diff commits between a given patch branch. | 
					
						
							|  |  |  |  * The commit header is reliable enough as it contains a direct reference to the source PR. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function createDedupeWriterOptions() { | 
					
						
							|  |  |  |   const existingChangelogContent = readFileSync('CHANGELOG.md', 'utf8'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     // Specify a writer option that can be used to modify the content of a new changelog section.
 | 
					
						
							|  |  |  |     // See: conventional-changelog/tree/master/packages/conventional-changelog-writer
 | 
					
						
							|  |  |  |     finalizeContext: (context) => { | 
					
						
							|  |  |  |       context.commitGroups = context.commitGroups.filter((group) => { | 
					
						
							|  |  |  |         group.commits = group.commits.filter((commit) => { | 
					
						
							|  |  |  |           // NOTE: We cannot compare the SHAs because the commits will have a different SHA
 | 
					
						
							|  |  |  |           // if they are being cherry-picked into a different branch.
 | 
					
						
							|  |  |  |           if (existingChangelogContent.includes(commit.subject)) { | 
					
						
							|  |  |  |             console.info(yellow(`  ↺   Skipping duplicate: "${bold(commit.header)}"`)); | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           return true; | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Filter out commit groups which don't have any commits. Commit groups will become
 | 
					
						
							|  |  |  |         // empty if we filter out all duplicated commits.
 | 
					
						
							|  |  |  |         return group.commits.length !== 0; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return context; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |