Skip to content

Commit 6180b00

Browse files
committed
feat: Initial commit 🎉
0 parents  commit 6180b00

25 files changed

+11054
-0
lines changed

.codeclimate.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
engines:
2+
eslint:
3+
enabled: true
4+
config:
5+
config: .eslintrc.js
6+
duplication:
7+
enabled: true
8+
exclude_paths:
9+
- test/**/*
10+
config:
11+
languages:
12+
- javascript
13+
ratings:
14+
paths:
15+
- src/index.js
16+
- test/*.js
17+
- test/helpers/*.js

.eslintrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
extends: [
3+
'@metahub/eslint-config/es6-config',
4+
'@metahub/eslint-config/node-config',
5+
'@metahub/eslint-config/promise-config',
6+
'@metahub/eslint-config/ava-config',
7+
'@metahub/eslint-config/prettier-config',
8+
],
9+
parserOptions: {sourceType: 'module'},
10+
};

.gitignore

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
2+
# Created by https://www.gitignore.io/api/macos,windows,linux,node
3+
4+
### Linux ###
5+
*~
6+
7+
# temporary files which can be created if a process still has a handle open of a deleted file
8+
.fuse_hidden*
9+
10+
# KDE directory preferences
11+
.directory
12+
13+
# Linux trash folder which might appear on any partition or disk
14+
.Trash-*
15+
16+
# .nfs files are created when an open file is removed but is still being accessed
17+
.nfs*
18+
19+
### macOS ###
20+
*.DS_Store
21+
.AppleDouble
22+
.LSOverride
23+
24+
# Icon must end with two \r
25+
Icon
26+
27+
# Thumbnails
28+
._*
29+
30+
# Files that might appear in the root of a volume
31+
.DocumentRevisions-V100
32+
.fseventsd
33+
.Spotlight-V100
34+
.TemporaryItems
35+
.Trashes
36+
.VolumeIcon.icns
37+
.com.apple.timemachine.donotpresent
38+
39+
# Directories potentially created on remote AFP share
40+
.AppleDB
41+
.AppleDesktop
42+
Network Trash Folder
43+
Temporary Items
44+
.apdisk
45+
46+
### Node ###
47+
# Logs
48+
logs
49+
*.log
50+
npm-debug.log*
51+
yarn-debug.log*
52+
yarn-error.log*
53+
54+
# Runtime data
55+
pids
56+
*.pid
57+
*.seed
58+
*.pid.lock
59+
60+
# Directory for instrumented libs generated by jscoverage/JSCover
61+
lib-cov
62+
63+
# Coverage directory used by tools like istanbul
64+
coverage
65+
66+
# nyc test coverage
67+
.nyc_output
68+
69+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
70+
.grunt
71+
72+
# Bower dependency directory (https://bower.io/)
73+
bower_components
74+
75+
# node-waf configuration
76+
.lock-wscript
77+
78+
# Compiled binary addons (http://nodejs.org/api/addons.html)
79+
build/Release
80+
81+
# Dependency directories
82+
node_modules/
83+
jspm_packages/
84+
85+
# Typescript v1 declaration files
86+
typings/
87+
88+
# Optional npm cache directory
89+
.npm
90+
91+
# Optional eslint cache
92+
.eslintcache
93+
94+
# Optional REPL history
95+
.node_repl_history
96+
97+
# Output of 'npm pack'
98+
*.tgz
99+
100+
# Yarn Integrity file
101+
.yarn-integrity
102+
103+
# dotenv environment variables file
104+
.env
105+
106+
107+
### Windows ###
108+
# Windows thumbnail cache files
109+
Thumbs.db
110+
ehthumbs.db
111+
ehthumbs_vista.db
112+
113+
# Folder config file
114+
Desktop.ini
115+
116+
# Recycle Bin used on file shares
117+
$RECYCLE.BIN/
118+
119+
# Windows Installer files
120+
*.cab
121+
*.msi
122+
*.msm
123+
*.msp
124+
125+
# Windows shortcuts
126+
*.lnk
127+
128+
# End of https://www.gitignore.io/api/macos,windows,linux,node

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
language: node_js
2+
node_js:
3+
- 8
4+
cache:
5+
directories:
6+
- node_modules
7+
branches:
8+
only:
9+
- master
10+
- /^greenkeeper.*$/
11+
git:
12+
depth: 3
13+
before_install:
14+
- npm install -g greenkeeper-lockfile@1
15+
before_script:
16+
- npm prune
17+
- greenkeeper-lockfile-update
18+
script:
19+
- npm run test
20+
after_script:
21+
- greenkeeper-lockfile-upload
22+
after_success:
23+
- if [ -n "${CODECOV_TOKEN:-}" ]; then npm run codecov; fi
24+
- npm run semantic-release

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Pierre-Denis Vanduynslager
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# **sr-commit-analyzer**
2+
3+
Customizable commit-analyzer plugin for [semantic-release](https://github.com/semantic-release/semantic-release) based on [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)
4+
5+
[![npm](https://img.shields.io/npm/v/sr-commit-analyzer.svg)](https://www.npmjs.com/package/sr-commit-analyzer)
6+
[![npm](https://img.shields.io/npm/dt/sr-commit-analyzer.svg)](https://www.npmjs.com/package/sr-commit-analyzer)
7+
[![Greenkeeper badge](https://badges.greenkeeper.io/vanduynslagerp/sr-commit-analyzer.svg)](https://greenkeeper.io/)
8+
[![license](https://img.shields.io/github/license/vanduynslagerp/sr-commit-analyzer.svg)](https://github.com/vanduynslagerp/sr-commit-analyzer/blob/master/LICENSE)
9+
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
10+
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
11+
12+
[![Travis](https://img.shields.io/travis/vanduynslagerp/sr-commit-analyzer.svg)](https://travis-ci.org/vanduynslagerp/sr-commit-analyzer)
13+
[![Code Climate](https://img.shields.io/codeclimate/github/vanduynslagerp/karma-postcss-preprocessor.svg)](https://codeclimate.com/github/vanduynslagerp/karma-postcss-preprocessor)
14+
[![Codecov](https://img.shields.io/codecov/c/github/vanduynslagerp/sr-commit-analyzer.svg)](https://codecov.io/gh/vanduynslagerp/sr-commit-analyzer)
15+
16+
## Install
17+
```bash
18+
npm install --save-dev semantic-release sr-commit-analyzer
19+
```
20+
21+
Set the `analyzeCommits` plugin for `semantic-release` in `package.json`. See [semantic-release plugins](https://github.com/semantic-release/semantic-release#plugins).
22+
```json
23+
{
24+
"release": {
25+
"analyzeCommits": "sr-commit-analyzer"
26+
}
27+
}
28+
```
29+
30+
## Options
31+
32+
By default `sr-commit-analyzer` uses the `angular` format described in [Angular convention](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/convention.md).
33+
34+
Additionnal options can be set within the plugin definition in `package.json` to use a different commit format and to customize it:
35+
36+
```json
37+
{
38+
"release": {
39+
"analyzeCommits": {
40+
"path": "sr-commit-analyzer",
41+
"preset": "angular",
42+
"commitTypes": [
43+
{"type": "docs", "scope":"README", "release": "patch"},
44+
{"type": "refactor", "release": "patch"},
45+
{"type": "style", "release": "patch"}
46+
],
47+
"parserOpts": {
48+
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"]
49+
}
50+
}
51+
}
52+
}
53+
```
54+
55+
| Option | Description | Default |
56+
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- |
57+
| `preset` | [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset (possible values: `angular`, `atom`, `codemirror`, `ember`, `eslint`, `express`, `jquery`, `jscs`, `jshint`). | `angular` |
58+
| `config` | NPM package name of a custom [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) preset. | - |
59+
| `commitTypes` | An external module, a path to a module or an `Array` of rules. See [Commit types](#commit-types). | See [Commit types](#commit-types) |
60+
| `parserOpts` | Additional [conventional-commits-parser](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#conventionalcommitsparseroptions) options that will extends ones loaded by `preset` or `config`. See [Parser options](#parser-options). | - |
61+
62+
**NOTE:** `config` will be overwritten by the values of `preset`. You should use either `preset` or `config`, but not both. Individual properties of `parserOpts` will overwrite ones loaded with `preset` or `config`.
63+
64+
### Commit Types
65+
66+
#### Rules definition
67+
This is an `Array` of rule objects. A rule object has a `release` property and 1 or more criteria.
68+
```json
69+
{
70+
"release": {
71+
"analyzeCommits": {
72+
"preset": "angular",
73+
"commitTypes": [
74+
{"type": "docs", "scope": "README", "release": "patch"},
75+
{"type": "refactor", "scope": "/core-.*/", "release": "minor"},
76+
{"type": "refactor", "release": "patch"}
77+
]
78+
}
79+
}
80+
}
81+
```
82+
#### Rules matching
83+
84+
Each commit will be compared with each rule and when it matches, the commit will be associated with the release type in the rule's `release` property. If a commit match multiple rules, the highest release type (`major` > `minor` > `patch`) is associated with the commit.
85+
86+
See [release types](lib/default/release-types.js) for the release types hierarchy.
87+
88+
With the previous example:
89+
* Commits with `type` 'docs' and `scope` 'README' will be associated with a `patch` release.
90+
* Commits with `type` 'refactor' and `scope` starting with 'core-' (i.e. 'core-ui', 'core-rules', ...) will be associated with a `minor` release.
91+
* Other commits with `type` 'refactor' (without `scope` or with a `scope` not matching the regexp `/core-.*/`) will be associated with a `patch` release.
92+
93+
#### Default rules matching
94+
95+
If a commit doesn't match any rule in `commitTypes` it will be evaluated agaisnt the [default commit types](lib/default/commit-types.js).
96+
97+
With the previous example:
98+
* Commits with a breaking change will be associated with a `minor` release.
99+
* Commits with `type` 'feat' will be associated with a `minor` release.
100+
* Commits with `type` 'fix' will be associated with a `patch` release.
101+
* Commits with `type` 'perf' will be associated with a `patch` release.
102+
103+
#### No rules matching
104+
105+
If a commit doesn't match any rules in `commitTypes` or in [default commit types](lib/default/commit-types.js) then no release type will be associated with the commit.
106+
107+
With the previous example:
108+
* Commits with `type` 'style' will not be associated with a release type.
109+
* Commits with `type` 'test' will not be associated with a release type.
110+
* Commits with `type` 'chore' will not be associated with a release type.
111+
112+
#### Multiple commits
113+
114+
If there is multiple commits that match one or more rules, the one with the highest realease type will determine the global release type.
115+
116+
Considering the following commits:
117+
* `docs(README): Add more details to the API docs`
118+
* `feat(API): Add a new method to the public API`
119+
120+
With the previous example the release type determine by the plugin will be `minor`.
121+
122+
#### Specific commit properties
123+
124+
The properties to set in the rules will depends on the commit style choosen. For example [conventional-changelog-angular](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/index.js#L9-L13) use the commit properties `type`, `scope` and `subject` but [conventional-changelog-eslint](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-eslint/index.js#L9-L12) uses `tag` and `message`.
125+
126+
For example with `eslint` preset:
127+
```json
128+
{
129+
"release": {
130+
"analyzeCommits": {
131+
"preset": "eslint",
132+
"commitTypes": [
133+
{"tag": "Docs", "message":"/README/", "release": "patch"},
134+
{"type": "New", "release": "patch"}
135+
]
136+
}
137+
}
138+
}
139+
```
140+
With this configuration:
141+
* Commits with `tag` 'Docs', that contains 'README' in their header message will be associated with a `patch` release.
142+
* Commits with `tag` 'New' will be associated with a `patch` release.
143+
* Commits with `tag` 'Breaking' will be associated with a `major` release (per [default commit types](lib/default/commit-types.js)).
144+
* Commits with `tag` 'Fix' will be associated with a `patch` release (per [default commit types](lib/default/commit-types.js)).
145+
* Commits with `tag` 'Update' will be associated with a `minor` release (per [default commit types](lib/default/commit-types.js)).
146+
* Commits with `tag` 'New' will be associated with a `minor` release (per [default commit types](lib/default/commit-types.js)).
147+
* All other commits will not be associated with a release type.
148+
149+
#### External package / file
150+
151+
`commitTypes` can also reference a module, either by it's `npm` name or path:
152+
```json
153+
{
154+
"release": {
155+
"analyzeCommits": {
156+
"path": "sr-commit-analyzer",
157+
"preset": "angular",
158+
"commitTypes": "config/commit-types.js"
159+
}
160+
}
161+
}
162+
```
163+
```js
164+
// File: config/commit-types.js
165+
module.exports = [
166+
{type: 'docs', scope: 'README', release: 'patch'},
167+
{type: 'refactor', scope: /core-.*/, release: 'minor'},
168+
{type: 'refactor', release: 'patch'},
169+
];
170+
```
171+
172+
### Parser Options
173+
174+
Allow to overwrite specific [conventional-commits-parser](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#conventionalcommitsparseroptions) options. This is convenient to use a [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) with some customizations without having to create a new module.
175+
176+
The following example uses [Angular convention](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/convention.md) but will consider a commit to be a breaking change if it's body contains `BREAKING CHANGE`, `BREAKING CHANGES` or `BREAKING`. By default the [preset](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/index.js#L14) checks only for `BREAKING CHANGE` and `BREAKING CHANGES`.
177+
```json
178+
{
179+
"release": {
180+
"analyzeCommits": {
181+
"preset": "angular",
182+
"parserOpts": {
183+
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"],
184+
}
185+
}
186+
}
187+
}
188+
```

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {extends: ['@commitlint/config-angular']};

0 commit comments

Comments
 (0)