Socket
Socket
Sign inDemoInstall

conventional-changelog

Package Overview
Dependencies
Maintainers
2
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conventional-changelog - npm Package Compare versions

Comparing version 0.0.17 to 0.1.0-alpha.1

.editorconfig

21

CHANGELOG.md

@@ -0,1 +1,22 @@

<a name="0.1.0-alpha.1"></a>
# 0.1.0-alpha.1 (2015-06-24)
### Bug Fixes
* **err:** emit error if there is any in gitRawCommits and conventionalCommitsParser ([00ac3c1](https://github.com/ajoslin/conventional-changelog/commit/00ac3c1))
### Features
* **cli:** first commit of cli ([d74b96b](https://github.com/ajoslin/conventional-changelog/commit/d74b96b)), closes [#31](https://github.com/ajoslin/conventional-changelog/issues/31)
* **issuePrefixes:** default for the hosts ([b1c3ee9](https://github.com/ajoslin/conventional-changelog/commit/b1c3ee9)), closes [#59](https://github.com/ajoslin/conventional-changelog/issues/59) [#60](https://github.com/ajoslin/conventional-changelog/issues/60)
* **rewrite:** rewrite this module ([7c48e0d](https://github.com/ajoslin/conventional-changelog/commit/7c48e0d)), closes [#50](https://github.com/ajoslin/conventional-changelog/issues/50) [#45](https://github.com/ajoslin/conventional-changelog/issues/45) [#40](https://github.com/ajoslin/conventional-changelog/issues/40) [#22](https://github.com/ajoslin/conventional-changelog/issues/22) [#13](https://github.com/ajoslin/conventional-changelog/issues/13) [#12](https://github.com/ajoslin/conventional-changelog/issues/12) [#54](https://github.com/ajoslin/conventional-changelog/issues/54) [#51](https://github.com/ajoslin/conventional-changelog/issues/51)
### BREAKING CHANGES
* This module is rewritten so API is changed and it is not backward compatible. Please check docs and all the submodules including git-raw-commits, conventional-commits-parser and conventional-commits-writer for more information.
<a name"0.0.17"></a>

@@ -2,0 +23,0 @@ ### 0.0.17 (2015-04-03)

188

index.js
'use strict';
var conventionalCommitsParser = require('conventional-commits-parser');
var conventionalCommitsWriter = require('conventional-commits-writer');
var fs = require('fs');
var git = require('./lib/git');
var writeLog = require('./lib/writeLog');
var extend = require('lodash').assign;
var getPkgRepo = require('get-pkg-repo');
var gitLatestSemverTag = require('git-latest-semver-tag');
var gitRawCommits = require('git-raw-commits');
var Q = require('q');
var stream = require('stream');
var through = require('through2');
var url = require('url');
var _ = require('lodash');
function generate(options, done) {
function getChangelogCommits() {
git.getCommits(options, function(err, commits) {
if (err) {
return done('Failed to read git log.\n' + err);
}
writeChangelog(commits);
});
var rhosts = /github|butbucket/i;
function changelog(options, context, gitRawCommitsOpts, parserOpts, writerOpts) {
var presetPromise;
var pkgPromise;
var latestSemverPromise;
var readable = new stream.Readable();
readable._read = function() {};
context = context || {};
gitRawCommitsOpts = gitRawCommitsOpts || {};
options = _.assign({
pkg: 'package.json',
append: false,
allBlocks: false,
warn: function() {},
}, options);
var loadPreset = options.preset;
var loadPkg = (!context.host || !context.repository || !context.version) && options.pkg;
if (loadPreset) {
try {
var presetFn = require('./presets/' + options.preset);
presetPromise = Q.nfcall(presetFn);
} catch (err) {
options.warn('Preset: "' + options.preset + '" does not exist');
}
}
function writeChangelog(commits) {
options.log('Parsed %d commits.', commits.length);
writeLog(commits, options, function(err, changelog) {
if (err) {
return done('Failed to write changelog.\n' + err);
if (loadPkg) {
pkgPromise = Q.nfcall(fs.readFile, options.pkg, 'utf8');
}
if (!options.allBlocks && !gitRawCommitsOpts.from) {
latestSemverPromise = Q.nfcall(gitLatestSemverTag);
}
Q.allSettled([presetPromise, pkgPromise, latestSemverPromise])
.spread(function(presetObj, pkgObj, tagObj) {
var preset;
var pkg;
var tag;
var hostOpts;
if (loadPreset) {
if (presetObj.state === 'fulfilled') {
preset = presetObj.value;
} else {
options.warn('Internal error in preset: "' + options.preset + '"');
preset = {};
}
} else {
preset = {};
}
if (options.file && fs.existsSync(options.file)) {
fs.readFile(options.file, {
encoding: 'UTF-8'
}, function(err, contents) {
if (err) {
return done('Failed to read ' + options.file + '.\n' + err);
if (loadPkg) {
if (pkgObj.state === 'fulfilled') {
pkg = pkgObj.value;
try {
pkg = JSON.parse(pkg);
var repositoryUrl = url.parse(getPkgRepo(pkg));
context.host = context.host || repositoryUrl.protocol + (repositoryUrl.slashes ? '//' : '') + repositoryUrl.host;
context.version = context.version || pkg.version;
context.repository = context.repository || repositoryUrl.pathname.replace('/', '');
} catch (err) {
options.warn('package.json: "' + options.pkg + '" cannot be parsed');
pkg = {};
}
done(null, changelog + '\n' + String(contents));
});
} else {
options.warn('package.json: "' + options.pkg + '" does not exist');
pkg = {};
}
} else {
done(null, changelog);
pkg = {};
}
if (tagObj.state === 'fulfilled') {
tag = tagObj.value;
}
if (context.host && (!context.issue || !context.commit || !parserOpts || !parserOpts.referenceActions)) {
var match = context.host.match(rhosts);
if (match) {
hostOpts = require('./hosts/' + match[0]);
context = _.assign({
issue: hostOpts.issue,
commit: hostOpts.commit
}, context);
} else {
options.warn('Host: "' + context.host + '" does not exist');
hostOpts = {};
}
} else {
hostOpts = {};
}
gitRawCommitsOpts = _.assign({
format: '%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci',
from: tag
},
gitRawCommitsOpts
);
if (options.append) {
gitRawCommitsOpts.reverse = gitRawCommitsOpts.reverse || true;
}
parserOpts = _.assign(
preset.parserOpts || {}, {
referenceActions: hostOpts.referenceActions,
issuePrefixes: hostOpts.issuePrefixes,
warn: options.warn
},
parserOpts);
writerOpts = _.assign(
preset.writerOpts || {}, {
reverse: options.append
},
writerOpts
);
gitRawCommits(gitRawCommitsOpts)
.on('error', function(err) {
readable.emit('error', 'Error in git-raw-commits. ' + err);
})
.pipe(conventionalCommitsParser(parserOpts))
.on('error', function(err) {
readable.emit('error', 'Error in conventional-commits-parser. ' + err);
})
// it would be better to if `gitRawCommits` could spit out better formatted data
// so we don't need to transform here
.pipe(options.transform || preset.transform || through.obj())
.pipe(conventionalCommitsWriter(context, writerOpts))
.pipe(through(function(chunk, enc, cb) {
readable.push(chunk);
cb();
}, function(cb) {
readable.push(null);
cb();
}));
});
}
options = extend({
file: 'CHANGELOG.md',
log: console.log.bind(console),
warn: console.warn.bind(console)
}, options || {});
getChangelogCommits();
return readable;
}
module.exports = generate;
module.exports = changelog;

57

package.json
{
"name": "conventional-changelog",
"version": "0.0.17",
"description": "Generate a changelog from git metadata, using the AngularJS commit conventions",
"main": "index.js",
"scripts": {
"coverage": "istanbul cover _mocha -- -R spec && rm -rf ./coverage",
"lint": "jshint lib test index.js --exclude node_modules",
"test": "npm run-script lint && mocha --no-colors"
},
"files": [
"index.js",
"lib/",
"test/"
],
"version": "0.1.0-alpha.1",
"description": "Generate a changelog from git metadata",
"repository": {

@@ -21,3 +10,6 @@ "type": "git",

"keywords": [
"changelog"
"conventional-changelog",
"conventional",
"changelog",
"log"
],

@@ -37,15 +29,36 @@ "license": "BSD",

"dependencies": {
"add-stream": "^1.0.0",
"compare-func": "^1.2.0",
"conventional-commits-parser": "0.0.17",
"conventional-commits-writer": "0.0.14",
"dateformat": "^1.0.11",
"event-stream": "^3.3.0",
"github-url-from-git": "^1.4.0",
"lodash": "^3.6.0",
"normalize-package-data": "^1.0.3"
"get-pkg-repo": "0.0.6",
"git-latest-semver-tag": "0.0.0",
"git-raw-commits": "0.0.7",
"lodash": "^3.9.3",
"meow": "^3.1.0",
"q": "^1.4.1",
"semver": "^4.3.6",
"tempfile": "^1.1.1",
"through2": "^2.0.0"
},
"devDependencies": {
"chai": "^2.2.0",
"chai": "^3.0.0",
"concat-stream": "^1.4.10",
"coveralls": "^2.11.2",
"istanbul": "^0.3.13",
"jshint": "^2.6.3",
"mocha": "*"
"istanbul": "^0.3.15",
"jscs": "^1.13.1",
"jshint": "^2.8.0",
"mocha": "*",
"shelljs": "^0.5.1"
},
"scripts": {
"coverage": "istanbul cover _mocha -- -R spec && rm -rf ./coverage",
"lint": "jshint presets hosts test *.js --exclude node_modules && jscs presets hosts test *.js",
"test": "npm run-script lint && mocha"
},
"bin": "cli.js",
"publishConfig": {
"tag": "0.1.0-alpha"
}
}

@@ -1,6 +0,16 @@

# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coverall-image]][coverall-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]
> Generate a changelog from git metadata, using the AngularJS commit conventions
> Generate a changelog from git metadata
## Why
- Used by AngularJS and related projects.
- Everything internally or externally is 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

@@ -12,8 +22,8 @@

- [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).
*Note:* As 0.1.x this module is rewritten and so the API is not backward compatible. If you are still using 0.0.x please checkout the README in your downloaded package or dig through the old tags.
[Synopsis of Conventions](conventions)
## Example output

@@ -25,62 +35,114 @@

## 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({
preset: 'angular'
})
.pipe(process.stdout);
```
## 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);
});
```
### conventionalChangelog([options, [context, [gitRawCommitsOpts, [parserOpts, [writerOpts]]]]])
#### `changelog(options, callback)`
Returns a readable stream.
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).
#### options
`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.
##### preset
`options` is the first parameter, an object. The following fields are available:
Type: `string` Possible values: `'angular'`, `'jquery'`
##### The Most Important Options
A set of options of a popular project.
* `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.
##### pkg
* `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: `string` Default: `'package.json'`
* `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.
The location of your "package.json".
* `pkg` `{string}` - The path of `package.json`. Defaults to `./package.json`.
##### append
* `from` `{string}` - Which commit the changelog should start at. By default, uses previous tag, or if no previous tag the first commit.
Type: `boolean` Default: `false`
* `to` `{string}` - Which commit the changelog should end at. By default, uses HEAD.
Should the log be appended.
* `file` `{string}` - Which file to read the current changelog from and prepend the new changelog's contents to. By default, uses `'CHANGELOG.md'`.
##### allBlocks
##### The "I really want to get crazy" Options
Type: `boolean` Default: `false`
* `versionText` `{function(version, subtitle)}` - What to use for the title of a major version in the changelog. Defaults to `'## ' + version + ' ' + subtitle`.
Set to `true` if you want to generate all blocks of the log. `false` if you just want to generate the current one.
* `patchVersionText` `{function(version, subtitle)}` - What to use for the title of a patch version in the changelog. Defaults to `'### ' + version + ' ' + subtitle`.
##### warn
* `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`.
Type: `function` Default: `function() {}`
* `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`.
A warn function. EG: `grunt.verbose.writeln`
* `log` `{function()}` - What logging function to use. For example, `{log: grunt.log.ok}`. By default, uses `console.log`.
##### transform
* `warn` `{function()}` - What warn function to use. For example, `{warn: grunt.log.writeln}`. By default, uses `console.warn`.
Type: `object` Default: `through.obj()`
A transform stream that applies after the parser and before the writer.
#### context
See the [conventional-commits-writer](https://github.com/stevemao/conventional-commits-writer) docs.
#### gitRawCommitsOpts
See the [git-raw-commits](https://github.com/stevemao/git-raw-commits) docs.
#### parserOpts
See the [conventional-commits-parser](https://github.com/stevemao/conventional-commits-parser) docs.
#### writerOpts
See the [conventional-commits-writer](https://github.com/stevemao/conventional-commits-writer) docs.
### CLI
```sh
$ npm install -g conventional-changelog
```
```sh
$ conventional-changelog --help
Generate a changelog from git metadata
Usage
conventional-changelog
Example
conventional-changelog -i CHANGELOG.md --overwrite
Options
-i, --infile Read the CHANGELOG from this file.
-o, --outfile Write the CHANGELOG to this file. If unspecified, it prints to stdout
-w, --overwrite Overwrite the infile
-p, --preset Name of the preset you want to use
-k, --pkg A filepath of where your package.json is located
-a, --append Should the generated block be appended
-b, --all-blocks Generate all blocks
-v, --verbose Verbose output
-c, --context A filepath of a javascript that is used to define template variables
--git-raw-commits-opts A filepath of a javascript that is used to define git-raw-commits options
--parser-opts A filepath of a javascript that is used to define conventional-commits-parser options
--writer-opts A filepath of a javascript that is used to define conventional-commits-writer options
```
## Related
- [conventional-recommended-bump](https://github.com/stevemao/conventional-recommended-bump) - Get a recommended version bump based on conventional commits
## License

@@ -97,3 +159,3 @@

[daviddm-url]: https://david-dm.org/ajoslin/conventional-changelog
[coverall-image]: https://coveralls.io/repos/ajoslin/conventional-changelog/badge.svg
[coverall-url]: https://coveralls.io/r/ajoslin/conventional-changelog
[coveralls-image]: https://coveralls.io/repos/ajoslin/conventional-changelog/badge.svg
[coveralls-url]: https://coveralls.io/r/ajoslin/conventional-changelog
{
"name": "test",
"version": "1.0.0",
"repository": "www.bitbucket.com/user/repo.git"
"version": "0.0.17",
"repository": {
"type": "git",
"url": "https://github.com/ajoslin/conventional-changelog.git"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc