Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable version to be specified #42

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ $ changelog -h
-p, --patch create a patch changelog
-m, --minor create a minor changelog
-M, --major create a major changelog
-s, --semver [value] the version value (e.g. v1.2.3)
-t, --tag <range> generate from specific tag or range (e.g. v1.2.3 or v1.2.3..v1.2.4)
-x, --exclude <types> exclude selected commit types (comma separated)
-f, --file [file] file to write to, defaults to ./CHANGELOG.md, use - for stdout
Expand Down Expand Up @@ -92,6 +93,13 @@ The way that I would recommend using this module would be the way it's being use
"release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags",
```

To use a specific version rather than a generated value, you can use `-s VERSION` or `--semver VERSION` rather than the major, minor or patch argument switches. For example, using npm's version `scripts` object in your `package.json` the previous `release` scripts could be condensed to:

```json
"version": "changelog -s $npm_package_version && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md"
"postversion": "git push origin && git push origin --tags"
```

## Testing

To run the test suite, just clone the repository and run the following:
Expand Down
1 change: 1 addition & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = CLI
.option('-p, --patch', 'create a patch changelog')
.option('-m, --minor', 'create a minor changelog')
.option('-M, --major', 'create a major changelog')
.option('-s, --semver [value]', 'specify the version to use (e.g. v1.2.3)')
.option('-t, --tag <range>', 'generate from specific tag or range (e.g. v1.2.3 or v1.2.3..v1.2.4)')
.option('-x, --exclude <types>', 'exclude selected commit types (comma separated)', list)
.option('-f, --file [file]', 'file to write to, defaults to ./CHANGELOG.md, use - for stdout', './CHANGELOG.md')
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var Writer = require('./writer');
* @param {Boolean} options.patch - whether it should be a patch changelog
* @param {Boolean} options.minor - whether it should be a minor changelog
* @param {Boolean} options.major - whether it should be a major changelog
* @param {String} [options.semver] - the semver version
* @param {String} options.repoUrl - repo URL that will be used when linking commits
* @param {Array} options.exclude - exclude listed commit types (e.g. ['chore', 'style', 'refactor'])
* @returns {Promise<String>} the \n separated changelog string
Expand Down
7 changes: 7 additions & 0 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var File = require('./file');
var ParseGitHubUrl = require('github-url-from-git');
var Bluebird = require('bluebird');

/**
* Get the package.json object located in the current directory.
Expand Down Expand Up @@ -46,10 +47,16 @@ exports.extractRepoUrl = function () {
* @param {Boolean} options.patch - whether it should be a patch version
* @param {Boolean} options.minor - whether it should be a minor version
* @param {Boolean} options.major - whether it should be a major version
* @param {String} [options.semver] - the semver version
* @returns {Promise<String>} - new version
*/
exports.calculateNewVersion = function (options) {
options = options || {};

if (options.semver) {
return Bluebird.resolve(options.semver);
}

return exports.getUserPackage()
.then(function (userPackage) {
if (!userPackage.version) {
Expand Down
9 changes: 9 additions & 0 deletions test/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ describe('package', function () {
});
});

it('return the version value if semver is provided', function () {
var options = { semver: '1.0.0' };

return Package.calculateNewVersion(options)
.then(function (version) {
Expect(version).to.eql('1.0.0');
});
});

it('leaves the version untouched if none of three options is true', function () {
return Package.calculateNewVersion()
.then(function (version) {
Expand Down