Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
feat(exports): export the promise
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Dec 30, 2015
1 parent dbc5272 commit 60def39
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 67 deletions.
128 changes: 62 additions & 66 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,73 @@ var Q = require('q');
var readFile = Q.denodeify(require('fs').readFile);
var resolve = require('path').resolve;

function presetOpts() {
var parserOpts = {
headerPattern: /^(\w*)(?:\((.*)\))?\: (.*)$/,
headerCorrespondence: [
'type',
'scope',
'subject'
],
noteKeywords: 'BREAKING CHANGE',
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
revertCorrespondence: ['header', 'hash']
};
var parserOpts = {
headerPattern: /^(\w*)(?:\((.*)\))?\: (.*)$/,
headerCorrespondence: [
'type',
'scope',
'subject'
],
noteKeywords: 'BREAKING CHANGE',
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
revertCorrespondence: ['header', 'hash']
};

var writerOpts = {
transform: function(commit) {
if (commit.type === 'feat') {
commit.type = 'Features';
} else if (commit.type === 'fix') {
commit.type = 'Bug Fixes';
} else if (commit.type === 'perf') {
commit.type = 'Performance Improvements';
} else if (commit.type === 'revert') {
commit.type = 'Reverts';
} else {
return;
}

if (commit.scope === '*') {
commit.scope = '';
}
var writerOpts = {
transform: function(commit) {
if (commit.type === 'feat') {
commit.type = 'Features';
} else if (commit.type === 'fix') {
commit.type = 'Bug Fixes';
} else if (commit.type === 'perf') {
commit.type = 'Performance Improvements';
} else if (commit.type === 'revert') {
commit.type = 'Reverts';
} else {
return;
}

if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, 7);
}
if (commit.scope === '*') {
commit.scope = '';
}

if (typeof commit.subject === 'string') {
commit.subject = commit.subject.substring(0, 80);
}
if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, 7);
}

commit.notes.forEach(function(note) {
if (note.title === 'BREAKING CHANGE') {
note.title = 'BREAKING CHANGES';
}
});
if (typeof commit.subject === 'string') {
commit.subject = commit.subject.substring(0, 80);
}

return commit;
},
groupBy: 'type',
commitGroupsSort: 'title',
commitsSort: ['scope', 'subject'],
noteGroupsSort: 'title',
notesSort: compareFunc
};
commit.notes.forEach(function(note) {
if (note.title === 'BREAKING CHANGE') {
note.title = 'BREAKING CHANGES';
}
});

return Q.all([
readFile(resolve(__dirname, 'templates/template.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/header.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/commit.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/footer.hbs'), 'utf-8')
])
.spread(function(template, header, commit, footer) {
writerOpts.mainTemplate = template;
writerOpts.headerPartial = header;
writerOpts.commitPartial = commit;
writerOpts.footerPartial = footer;
return commit;
},
groupBy: 'type',
commitGroupsSort: 'title',
commitsSort: ['scope', 'subject'],
noteGroupsSort: 'title',
notesSort: compareFunc
};

return {
parserOpts: parserOpts,
writerOpts: writerOpts
};
});
}
module.exports = Q.all([
readFile(resolve(__dirname, 'templates/template.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/header.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/commit.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/footer.hbs'), 'utf-8')
])
.spread(function(template, header, commit, footer) {
writerOpts.mainTemplate = template;
writerOpts.headerPartial = header;
writerOpts.commitPartial = commit;
writerOpts.footerPartial = footer;

module.exports = presetOpts;
return {
parserOpts: parserOpts,
writerOpts: writerOpts
};
});
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';
var child = require('child_process');
var conventionalChangelogCore = require('conventional-changelog-core');
var preset = require('./');
var expect = require('chai').expect;
var gitDummyCommit = require('git-dummy-commit');
var shell = require('shelljs');
var through = require('through2');
var preset = require('./')();

describe('angular preset', function() {
before(function(done) {
Expand Down

0 comments on commit 60def39

Please sign in to comment.