| OLD | NEW |
| 1 #!/usr/bin/env node | 1 #!/usr/bin/env node |
| 2 | 2 |
| 3 // TODO(vojta): pre-commit hook for validating messages | 3 // TODO(vojta): pre-commit hook for validating messages |
| 4 // TODO(vojta): report errors, currently Q silence everything which really sucks | 4 // TODO(vojta): report errors, currently Q silence everything which really sucks |
| 5 | 5 |
| 6 var child = require('child_process'); | 6 var child = require('child_process'); |
| 7 var fs = require('fs'); | 7 var fs = require('fs'); |
| 8 var util = require('util'); | 8 var util = require('util'); |
| 9 var q = require('qq'); | 9 var q = require('qq'); |
| 10 | 10 |
| 11 var GIT_LOG_CMD = 'git log --grep="%s" -E --format=%s %s..HEAD'; | 11 var GIT_LOG_CMD = 'git log --grep="%s" -E --format=%s %s'; |
| 12 var GIT_TAG_CMD = 'git describe --tags --abbrev=0'; | 12 var GIT_TAG_CMD = 'git describe --tags --abbrev=0'; |
| 13 | 13 |
| 14 var HEADER_TPL = '<a name="%s"></a>\n# %s (%s)\n\n'; | 14 var HEADER_TPL = '<a name="%s"></a>\n# %s (%s)\n\n'; |
| 15 var LINK_ISSUE = '[#%s](https://github.com/angular/angular.dart/issues/%s)'; | 15 var LINK_ISSUE = '[#%s](https://github.com/angular/di.dart/issues/%s)'; |
| 16 var LINK_COMMIT = '[%s](https://github.com/angular/angular.dart/commit/%s)'; | 16 var LINK_COMMIT = '[%s](https://github.com/angular/di.dart/commit/%s)'; |
| 17 | 17 |
| 18 var EMPTY_COMPONENT = '$$'; | 18 var EMPTY_COMPONENT = '$$'; |
| 19 | 19 |
| 20 | 20 |
| 21 var warn = function() { | 21 var warn = function() { |
| 22 console.log('WARNING:', util.format.apply(null, arguments)); | 22 console.log('WARNING:', util.format.apply(null, arguments)); |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 | 25 |
| 26 var parseRawCommit = function(raw) { | 26 var parseRawCommit = function(raw) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 }); | 116 }); |
| 117 | 117 |
| 118 stream.write('\n'); | 118 stream.write('\n'); |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 | 121 |
| 122 var readGitLog = function(grep, from) { | 122 var readGitLog = function(grep, from) { |
| 123 var deferred = q.defer(); | 123 var deferred = q.defer(); |
| 124 | 124 |
| 125 // TODO(vojta): if it's slow, use spawn and stream it instead | 125 // TODO(vojta): if it's slow, use spawn and stream it instead |
| 126 console.log(util.format(GIT_LOG_CMD, grep, '%H%n%s%n%b%n==END==', from)); |
| 126 child.exec(util.format(GIT_LOG_CMD, grep, '%H%n%s%n%b%n==END==', from), functi
on(code, stdout, stderr) { | 127 child.exec(util.format(GIT_LOG_CMD, grep, '%H%n%s%n%b%n==END==', from), functi
on(code, stdout, stderr) { |
| 127 var commits = []; | 128 var commits = []; |
| 128 | 129 |
| 129 stdout.split('\n==END==\n').forEach(function(rawCommit) { | 130 stdout.split('\n==END==\n').forEach(function(rawCommit) { |
| 130 var commit = parseRawCommit(rawCommit); | 131 var commit = parseRawCommit(rawCommit); |
| 131 if (commit) commits.push(commit); | 132 if (commit) commits.push(commit); |
| 132 }); | 133 }); |
| 133 | 134 |
| 134 deferred.resolve(commits); | 135 deferred.resolve(commits); |
| 135 }); | 136 }); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 }); | 169 }); |
| 169 | 170 |
| 170 stream.write(util.format(HEADER_TPL, version, version, currentDate())); | 171 stream.write(util.format(HEADER_TPL, version, version, currentDate())); |
| 171 printSection(stream, 'Bug Fixes', sections.fix); | 172 printSection(stream, 'Bug Fixes', sections.fix); |
| 172 printSection(stream, 'Features', sections.feat); | 173 printSection(stream, 'Features', sections.feat); |
| 173 printSection(stream, 'Performance Improvements', sections.perf); | 174 printSection(stream, 'Performance Improvements', sections.perf); |
| 174 printSection(stream, 'Breaking Changes', sections.breaks, false); | 175 printSection(stream, 'Breaking Changes', sections.breaks, false); |
| 175 } | 176 } |
| 176 | 177 |
| 177 | 178 |
| 178 var getPreviousTag = function() { | 179 var generate = function(tagRange, file) { |
| 179 var deferred = q.defer(); | 180 console.log('Reading git log for', tagRange); |
| 180 child.exec(GIT_TAG_CMD, function(code, stdout, stderr) { | 181 readGitLog('^fix|^feat|^perf|BREAKING', tagRange).then(function(commits) { |
| 181 if (code) deferred.reject('Cannot get the previous tag.'); | 182 console.log('Parsed', commits.length, 'commits'); |
| 182 else deferred.resolve(stdout.replace('\n', '')); | 183 console.log('Generating changelog to', file || 'stdout', '(', tagRange, ')')
; |
| 183 }); | 184 writeChangelog(file ? fs.createWriteStream(file) : process.stdout, commits,
tagRange); |
| 184 return deferred.promise; | |
| 185 }; | |
| 186 | |
| 187 | |
| 188 var generate = function(version, file) { | |
| 189 getPreviousTag().then(function(tag) { | |
| 190 console.log('Reading git log since', tag); | |
| 191 readGitLog('^fix|^feat|^perf|BREAKING', tag).then(function(commits) { | |
| 192 console.log('Parsed', commits.length, 'commits'); | |
| 193 console.log('Generating changelog to', file || 'stdout', '(', version, ')'
); | |
| 194 writeChangelog(file ? fs.createWriteStream(file) : process.stdout, commits
, version); | |
| 195 }); | |
| 196 }); | 185 }); |
| 197 }; | 186 }; |
| 198 | 187 |
| 199 | 188 |
| 200 // publish for testing | 189 // publish for testing |
| 201 exports.parseRawCommit = parseRawCommit; | 190 exports.parseRawCommit = parseRawCommit; |
| 202 | 191 |
| 203 // hacky start if not run by jasmine :-D | 192 // hacky start if not run by jasmine :-D |
| 204 if (process.argv.join('').indexOf('jasmine-node') === -1) { | 193 if (process.argv.join('').indexOf('jasmine-node') === -1) { |
| 205 generate(process.argv[2], process.argv[3]); | 194 generate(process.argv[2], process.argv[3]); |
| 206 } | 195 } |
| OLD | NEW |