Skip to content

Commit 7a2c01e

Browse files
committed
fix(gen): require q and grunt in gruntUtils
1 parent 07a158e commit 7a2c01e

File tree

2 files changed

+62
-58
lines changed

2 files changed

+62
-58
lines changed

Diff for: Gruntfile.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ var shell = require('shelljs');
44
var child_process = require('child_process');
55
var Q = require('q');
66
var helpers = require('yeoman-generator').test;
7-
var gruntUtils = require('./task-utils/grunt');
87
var fs = require('fs');
98
var path = require('path');
109

11-
var gitCmd = gruntUtils.gitCmd;
12-
var gitCmdAsync = gruntUtils.gitCmdAsync;
13-
1410
module.exports = function (grunt) {
11+
var gruntUtils = require('./task-utils/grunt')(grunt);
12+
var gitCmd = gruntUtils.gitCmd;
13+
var gitCmdAsync = gruntUtils.gitCmdAsync;
14+
1515
// Load grunt tasks automatically, when needed
1616
require('jit-grunt')(grunt, {
1717
buildcontrol: 'grunt-build-control'

Diff for: task-utils/grunt.js

+58-54
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,76 @@
22

33
var path = require('path');
44
var fs = require('fs');
5+
var Q = require('q');
56

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+
},
1417

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+
},
2528

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;
3033

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];
3639

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+
}
4246
}
47+
} else {
48+
context.previousTag = context.previousTag || gitSemverTags[0];
49+
context.currentTag = context.currentTag || 'v' + context.version;
4350
}
44-
} else {
45-
context.previousTag = context.previousTag || gitSemverTags[0];
46-
context.currentTag = context.currentTag || 'v' + context.version;
47-
}
4851

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+
}
5255

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+
}
6367
}
6468
}
6569
}
6670
}
6771
}
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+
};
7377
};

0 commit comments

Comments
 (0)