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

Commit

Permalink
feat(defaults): merge default options and make it less angular
Browse files Browse the repository at this point in the history
Also improve tests.

Closes #3, #4
  • Loading branch information
stevemao committed Jun 6, 2015
1 parent 4e7337f commit 9ca5845
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 201 deletions.
50 changes: 0 additions & 50 deletions CONVENTIONS.md

This file was deleted.

63 changes: 15 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,6 @@
> Write logs based on conventional commits and templates

## Conventional Commit Message Format

Each input commit message consists of a **header**, a **body** (optional) and a **footer** (optional).

```
<header>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```

### header

The header has a special format that includes a **type**, a **scope** (optional) and a **subject**

```
<type>(<scope>): <subject>
```

### footer

The footer should contain any information about **Important Notes** (optional) and is also the place to reference GitHub issues that this commit **references** (optional).

```
<important note>
<BLANK LINE>
<references>
```

[More details](CONVENTIONS.md)


## Install

```sh
Expand All @@ -51,7 +18,9 @@ var conventionalcommitsWriter = require('conventional-commits-writer');
conventionalcommitsWriter(context, options);
```

It returns a transform stream and expects an object mode upstream that looks something like this:
It returns a transform stream.

It expects an object mode upstream that looks something like this:

```js
{ hash: '9b1aff905b638aa274a5fc8f88662df446d374bd',
Expand All @@ -74,7 +43,9 @@ It returns a transform stream and expects an object mode upstream that looks som
references: [] }
```

Each chunk should be a commit. Json object is also **valid**. The downstream will look something like this:
Each chunk should be a commit. Json object is also **valid**. Parts of the objects will be formatted and combined into a log based on the handlebars context, templates and options.

The downstream might look something like this:

```js
<a name="0.0.1"></a>
Expand All @@ -90,11 +61,6 @@ Each chunk should be a commit. Json object is also **valid**. The downstream wil
### BREAKING CHANGES

* some breaking change





```
Expand Down Expand Up @@ -128,7 +94,7 @@ By default, this value is true if `version`'s patch is `0`.
Type: `string`
The hosting website. Eg: `'https://github.com/'` or `'https://bitbucket.org/'`
The hosting website. Eg: `'https://github.com'` or `'https://bitbucket.org'`
##### repository
Expand Down Expand Up @@ -166,15 +132,19 @@ Type: `object`
##### transform
Type: `object` or `function` Default: get the first 7 digits of hash, change `'fix'`, `'feat'` and `'perf'` to `'Bug Fixes'`, `'Features'` and `'Performance Improvements'`, strip leading `'v'` for `version`, change `'BREAKING CHANGE'` to `'BREAKING CHANGES'`, and `authorDate` will be formatted as `'yyyy-mm-dd'`.
Type: `object` or `function` Default: get the first 7 digits of hash, strip leading `'v'` for `version`, and `authorDate` will be formatted as `'yyyy-mm-dd'`.

Replace with new values in each commit.

If this is an object, the keys are paths (can be a [dot path](https://github.com/sindresorhus/dot-prop) to a nested object property). the values can be a string (static) and a function (dynamic) with the old value and path passed as arguments. This valued is merged with your own transform object.

Replace with new values in each commit. If this is an object, the keys are paths (can be a [dot path](https://github.com/sindresorhus/dot-prop) to a nested object property) and the values can be a string (static) and a function (dynamic) with the old value and path passed as arguments. If this is a function, the commit chunk will be passed as the argument and the returned value would be the new commit object. This is a handy function if you can't provide a transform stream as an upstream of this one. If returns a falsy value this commit is ignored.
If this is a function, the commit chunk will be passed as the argument and the returned value would be the new commit object. This is a handy function if you can't provide a transform stream as an upstream of this one. If returns a falsy value this commit is ignored.

##### groupBy

Type: `string` Default: `'type'`

How to group the commits. If this value is falsy, commits are not grouped.
How to group the commits. EG: based on the same type. If this value is falsy, commits are not grouped.

##### commitGroupsSort

Expand All @@ -186,7 +156,7 @@ The string can be a dot path to a nested object property.

##### commitsSort

Type: `function`, `string` or `array` Default: `['scope', 'subject']`
Type: `function`, `string` or `array` Default: `'header'`

A compare function used to sort commits. If it's a string or array, it sorts on the property(ies) by `localeCompare`.

Expand Down Expand Up @@ -307,9 +277,6 @@ The output might become
### BREAKING CHANGES

* The &#x60;ngMessagesInclude&#x60; attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive.



```
It is printed to stdout.
Expand Down
34 changes: 4 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,15 @@ function conventionalcommitsWriter(context, options) {
context.linkReferences = context.linkReferences || true;
}

if (host && host[host.length - 1] === '/') {
context.host = host.slice(0, -1);
}

options = _.extend({
options = _.merge({
transform: {
hash: function(hash) {
if (typeof hash === 'string') {
return hash.substring(0, 7);
}
},
subject: function(subject) {
if (typeof subject === 'string') {
return subject.substring(0, 80);
}
},
type: function(type) {
if (type === 'fix') {
return 'Bug Fixes';
} else if (type === 'feat') {
return 'Features';
} else if (type === 'perf') {
return 'Performance Improvements';
}
},
notes: function(notes) {
_.map(notes, function(note) {
if (note.title === 'BREAKING CHANGE') {
note.title = 'BREAKING CHANGES';
}

return note;
});

return notes;
header: function(header) {
return header.substring(0, 100);
},
version: function(version) {
if (typeof version === 'string') {
Expand All @@ -76,7 +50,7 @@ function conventionalcommitsWriter(context, options) {
},
groupBy: 'type',
commitGroupsSort: 'title',
commitsSort: ['scope', 'subject'],
commitsSort: 'header',
noteGroupsSort: 'title',
notesSort: compareFunc(),
generateOn: function(commit) {
Expand Down
2 changes: 1 addition & 1 deletion templates/commit.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*{{#if scope}} **{{scope}}:**{{/if}} {{#if subject}}{{subject}}{{else}}{{header}}{{/if}}
* {{header}}

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

Expand Down
3 changes: 1 addition & 2 deletions test/cli.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
var concat = require('concat-stream');
var dateFormat = require('dateformat');
var expect = require('chai').expect;
var fs = require('fs');
var spawn = require('child_process').spawn;
Expand All @@ -17,7 +16,7 @@ describe('cli', function() {
});
cp.stdout
.pipe(concat(function(chunk) {
expect(chunk.toString()).to.equal('<a name=""></a>\n# (' + dateFormat(new Date(), 'yyyy-mm-dd', true) + ')\n\n\n### Features\n\n* **ngMessages:** provide support for dynamic message resolution 9b1aff9, closes #10036 #9338\n\n\n### BREAKING CHANGES\n\n* The &#x60;ngMessagesInclude&#x60; attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive.\n\n\n\n');
expect(chunk.toString()).to.not.be.empty; // jshint ignore:line
done();
}));
});
Expand Down
Loading

0 comments on commit 9ca5845

Please sign in to comment.