Skip to content

Commit

Permalink
chore(gen): update grunt-conventional-changelog to ^4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcody committed Sep 9, 2015
1 parent 4511e7c commit a43e712
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 24 deletions.
41 changes: 18 additions & 23 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,38 @@ var shell = require('shelljs');
var child_process = require('child_process');
var Q = require('q');
var helpers = require('yeoman-generator').test;
var gruntUtils = require('./task-utils/grunt');
var fs = require('fs');
var path = require('path');

var gitCmd = gruntUtils.gitCmd;
var gitCmdAsync = gruntUtils.gitCmdAsync;

module.exports = function (grunt) {
// Load grunt tasks automatically, when needed
require('jit-grunt')(grunt, {
buildcontrol: 'grunt-build-control',
changelog: 'grunt-conventional-changelog'
buildcontrol: 'grunt-build-control'
});

grunt.initConfig({
config: {
demo: 'demo'
},
pkg: grunt.file.readJSON('package.json'),
changelog: {
conventionalChangelog: {
options: {
dest: 'CHANGELOG.md',
versionFile: 'package.json'
changelogOpts: {
// conventional-changelog options go here
preset: 'angular'
},
writerOpts: {
// conventional-changelog-writer options go here
finalizeContext: gruntUtils.conventionalChangelog.finalizeContext,
commitPartial: gruntUtils.conventionalChangelog.commitPartial
}
},
release: {
src: 'CHANGELOG.md'
}
},
release: {
Expand Down Expand Up @@ -119,24 +132,6 @@ module.exports = function (grunt) {
}
});

function gitCmd(args, opts, done) {
grunt.util.spawn({
cmd: process.platform === 'win32' ? 'git.cmd' : 'git',
args: args,
opts: opts || {}
}, done);
}
function gitCmdAsync(args, opts) {
return function() {
var deferred = Q.defer();
gitCmd(args, opts, function(err) {
if (err) { return deferred.reject(err); }
deferred.resolve();
});
return deferred.promise;
};
}

grunt.registerTask('stage', 'git add files before running the release task', function () {
var files = grunt.config('stage.options').files;
gitCmd(['add'].concat(files), {}, this.async());
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"grunt-build-control": "^0.6.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-jshint": "^0.11.2",
"grunt-conventional-changelog": "~1.0.0",
"grunt-conventional-changelog": "^4.1.0",
"grunt-david": "~0.5.0",
"grunt-env": "^0.4.1",
"grunt-mocha-test": "^0.12.7",
Expand Down
6 changes: 6 additions & 0 deletions task-utils/changelog-templates/commit.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{#if subScope}} {{/if}}*{{#if scope}}{{#unless subScope}} **{{index}}{{scope}}:**{{/unless}}{{/if}} {{#unless leadScope}}{{#if subject}}{{subject}}{{else}}{{header}}{{/if}}{{/unless}}{{#if leadScope}}{{#if subject}}
* {{subject}}{{else}}{{header}}{{/if}}{{/if}}

{{~!-- commit hash --}} {{#if @root.linkReferences}}([{{hash}}]({{@root.host}}/{{#if @root.owner}}{{@root.owner}}/{{/if}}{{@root.repository}}/{{@root.commit}}/{{hash}})){{else}}{{hash~}}{{/if}}

{{~!-- 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}}
73 changes: 73 additions & 0 deletions task-utils/grunt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';

var path = require('path');
var fs = require('fs');

exports = module.exports = {
gitCmd: function gitCmd(args, opts, done) {
grunt.util.spawn({
cmd: process.platform === 'win32' ? 'git.cmd' : 'git',
args: args,
opts: opts || {}
}, done);
},

gitCmdAsync: function gitCmdAsync(args, opts) {
return function() {
var deferred = Q.defer();
gitCmd(args, opts, function(err) {
if (err) { return deferred.reject(err); }
deferred.resolve();
});
return deferred.promise;
};
},

conventionalChangelog: {
finalizeContext: function(context, writerOpts, commits, keyCommit) {
var gitSemverTags = context.gitSemverTags;
var commitGroups = context.commitGroups;

if ((!context.currentTag || !context.previousTag) && keyCommit) {
var match = /tag:\s*(.+?)[,\)]/gi.exec(keyCommit.gitTags);
var currentTag = context.currentTag = context.currentTag || match ? match[1] : null;
var index = gitSemverTags.indexOf(currentTag);
var previousTag = context.previousTag = gitSemverTags[index + 1];

if (!previousTag) {
if (options.append) {
context.previousTag = context.previousTag || commits[0] ? commits[0].hash : null;
} else {
context.previousTag = context.previousTag || commits[commits.length - 1] ? commits[commits.length - 1].hash : null;
}
}
} else {
context.previousTag = context.previousTag || gitSemverTags[0];
context.currentTag = context.currentTag || 'v' + context.version;
}

if (typeof context.linkCompare !== 'boolean' && context.previousTag && context.currentTag) {
context.linkCompare = true;
}

if (Array.isArray(commitGroups)) {
for (var i = 0, commitGroupsLength = commitGroups.length; i < commitGroupsLength; i++) {
var commits = commitGroups[i].commits;
if (Array.isArray(commits)) {
for (var n = 1, commitsLength = commits.length; n < commitsLength; n++) {
var commit = commits[n], prevCommit = commits[n - 1];
if (commit.scope && commit.scope === prevCommit.scope) {
commit.subScope = true;
if (prevCommit.scope && !prevCommit.subScope) {
prevCommit.leadScope = true;
}
}
}
}
}
}
return context;
},
commitPartial: fs.readFileSync(path.resolve(__dirname, 'changelog-templates', 'commit.hbs')).toString()
}
};

0 comments on commit a43e712

Please sign in to comment.