Skip to content

Commit

Permalink
feat(rewrite): rewrite this module
Browse files Browse the repository at this point in the history
Use smaller modules including git-raw-commits, conventional-commits-parser and conventional-commits-writer. It has better API and better project structures.

BREAKING CHANGE:

This module is rewritten so API is changed and it is not backward compatible. Please check git-raw-commits, conventional-commits-parser and conventional-commits-writer for more information.
  • Loading branch information
stevemao committed Jun 10, 2015
1 parent 4c7ec38 commit 5c6d92f
Show file tree
Hide file tree
Showing 36 changed files with 1,004 additions and 764 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
/node_modules/
npm-debug.log
tmp
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -4,4 +4,7 @@ node_js:
- 'iojs'
- '0.12'
- '0.10'
before_script:
- git config --global user.name "Travis-CI"
- git config --global user.email "dummy@example.org"
after_script: NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
82 changes: 44 additions & 38 deletions README.md
@@ -1,6 +1,16 @@
# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url]

> Generate a changelog from git metadata, using the AngularJS commit conventions
> Generate a changelog from git metadata

## Why

- Used by AngularJS and related projects.
- Pluggable.
- High performant. It doesn't spawn any extra child process to fetch data.
- Fully configurable. There are several presets that you can use if you just want to use the same conventions. But it is also possible to configure if you want to go down to the nth degree.
- Task runner integrations.
- Actively maintained.


## Install
Expand All @@ -9,9 +19,6 @@
$ npm install conventional-changelog
```

- [Synopsis of Conventions in CONVENTIONS.md](https://github.com/ajoslin/conventional-changelog/blob/master/CONVENTIONS.md)
- [Full Convention Spec on Google Docs](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/)

Adapted from code originally written by @vojtajina and @btford in [grunt-conventional-changelog](https://github.com/btford/grunt-conventional-changelog).


Expand All @@ -21,65 +28,64 @@ Adapted from code originally written by @vojtajina and @btford in [grunt-convent
- https://github.com/karma-runner/karma/blob/master/CHANGELOG.md


## Roadmap
## Usage

- Make it return a stream
- Add a proper command line interface
- Add configurable subjects & sections
- Split up this repo into smaller modules [#22](https://github.com/ajoslin/conventional-changelog/issues/22)
```js
var conventionalChangelog = require('conventional-changelog');

conventionalChangelog();
```

## Documentation

Simple usage:
## API

```js
require('conventional-changelog')({
repository: 'https://github.com/joyent/node',
version: require('./package.json').version
}, function(err, log) {
console.log('Here is your changelog!', log);
});
```
### changelog([options, [context, [gitRawCommitsOpts, [parserOpts, [writerOpts]]]]])

Returns a readable stream.

#### options

##### preset

#### `changelog(options, callback)`
Type: `string`

By default, calls the callback with a string containing a changelog from the previous tag to HEAD, using pkg.version, prepended to existing CHANGELOG.md (if it exists).
##### pkg

`callback` is the second parameter, and takes two parameters: `(err, log)`. `log` is a string containing the newly generated changelog, and `err` is either an error or null.
Type: `string` Default: `'package.json'`

`options` is the first parameter, an object. The following fields are available:
##### append

##### The Most Important Options
Type: `boolean` Default: `false`

* `version` `{string}` - The version to be written to the changelog. For example, `{version: "1.0.1"}`. Defaults to the version found in `package.json`. See `pkg` to configure the path of package.json.
##### allBlocks

* `subtitle` `{string}` - A string to display after the version title in the changelog. For example, it will show '## 1.0.0 "Super Version"' if codename '"Super Version"' is given. By default, it's blank.
Type: `boolean` Default: `false`

* `repository` `{string}` - If this is provided, allows issues and commit hashes to be linked to the actual commit. Usually used with github repositories. For example, `{repository: 'http://github.com/joyent/node'}`. Defaults to "normalized" `repository.url` found in `package.json`. See `pkg` to configure the path of package.json.
##### warn

* `pkg` `{string}` - The path of `package.json`. Defaults to `./package.json`.
Type: `function` Default: `function() {}`

* `from` `{string}` - Which commit the changelog should start at. By default, uses previous tag, or if no previous tag the first commit.
##### transform

* `to` `{string}` - Which commit the changelog should end at. By default, uses HEAD.
Type: `object` Default: `through.obj()`

* `file` `{string}` - Which file to read the current changelog from and prepend the new changelog's contents to. By default, uses `'CHANGELOG.md'`.
A transform stream that applies after the parser and before the writer.

##### The "I really want to get crazy" Options
#### context

* `versionText` `{function(version, subtitle)}` - What to use for the title of a major version in the changelog. Defaults to `'## ' + version + ' ' + subtitle`.
See the [conventional-commits-writer](https://github.com/stevemao/conventional-commits-writer) docs.

* `patchVersionText` `{function(version, subtitle)}` - What to use for the title of a patch version in the changelog. Defaults to `'### ' + version + ' ' + subtitle`.
#### gitRawCommitsOpts

* `commitLink` `{function(commitHash)}` - If repository is provided, this function will be used to link to commits. By default, returns a github commit link based on options.repository: `opts.repository + '/commit/' + hash`.
See the [git-raw-commits](https://github.com/stevemao/git-raw-commits) docs.

* `issueLink` `{function(issueId)}` - If repository is provided, this function will be used to link to issues. By default, returns a github issue link based on options.repository: `opts.repository + '/issues/' + id`.
#### parserOpts

* `log` `{function()}` - What logging function to use. For example, `{log: grunt.log.ok}`. By default, uses `console.log`.
See the [conventional-commits-parser](https://github.com/stevemao/conventional-commits-parser) docs.

* `warn` `{function()}` - What warn function to use. For example, `{warn: grunt.log.writeln}`. By default, uses `console.warn`.
#### writerOpts

See the [conventional-commits-writer](https://github.com/stevemao/conventional-commits-writer) docs.

## License

Expand Down
85 changes: 85 additions & 0 deletions cli.js
@@ -0,0 +1,85 @@
#!/usr/bin/env node
'use strict';
var conventionalChangelog = require('./');
var fs = require('fs');
var meow = require('meow');

var cli = meow({
help: [
'Usage',
' conventional-changelog [<path>]',
' cat <path> | conventional-changelog',
'',
'Example',
' conventional-changelog CHANGELOG.md > CHANGELOG.md',
' cat CHANGELOG.md | conventional-changelog',
'',
'Options',
' -o, --options A filepath of a javascript that is used to define options',
' -t, --context A filepath of a javascript that is used to define template variables',
' --gitRawCommitsOpts A filepath of a javascript that is used to define git-raw-commits options',
' --parserOpts A filepath of a javascript that is used to define conventional-commits-parser options',
' --writerOpts A filepath of a javascript that is used to define conventional-commits-writer options',
].join('\n')
}, {
alias: {
o: 'options',
c: 'context'
}
});

var path = cli.input[0];
var flags = cli.flags;
var options;
var templateContext;
var gitRawCommitsOpts;
var parserOpts;
var writerOpts;

try {
if (flags.options) {
options = require(flags.options);
}

if (flags.context) {
templateContext = require(flags.context);
}

if (flags.gitRawCommitsOpts) {
gitRawCommitsOpts = require(flags.gitRawCommitsOpts);
}

if (flags.parserOpts) {
parserOpts = require(flags.parserOpts);
}

if (flags.writerOpts) {
writerOpts = require(flags.writerOpts);
}
} catch (err) {
console.error('Failed to get file. ' + err);
process.exit(1);
}

var stream = conventionalChangelog(options, templateContext, gitRawCommitsOpts, parserOpts, writerOpts);

if (path && (!options || !options.allBlocks)) {
if (options && options.append) {
fs.createReadStream(path)
.on('end', function() {
stream
.pipe(process.stdout);
})
.pipe(process.stdout);
} else {
stream
.on('end', function() {
fs.createReadStream(path)
.pipe(process.stdout);
})
.pipe(process.stdout);
}
} else {
stream
.pipe(process.stdout);
}
17 changes: 14 additions & 3 deletions CONVENTIONS.md → conventions/angular.md
@@ -1,4 +1,5 @@
### Commit Message Format

Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
format that includes a **type**, a **scope** and a **subject**:

Expand All @@ -14,6 +15,7 @@ Any line of the commit message cannot be longer 100 characters! This allows the
to read on github as well as in various git tools.

### Type

Must be one of the following:

* **feat**: A new feature
Expand All @@ -28,25 +30,34 @@ Must be one of the following:
generation

### 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** are detected as such if the Footer contains a line starting with
`BREAKING CHANGE:` The rest of the commit message is then used for this.
**Breaking Changes** are detected as such if the footer contains a line starting with BREAKING CHANGE:
(with optional 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

A detailed explanation can be found in this [document](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/).
[commit-message-format]: https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#
24 changes: 24 additions & 0 deletions conventions/atom.md
@@ -0,0 +1,24 @@
## Git Commit Messages

* Use the present tense ("Add feature" not "Added feature")
* Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
* Limit the first line to 72 characters or less
* Reference issues and pull requests liberally
* Consider starting the commit message with an applicable emoji:
* :art: `:art:` when improving the format/structure of the code
* :racehorse: `:racehorse:` when improving performance
* :non-potable_water: `:non-potable_water:` when plugging memory leaks
* :memo: `:memo:` when writing docs
* :penguin: `:penguin:` when fixing something on Linux
* :apple: `:apple:` when fixing something on Mac OS
* :checkered_flag: `:checkered_flag:` when fixing something on Windows
* :bug: `:bug:` when fixing a bug
* :fire: `:fire:` when removing code or files
* :green_heart: `:green_heart:` when fixing the CI build
* :white_check_mark: `:white_check_mark:` when adding tests
* :lock: `:lock:` when dealing with security
* :arrow_up: `:arrow_up:` when upgrading dependencies
* :arrow_down: `:arrow_down:` when downgrading dependencies
* :shirt: `:shirt:` when removing linter warnings

Based on https://github.com/atom/atom/blob/master/CONTRIBUTING.md#git-commit-messages
33 changes: 33 additions & 0 deletions conventions/eslint.md
@@ -0,0 +1,33 @@
Make the changes to the code and tests and then commit to your branch. Be sure to follow the commit message conventions.

Commit message summaries must follow this basic format:

```
Tag: Message (fixes #1234)
```

`Tag` should not be confused with git tag.

The `Tag` is one of the following:

* `Fix` - for a bug fix.
* `Update` - for a backwards-compatible enhancement.
* `Breaking` - for a backwards-incompatible enhancement.
* `Docs` - changes to documentation only.
* `Build` - changes to build process only.
* `New` - implemented a new feature.
* `Upgrade` - for a dependency upgrade.

The message summary should be a one-sentence description of the change. The issue number should be mentioned at the end. * The commit message should say "(fixes #1234)" at the end of the description if it closes out an existing issue (replace 1234 with the issue number). If the commit doesn't completely fix the issue, then use `(refs #1234)` instead of `(fixes #1234)`.

Here are some good commit message summary examples:

```
Build: Update Travis to only test Node 0.10 (refs #734)
Fix: Semi rule incorrectly flagging extra semicolon (fixes #840)
Upgrade: Esprima to 1.2, switch to using Esprima comment attachment (fixes #730)
```

The commit message format is important because these messages are used to create a changelog for each release. The tag and issue number help to create more consistent and useful changelogs.

Based on https://github.com/eslint/eslint.github.io/blob/master/docs/developer-guide/contributing.md#step-2-make-your-changes
39 changes: 39 additions & 0 deletions conventions/jquery.md
@@ -0,0 +1,39 @@
## Commit Guidelines

Commits should be atomic. If three separate issues are being fixed (unless they are all fixed by one change), they need to be done as three separate commits. This also applies to whitespace changes, which should be done in their own commit. Whitespace commits should not include code or content changes. Accordingly, code change commits should not include whitespace changes (unless the whitespace changes are on the same lines as the code being changed).

Commit messages should describe what changed, and reference the issue number if the commit closes or is associated with a particular issue. Commit messages for all jQuery projects should look like this:

```
Component: Short Description
Optional Long Description
Fixes #xxx
Closes gh-yyy
Ref #zzz
```

Every commit must have a subject (the first line). Everything else is optional.

### Subject

This is the first line. It consists of a component, like "Event" or "Autocomplete". This line must be 72 characters or less. There should be no full stop (period) at the end.

### Long description

There are two line breaks between the subject and the long description. The description can have any length and formatting, like lists, but it must be hard-wrapped at 80 characters.

### References

References to issues or pull requests go after the long description, each one on their own line.

* Use **Fixes** when the commit fixes an open issue.

* Use **Closes** when the commit closes an open pull request.

* Use **Ref** when referencing an issue or pull request that is already closed or should remain open. Examples include partial fixes and commits that add a test but not a fix.

* Always use "gh-xxx" for GitHub issues and pull requests within the same repository. Use "\[user\]/\[repo\]#xxx" when referencing an issue or pull request in another repository, e.g., "Closes jquery/jquery-ui#175".

Based on https://github.com/jquery/contribute.jquery.org/blob/master/pages/commits-and-pull-requests.md#commit-guidelines

0 comments on commit 5c6d92f

Please sign in to comment.