diff --git a/CHANGELOG.md b/CHANGELOG.md index eb0dd1331a1..85480b5d05b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -# [2.0.0-alpha.7 wax-umpire](https://github.com/angular/material2/compare/2.0.0-alpha.6...v2.0.0-alpha.7) (2016-08-09) +# [2.0.0-alpha.7 wax-umpire](https://github.com/angular/material2/compare/2.0.0-alpha.6...2.0.0-alpha.7) (2016-08-09) ### Bug Fixes @@ -50,7 +50,7 @@ The MD_XXX_DIRECTIVES constants are now deprecated and will be removed in alpha. -# [2.0.0-alpha.6 carbonfiber-discotheque](https://github.com/angular/material2/compare/2.0.0-alpha.5...v2.0.0-alpha.6) (2016-06-30) +# [2.0.0-alpha.6 carbonfiber-discotheque](https://github.com/angular/material2/compare/2.0.0-alpha.5...2.0.0-alpha.6) (2016-06-30) ### Breaking changes * `MdRadioDispatcher` is now `MdUniqueSelectionDispatcher` and is imported from `core` @@ -110,7 +110,7 @@ The MD_XXX_DIRECTIVES constants are now deprecated and will be removed in alpha. -# [2.0.0-alpha.5 granite-gouda](https://github.com/angular/material2/compare/2.0.0-alpha.4...v2.0.0-alpha.5) (2016-05-25) +# [2.0.0-alpha.5 granite-gouda](https://github.com/angular/material2/compare/2.0.0-alpha.4...2.0.0-alpha.5) (2016-05-25) ### Bug Fixes @@ -152,7 +152,7 @@ The MD_XXX_DIRECTIVES constants are now deprecated and will be removed in alpha. -# [2.0.0-alpha.4 mahogany-tambourine](https://github.com/angular/material2/compare/2.0.0-alpha.3...v2.0.0-alpha.4) (2016-05-04) +# [2.0.0-alpha.4 mahogany-tambourine](https://github.com/angular/material2/compare/2.0.0-alpha.3...2.0.0-alpha.4) (2016-05-04) ### Bug Fixes @@ -176,7 +176,7 @@ The MD_XXX_DIRECTIVES constants are now deprecated and will be removed in alpha. -# [2.0.0-alpha.3 cotton-candelabrum](https://github.com/angular/material2/compare/2.0.0-alpha.2...v2.0.0-alpha.3) (2016-04-21) +# [2.0.0-alpha.3 cotton-candelabrum](https://github.com/angular/material2/compare/2.0.0-alpha.2...2.0.0-alpha.3) (2016-04-21) ### Bug Fixes @@ -198,7 +198,7 @@ The MD_XXX_DIRECTIVES constants are now deprecated and will be removed in alpha. -# [2.0.0-alpha.2 diamond-haircut](https://github.com/angular/material2/compare/2.0.0-alpha.1...v2.0.0-alpha.2) (2016-04-06) +# [2.0.0-alpha.2 diamond-haircut](https://github.com/angular/material2/compare/2.0.0-alpha.1...2.0.0-alpha.2) (2016-04-06) ### Bug Fixes @@ -231,7 +231,7 @@ The MD_XXX_DIRECTIVES constants are now deprecated and will be removed in alpha. -# [2.0.0-alpha.1 nylon-hyperdrive](https://github.com/angular/material2/compare/2.0.0-alpha.0...v2.0.0-alpha.1) (2016-03-16) +# [2.0.0-alpha.1 nylon-hyperdrive](https://github.com/angular/material2/compare/2.0.0-alpha.0...2.0.0-alpha.1) (2016-03-16) ### Features diff --git a/scripts/release/changelog.js b/scripts/release/changelog.js index 3b4e137b5f2..d33b6e66082 100755 --- a/scripts/release/changelog.js +++ b/scripts/release/changelog.js @@ -1,20 +1,31 @@ #!/usr/bin/env node 'use strict'; -/** + +/* * Creates a conventional changelog from the current git repository / metadata. */ -var fs = require('fs'); -var addStream = require('add-stream'); -var cl = require('conventional-changelog'); -var inStream = fs.createReadStream('CHANGELOG.md'); +const fs = require('fs'); +const addStream = require('add-stream'); +const changelog = require('conventional-changelog'); +const spawnSync = require('child_process').spawnSync; +const npmVersion = require('../../package.json').version; /** * When the command line argument `--force` is provided, then the full changelog will created and overwritten. * By default, it will only create the changelog from the latest tag to head and prepends it to the changelog. */ -var isForce = process.argv.indexOf('--force') !== -1; +const isForce = process.argv.indexOf('--force') !== -1; +const inStream = fs.createReadStream('CHANGELOG.md'); +const gitTags = getAvailableTags(); + +// Whether the npm version is later than the most recent tag. +const isNpmLatest = npmVersion !== gitTags[0]; +// When the npm version is the latest, use the npm version, otherwise use the latest tag. +const currentTag = isNpmLatest ? npmVersion : gitTags[0]; +// When the npm version is the latest use the most recent tag. Otherwise use the previous tag. +const previousTag = isNpmLatest ? gitTags[0] : gitTags[1]; inStream.on('error', function(err) { console.error('An error occurred, while reading the previous changelog file.\n' + @@ -28,7 +39,12 @@ var config = { releaseCount: isForce ? 0 : 1 }; -var stream = cl(config) +var context = { + currentTag: currentTag, + previousTag: previousTag +}; + +var stream = changelog(config, context) .on('error', function(err) { console.error('An error occurred while generating the changelog: ' + err); }) @@ -45,3 +61,11 @@ if (!isForce) { function getOutputStream() { return fs.createWriteStream('CHANGELOG.md'); } + +/** + * Resolves available tags over all branches from the repository metadata. + * @returns {Array.} Array of available tags. + */ +function getAvailableTags() { + return spawnSync('git', ['tag']).stdout.toString().trim().split('\n').reverse(); +}