This repository has been archived by the owner on Nov 21, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Idea is from conventional-changelog/conventional-changelog#29.
- Loading branch information
0 parents
commit 5bca527
Showing
14 changed files
with
447 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/node_modules/ | ||
npm-debug.log | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"preset": "google", | ||
"maximumLineLength": null, | ||
"excludeFiles": ["node_modules/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"boss": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"eqnull": true, | ||
"immed": true, | ||
"latedef": true, | ||
"mocha" : true, | ||
"newcap": true, | ||
"noarg": true, | ||
"node": true, | ||
"sub": true, | ||
"undef": true, | ||
"unused": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sudo: false | ||
language: node_js | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coverall-image]][coverall-url] | ||
|
||
> Get a recommended version bump based on conventional commits | ||
Got the idea from https://github.com/ajoslin/conventional-changelog/pull/29 | ||
|
||
## Install | ||
|
||
```sh | ||
$ npm install --save conventional-recommended-bump | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
```js | ||
var conventionalRecommendedBump = require('conventional-recommended-bump'); | ||
|
||
conventionalRecommendedBump({ | ||
conventionalRecommendedBump({ | ||
preset: 'angular' | ||
}, function(err, releaseAs) { | ||
console.log(releaseAs); | ||
}); | ||
}); | ||
``` | ||
|
||
```sh | ||
$ npm install --global conventional-recommended-bump | ||
$ conventional-recommended-bump --help | ||
|
||
Get a recommended version bump based on conventional commits | ||
|
||
Usage | ||
conventional-recommended-bump | ||
|
||
Example | ||
conventional-recommended-bump | ||
Options | ||
-p, --preset Name of the preset you want to use | ||
-h, --header-pattern Regex to match header pattern | ||
-c, --header-correspondence Comma separated parts used to define what capturing group of headerPattern captures what | ||
-r, --reference-actions Comma separated keywords that used to reference issues | ||
-i, --issue-prefixes Comma separated prefixes of an issue | ||
-n, --note-keywords Comma separated keywords for important notes | ||
-f, --field-pattern Regex to match other fields | ||
-v, --verbose Verbose output | ||
``` | ||
|
||
|
||
## API | ||
|
||
### conventionalRecommendedBump([options, [parserOpts]], [callback]) | ||
|
||
#### options | ||
|
||
##### preset | ||
|
||
Type: `string` Possible values: `'angular'` | ||
|
||
A set of options of a popular project. | ||
|
||
##### whatBump | ||
|
||
Type: `function` | ||
|
||
A function that takes parsed commits as argument and returns a number indicating what bump it should be. | ||
|
||
###### whatBump(commits) | ||
|
||
####### commits | ||
|
||
Type: `array` | ||
|
||
An array of parsed commits. The commits are from last semver tag to `HEAD` and is parsed by [conventional-commits-parser](https://github.com/stevemao/conventional-commits-parser). | ||
|
||
If it returns `0` it will be a `major` bump. If `1`, `minor` bump. If `2`, `patch`. | ||
|
||
#### parserOpts | ||
|
||
See the [conventional-commits-parser](https://github.com/stevemao/conventional-commits-parser) docs. | ||
|
||
#### callback | ||
|
||
Type: `function` | ||
|
||
##### callback(error, releaseAs) | ||
|
||
###### releaseAs | ||
|
||
Type: `string` Possible values: `'major'`, `'minor'` and `'patch'` | ||
|
||
The value of what it should release as. If it cannot decide this is an empty string. | ||
|
||
|
||
## License | ||
|
||
MIT © [Steve Mao](https://github.com/stevemao) | ||
|
||
|
||
[npm-image]: https://badge.fury.io/js/conventional-recommended-bump.svg | ||
[npm-url]: https://npmjs.org/package/conventional-recommended-bump | ||
[travis-image]: https://travis-ci.org/stevemao/conventional-recommended-bump.svg?branch=master | ||
[travis-url]: https://travis-ci.org/stevemao/conventional-recommended-bump | ||
[daviddm-image]: https://david-dm.org/stevemao/conventional-recommended-bump.svg?theme=shields.io | ||
[daviddm-url]: https://david-dm.org/stevemao/conventional-recommended-bump | ||
[coverall-image]: https://coveralls.io/repos/stevemao/conventional-recommended-bump/badge.svg | ||
[coverall-url]: https://coveralls.io/r/stevemao/conventional-recommended-bump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
var meow = require('meow'); | ||
var conventionalRecommendedBump = require('./'); | ||
|
||
var cli = meow({ | ||
help: [ | ||
'Usage', | ||
' conventional-recommended-bump', | ||
'', | ||
'Example', | ||
' conventional-recommended-bump', | ||
'Options', | ||
' -p, --preset Name of the preset you want to use', | ||
' -h, --header-pattern Regex to match header pattern', | ||
' -c, --header-correspondence Comma separated parts used to define what capturing group of `headerPattern` captures what', | ||
' -r, --reference-actions Comma separated keywords that used to reference issues', | ||
' -i, --issue-prefixes Comma separated prefixes of an issue', | ||
' -n, --note-keywords Comma separated keywords for important notes', | ||
' -f, --field-pattern Regex to match other fields', | ||
' -v, --verbose Verbose output' | ||
].join('\n') | ||
}, { | ||
alias: { | ||
p: 'preset', | ||
h: 'headerPattern', | ||
c: 'headerCorrespondence', | ||
r: 'referenceActions', | ||
i: 'issuePrefixes', | ||
n: 'noteKeywords', | ||
f: 'fieldPattern', | ||
v: 'verbose' | ||
} | ||
}); | ||
|
||
var options; | ||
var flags = cli.flags; | ||
var preset = flags.preset; | ||
|
||
if (preset) { | ||
options = { | ||
preset: preset | ||
}; | ||
delete flags.preset; | ||
} | ||
|
||
if (flags.verbose) { | ||
options.warn = console.warn.bind(console); | ||
} | ||
|
||
conventionalRecommendedBump(options, flags, function(err, releaseAs) { | ||
if (err) { | ||
console.error(err.toString()); | ||
process.exit(1); | ||
} | ||
|
||
console.log(releaseAs); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
var concat = require('concat-stream'); | ||
var conventionalCommitsParser = require('conventional-commits-parser'); | ||
var gitLatestSemverTag = require('git-latest-semver-tag'); | ||
var gitRawCommits = require('git-raw-commits'); | ||
var objectAssign = require('object-assign'); | ||
|
||
var VERSIONS = ['major', 'minor', 'patch']; | ||
|
||
function conventionalRecommendedBump(options, parserOpts, cb) { | ||
var preset; | ||
var noop = function() {}; | ||
|
||
if (typeof options === 'function') { | ||
cb = options; | ||
} else if (typeof parserOpts === 'function') { | ||
cb = parserOpts; | ||
} else { | ||
cb = cb || noop; | ||
} | ||
|
||
options = objectAssign({ | ||
warn: function() {} | ||
}, options); | ||
|
||
if (options.preset) { | ||
try { | ||
preset = require('./presets/' + options.preset); | ||
} catch (err) { | ||
cb(new Error('Preset: "' + options.preset + '" does not exist')); | ||
return; | ||
} | ||
} else { | ||
preset = {}; | ||
} | ||
|
||
var whatBump = options.whatBump || preset.whatBump || noop; | ||
parserOpts = objectAssign({}, preset.parserOpts, parserOpts); | ||
parserOpts.warn = parserOpts.warn || options.warn; | ||
|
||
gitLatestSemverTag(function(err, tag) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
|
||
gitRawCommits({ | ||
from: tag | ||
}) | ||
.pipe(conventionalCommitsParser(parserOpts)) | ||
.pipe(concat(function(data) { | ||
var level = whatBump(data); | ||
var releaseAs = VERSIONS[level]; | ||
|
||
if (releaseAs) { | ||
cb(null, releaseAs); | ||
} else { | ||
cb(null, ''); | ||
} | ||
})); | ||
}); | ||
} | ||
|
||
module.exports = conventionalRecommendedBump; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "conventional-recommended-bump", | ||
"version": "0.0.0", | ||
"description": "Get a recommended version bump based on conventional commits", | ||
"homepage": "https://github.com/stevemao/conventional-recommended-bump", | ||
"author": { | ||
"name": "Steve Mao", | ||
"email": "maochenyan@gmail.com", | ||
"url": "https://github.com/stevemao" | ||
}, | ||
"repository": "stevemao/conventional-recommended-bump", | ||
"license": "MIT", | ||
"keywords": [ | ||
"conventional-recommended-bump", | ||
"recommend", | ||
"conventional", | ||
"bump" | ||
], | ||
"dependencies": { | ||
"concat-stream": "^1.4.10", | ||
"conventional-commits-parser": "0.0.17", | ||
"git-latest-semver-tag": "0.0.0", | ||
"git-raw-commits": "0.0.7", | ||
"meow": "^3.1.0", | ||
"object-assign": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^2.11.2", | ||
"istanbul": "^0.3.8", | ||
"jscs": "^1.11.3", | ||
"jshint": "^2.6.3", | ||
"mocha": "*", | ||
"shelljs": "^0.5.1" | ||
}, | ||
"scripts": { | ||
"coverage": "istanbul cover _mocha -- -R spec && rm -rf ./coverage", | ||
"lint": "jshint presets test *.js --exclude node_modules && jscs presets test *.js", | ||
"test": "npm run-script lint && mocha" | ||
}, | ||
"bin": "cli.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var presetOpts = { | ||
whatBump: function(commits) { | ||
var level = 2; | ||
|
||
commits.some(function(commit) { | ||
if (commit.notes.length > 0) { | ||
level = 0; | ||
return true; | ||
} else if (commit.type === 'feat') { | ||
level = 1; | ||
return true; | ||
} | ||
}); | ||
|
||
return level; | ||
}, | ||
parserOpts: { | ||
headerPattern: /^(\w*)(?:\((.*)\))?\: (.*)$/, | ||
headerCorrespondence: [ | ||
'type', | ||
'scope', | ||
'subject' | ||
], | ||
noteKeywords: 'BREAKING CHANGE' | ||
} | ||
}; | ||
|
||
module.exports = presetOpts; |
Oops, something went wrong.