Skip to content

Commit a43e712

Browse files
committed
chore(gen): update grunt-conventional-changelog to ^4.1.0
1 parent 4511e7c commit a43e712

File tree

4 files changed

+98
-24
lines changed

4 files changed

+98
-24
lines changed

Diff for: Gruntfile.js

+18-23
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,38 @@ 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');
78
var fs = require('fs');
89
var path = require('path');
910

11+
var gitCmd = gruntUtils.gitCmd;
12+
var gitCmdAsync = gruntUtils.gitCmdAsync;
13+
1014
module.exports = function (grunt) {
1115
// Load grunt tasks automatically, when needed
1216
require('jit-grunt')(grunt, {
13-
buildcontrol: 'grunt-build-control',
14-
changelog: 'grunt-conventional-changelog'
17+
buildcontrol: 'grunt-build-control'
1518
});
1619

1720
grunt.initConfig({
1821
config: {
1922
demo: 'demo'
2023
},
2124
pkg: grunt.file.readJSON('package.json'),
22-
changelog: {
25+
conventionalChangelog: {
2326
options: {
24-
dest: 'CHANGELOG.md',
25-
versionFile: 'package.json'
27+
changelogOpts: {
28+
// conventional-changelog options go here
29+
preset: 'angular'
30+
},
31+
writerOpts: {
32+
// conventional-changelog-writer options go here
33+
finalizeContext: gruntUtils.conventionalChangelog.finalizeContext,
34+
commitPartial: gruntUtils.conventionalChangelog.commitPartial
35+
}
36+
},
37+
release: {
38+
src: 'CHANGELOG.md'
2639
}
2740
},
2841
release: {
@@ -119,24 +132,6 @@ module.exports = function (grunt) {
119132
}
120133
});
121134

122-
function gitCmd(args, opts, done) {
123-
grunt.util.spawn({
124-
cmd: process.platform === 'win32' ? 'git.cmd' : 'git',
125-
args: args,
126-
opts: opts || {}
127-
}, done);
128-
}
129-
function gitCmdAsync(args, opts) {
130-
return function() {
131-
var deferred = Q.defer();
132-
gitCmd(args, opts, function(err) {
133-
if (err) { return deferred.reject(err); }
134-
deferred.resolve();
135-
});
136-
return deferred.promise;
137-
};
138-
}
139-
140135
grunt.registerTask('stage', 'git add files before running the release task', function () {
141136
var files = grunt.config('stage.options').files;
142137
gitCmd(['add'].concat(files), {}, this.async());

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"grunt-build-control": "^0.6.0",
5050
"grunt-contrib-clean": "^0.6.0",
5151
"grunt-contrib-jshint": "^0.11.2",
52-
"grunt-conventional-changelog": "~1.0.0",
52+
"grunt-conventional-changelog": "^4.1.0",
5353
"grunt-david": "~0.5.0",
5454
"grunt-env": "^0.4.1",
5555
"grunt-mocha-test": "^0.12.7",

Diff for: task-utils/changelog-templates/commit.hbs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{#if subScope}} {{/if}}*{{#if scope}}{{#unless subScope}} **{{index}}{{scope}}:**{{/unless}}{{/if}} {{#unless leadScope}}{{#if subject}}{{subject}}{{else}}{{header}}{{/if}}{{/unless}}{{#if leadScope}}{{#if subject}}
2+
* {{subject}}{{else}}{{header}}{{/if}}{{/if}}
3+
4+
{{~!-- commit hash --}} {{#if @root.linkReferences}}([{{hash}}]({{@root.host}}/{{#if @root.owner}}{{@root.owner}}/{{/if}}{{@root.repository}}/{{@root.commit}}/{{hash}})){{else}}{{hash~}}{{/if}}
5+
6+
{{~!-- commit references --}}{{#if references}}, closes{{~#each references}} {{#if @root.linkReferences}}[{{#if this.owner}}{{this.owner}}/{{/if}}{{this.repository}}#{{this.issue}}]({{@root.host}}/{{#if this.repository}}{{#if this.owner}}{{this.owner}}/{{/if}}{{this.repository}}{{else}}{{#if @root.owner}}{{@root.owner}}/{{/if}}{{@root.repository}}{{/if}}/{{@root.issue}}/{{this.issue}}){{else}}{{this.repository}}#{{this.issue}}{{/if}}{{/each}}{{/if}}

Diff for: task-utils/grunt.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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

Comments
 (0)