Skip to content

Commit

Permalink
feat(preset): add recommended-bump opts into presets
Browse files Browse the repository at this point in the history
Move `conventional-recommended-bump` options from the built-in
presets into the individual `conventional-changelog-*` presets
so that the same preset packages may be used between
`conventional-recommended-bump` and `conventional-changelog`.

Related to #241
  • Loading branch information
hutson committed Dec 15, 2017
1 parent 4895b39 commit 60815b5
Show file tree
Hide file tree
Showing 76 changed files with 1,329 additions and 789 deletions.
3 changes: 2 additions & 1 deletion packages/conventional-changelog-angular/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"curly": true,
"eqeqeq": true,
"eqnull": true,
"esversion": 6,
"immed": true,
"latedef": true,
"latedef": "nofunc",
"mocha" : true,
"newcap": true,
"noarg": true,
Expand Down
86 changes: 0 additions & 86 deletions packages/conventional-changelog-angular/convention.md

This file was deleted.

10 changes: 10 additions & 0 deletions packages/conventional-changelog-angular/conventional-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const Q = require(`q`);
const parserOpts = require(`./parser-opts`);
const writerOpts = require(`./writer-opts`);

module.exports = Q.all([parserOpts, writerOpts])
.spread((parserOpts, writerOpts) => {
return {parserOpts, writerOpts};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

module.exports = {
whatBump: (commits) => {
let level = 2;
let breakings = 0;
let features = 0;

commits.forEach(commit => {
if (commit.notes.length > 0) {
breakings += commit.notes.length;
level = 0;
} else if (commit.type === `feat`) {
features += 1;
if (level === 2) {
level = 1;
}
}
});

return {
level: level,
reason: `There are ${breakings} BREAKING CHANGES and ${features} features`
};
},

parserOpts: {
headerPattern: /^(\w*)(?:\((.*)\))?\: (.*)$/,
headerCorrespondence: [
`type`,
`scope`,
`subject`
],
noteKeywords: `BREAKING CHANGE`,
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
revertCorrespondence: [`header`, `hash`]
}
};
116 changes: 8 additions & 108 deletions packages/conventional-changelog-angular/index.js
Original file line number Diff line number Diff line change
@@ -1,112 +1,12 @@
'use strict';
var compareFunc = require('compare-func');
var Q = require('q');
var readFile = Q.denodeify(require('fs').readFile);
var resolve = require('path').resolve;

var parserOpts = {
headerPattern: /^(\w*)(?:\((.*)\))?\: (.*)$/,
headerCorrespondence: [
'type',
'scope',
'subject'
],
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES'],
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
revertCorrespondence: ['header', 'hash']
};
const Q = require(`q`);
const conventionalChangelog = require(`./conventional-changelog`);
const parserOpts = require(`./parser-opts`);
const recommendedBumpOpts = require(`./conventional-recommended-bump`);
const writerOpts = require(`./writer-opts`);

var writerOpts = {
transform: function(commit, context) {
var discard = true;
var issues = [];

commit.notes.forEach(function(note) {
note.title = 'BREAKING CHANGES';
discard = false;
});

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 if (discard) {
return;
} else if (commit.type === 'docs') {
commit.type = 'Documentation';
} else if (commit.type === 'style') {
commit.type = 'Styles';
} else if (commit.type === 'refactor') {
commit.type = 'Code Refactoring';
} else if (commit.type === 'test') {
commit.type = 'Tests';
} else if (commit.type === 'chore') {
commit.type = 'Chores';
}

if (commit.scope === '*') {
commit.scope = '';
}

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

if (typeof commit.subject === 'string') {
var url = context.repository ?
context.host + '/' + context.owner + '/' + context.repository :
context.repoUrl;
if (url) {
url = url + '/issues/';
// Issue URLs.
commit.subject = commit.subject.replace(/#([0-9]+)/g, function(_, issue) {
issues.push(issue);
return '[#' + issue + '](' + url + issue + ')';
});
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9]){0,38})/g, '[@$1](' + context.host + '/$1)');
}
}

// remove references that already appear in the subject
commit.references = commit.references.filter(function(reference) {
if (issues.indexOf(reference.issue) === -1) {
return true;
}

return false;
});

return commit;
},
groupBy: 'type',
commitGroupsSort: 'title',
commitsSort: ['scope', 'subject'],
noteGroupsSort: 'title',
notesSort: compareFunc
};

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;

return {
parserOpts: parserOpts,
writerOpts: writerOpts
};
module.exports = Q.all([conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts])
.spread((conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts) => {
return {conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts};
});
4 changes: 4 additions & 0 deletions packages/conventional-changelog-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
"preset"
],
"files": [
"conventional-changelog.js",
"conventional-recommended-bump.js",
"index.js",
"parser-opts.js",
"writer-opts.js",
"templates"
],
"author": "Steve Mao",
Expand Down
13 changes: 13 additions & 0 deletions packages/conventional-changelog-angular/parser-opts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = {
headerPattern: /^(\w*)(?:\((.*)\))?\: (.*)$/,
headerCorrespondence: [
`type`,
`scope`,
`subject`
],
noteKeywords: [`BREAKING CHANGE`, `BREAKING CHANGES`],
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
revertCorrespondence: [`header`, `hash`]
};
91 changes: 88 additions & 3 deletions packages/conventional-changelog-angular/readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,97 @@
# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url]
# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url]

> [conventional-changelog](https://github.com/ajoslin/conventional-changelog) [angular](https://github.com/angular/angular) preset
**Issues with the convention itself should be reported on the Angular issue tracker.**

See [convention](convention.md)
## Angular Convention

**Issues with the convention itself should be reported on the angular issue tracker.**
### Examples

Appears under "Features" header, pencil subheader:

```
feat(pencil): add 'graphiteWidth' option
```

Appears under "Bug Fixes" header, graphite subheader, with a link to issue #28:

```
fix(graphite): stop graphite breaking when width < 0.1
Closes #28
```

Appears under "Performance Improvements" header, and under "Breaking Changes" with the breaking change explanation:

```
perf(pencil): remove graphiteWidth option
BREAKING CHANGE: The graphiteWidth option has been removed. The default graphite width of 10mm is always used for performance reason.
```

The following commit and commit `667ecc1` do not appear in the changelog if they are under the same release. If not, the revert commit appears under the "Reverts" header.

```
revert: feat(pencil): add 'graphiteWidth' option
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
```

### Commit Message Format

A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**:

```
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```

The **header** is mandatory and the **scope** of the header is optional.

### Revert

If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.

### Type

If the prefix is `feat`, `fix` or `perf`, it will appear in the changelog. However if there is any [BREAKING CHANGE](#footer), the commit will always appear in the changelog.

Other prefixes are up to your discretion. Suggested prefixes are `docs`, `chore`, `style`, `refactor`, and `test` for non-changelog related tasks.

### Scope

The scope could be anything specifying place of the commit change. For example `$location`,
`$browser`, `$compile`, `$rootScope`, `ngHref`, `ngClick`, `ngView`, etc...

### Subject

The subject contains succinct description of the change:

* use the imperative, present tense: "change" not "changed" nor "changes"
* don't capitalize first letter
* no dot (.) at the end

### Body

Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
The body should include the motivation for the change and contrast this with previous behavior.

### Footer

The footer should contain any information about **Breaking Changes** and is also the place to
reference GitHub issues that this commit **Closes**.

**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.

A detailed explanation can be found in this [document][commit-message-format].

Based on https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#commit

[commit-message-format]: https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#

[npm-image]: https://badge.fury.io/js/conventional-changelog-angular.svg
[npm-url]: https://npmjs.org/package/conventional-changelog-angular
Expand Down

0 comments on commit 60815b5

Please sign in to comment.