|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var path = require('path'); |
| 4 | +var fs = require('fs'); |
| 5 | + |
| 6 | +exports = module.exports = { |
| 7 | + gitCmd: function gitCmd(args, opts, done) { |
| 8 | + grunt.util.spawn({ |
| 9 | + cmd: process.platform === 'win32' ? 'git.cmd' : 'git', |
| 10 | + args: args, |
| 11 | + opts: opts || {} |
| 12 | + }, done); |
| 13 | + }, |
| 14 | + |
| 15 | + gitCmdAsync: function gitCmdAsync(args, opts) { |
| 16 | + return function() { |
| 17 | + var deferred = Q.defer(); |
| 18 | + gitCmd(args, opts, function(err) { |
| 19 | + if (err) { return deferred.reject(err); } |
| 20 | + deferred.resolve(); |
| 21 | + }); |
| 22 | + return deferred.promise; |
| 23 | + }; |
| 24 | + }, |
| 25 | + |
| 26 | + conventionalChangelog: { |
| 27 | + finalizeContext: function(context, writerOpts, commits, keyCommit) { |
| 28 | + var gitSemverTags = context.gitSemverTags; |
| 29 | + var commitGroups = context.commitGroups; |
| 30 | + |
| 31 | + if ((!context.currentTag || !context.previousTag) && keyCommit) { |
| 32 | + var match = /tag:\s*(.+?)[,\)]/gi.exec(keyCommit.gitTags); |
| 33 | + var currentTag = context.currentTag = context.currentTag || match ? match[1] : null; |
| 34 | + var index = gitSemverTags.indexOf(currentTag); |
| 35 | + var previousTag = context.previousTag = gitSemverTags[index + 1]; |
| 36 | + |
| 37 | + if (!previousTag) { |
| 38 | + if (options.append) { |
| 39 | + context.previousTag = context.previousTag || commits[0] ? commits[0].hash : null; |
| 40 | + } else { |
| 41 | + context.previousTag = context.previousTag || commits[commits.length - 1] ? commits[commits.length - 1].hash : null; |
| 42 | + } |
| 43 | + } |
| 44 | + } else { |
| 45 | + context.previousTag = context.previousTag || gitSemverTags[0]; |
| 46 | + context.currentTag = context.currentTag || 'v' + context.version; |
| 47 | + } |
| 48 | + |
| 49 | + if (typeof context.linkCompare !== 'boolean' && context.previousTag && context.currentTag) { |
| 50 | + context.linkCompare = true; |
| 51 | + } |
| 52 | + |
| 53 | + if (Array.isArray(commitGroups)) { |
| 54 | + for (var i = 0, commitGroupsLength = commitGroups.length; i < commitGroupsLength; i++) { |
| 55 | + var commits = commitGroups[i].commits; |
| 56 | + if (Array.isArray(commits)) { |
| 57 | + for (var n = 1, commitsLength = commits.length; n < commitsLength; n++) { |
| 58 | + var commit = commits[n], prevCommit = commits[n - 1]; |
| 59 | + if (commit.scope && commit.scope === prevCommit.scope) { |
| 60 | + commit.subScope = true; |
| 61 | + if (prevCommit.scope && !prevCommit.subScope) { |
| 62 | + prevCommit.leadScope = true; |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + return context; |
| 70 | + }, |
| 71 | + commitPartial: fs.readFileSync(path.resolve(__dirname, 'changelog-templates', 'commit.hbs')).toString() |
| 72 | + } |
| 73 | +}; |
0 commit comments