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