chore(package): re-init package with commitizen and standard-release

This commit is contained in:
Pavel Pertsev
2018-05-16 12:54:46 +03:00
parent cb4e7a5643
commit eaf2328575
10640 changed files with 609660 additions and 117 deletions

19
node_modules/validate-commit-msg/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,19 @@
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

243
node_modules/validate-commit-msg/README.md generated vendored Normal file
View File

@@ -0,0 +1,243 @@
# validate-commit-msg
[![Build Status][build-badge]][build]
[![Code Coverage][coverage-badge]][coverage]
[![Dependencies][dependencyci-badge]][dependencyci]
[![version][version-badge]][package]
[![downloads][downloads-badge]][npm-stat]
[![MIT License][license-badge]][LICENSE]
[![All Contributors](https://img.shields.io/badge/all_contributors-28-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Donate][donate-badge]][donate]
[![Code of Conduct][coc-badge]][coc]
[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
[![Tweet][twitter-badge]][twitter]
This provides you a binary that you can use as a githook to validate the commit message. I recommend
[husky](http://npm.im/husky). You'll want to make this part of the `commit-msg` githook, e.g. when using [husky](http://npm.im/husky), add `"commitmsg": "validate-commit-msg"` to your [npm scripts](https://docs.npmjs.com/misc/scripts) in `package.json`.
Validates that your commit message follows this format:
```
<type>(<scope>): <subject>
```
Or without optional scope:
```
<type>: <subject>
```
## Installation
This module is distributed via [npm](https://www.npmjs.com/) which is bundled with [node](https://nodejs.org/) and
should be installed as one of your project's `devDependencies`:
```
npm install --save-dev validate-commit-msg
```
## Usage
### options
You can specify options in `.vcmrc`.
It must be valid JSON file.
The default configuration object is:
```json
{
"types": ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"],
"scope": {
"required": false,
"allowed": ["*"],
"validate": false,
"multiple": false
},
"warnOnFail": false,
"maxSubjectLength": 100,
"subjectPattern": ".+",
"subjectPatternErrorMsg": "subject does not match subject pattern!",
"helpMessage": "",
"autoFix": false
}
```
Alternatively, options can be specified in `package.json`:
```json
{
"config": {
"validate-commit-msg": {
/* your config here */
}
}
}
```
`.vcmrc` has precedence, if it does not exist, then `package.json` will be used.
#### types
These are the types that are allowed for your commit message. If omitted, the value is what is shown above.
You can also specify: `"types": "*"` to indicate that you don't wish to validate types.
Or you can specify the name of a module that exports types according to the
[conventional-commit-types](https://github.com/commitizen/conventional-commit-types)
spec, e.g. `"types": "conventional-commit-types"`.
#### scope
This object defines scope requirements for the commit message. Possible properties are:
##### required
A boolean to define whether a scope is required for all commit messages.
##### allowed
An array of scopes that are allowed for your commit message.
You may also define it as `"*"` which is the default to allow any scope names.
##### validate
A boolean to define whether or not to validate the scope(s) provided.
##### multiple
A boolean to define whether or not to allow multiple scopes.
#### warnOnFail
If this is set to `true` errors will be logged to the console, however the commit will still pass.
#### maxSubjectLength
This will control the maximum length of the subject.
#### subjectPattern
Optional, accepts a RegExp to match the commit message subject against.
#### subjectPatternErrorMsg
If `subjectPattern` is provided, this message will be displayed if the commit message subject does not match the pattern.
#### helpMessage
If provided, the helpMessage string is displayed when a commit message is not valid. This allows projects to provide a better developer experience for new contributors.
The `helpMessage` also supports interpolating a single `%s` with the original commit message.
#### autoFix
If this is set to `true`, type will be auto fixed to all lowercase, subject first letter will be lowercased, and the commit will pass (assuming there's nothing else wrong with it).
### Node
Through node you can use as follows
```javascript
var validateMessage = require('validate-commit-msg');
var valid = validateMessage('chore(index): an example commit message');
// valid = true
```
### CI
You can use your CI to validate your _last_ commit message:
```
validate-commit-msg "$(git log -1 --pretty=%B)"
```
_Note_ this will only validate the last commit message, not all messages in a pull request.
### Monorepo
If your lerna repo looks something like this:
```
my-lerna-repo/
package.json
packages/
package-1/
package.json
package-2/
package.json
```
The scope of your commit message should be one (or more) of the packages:
EG:
```json
{
"config": {
"validate-commit-msg": {
"scope": {
"required": true,
"allowed": ["package-1", "package-2"],
"validate": true,
"multiple": true
},
}
}
}
```
### Other notes
If the commit message begins with `WIP` then none of the validation will happen.
## Credits
This was originally developed by contributors to [the angular.js project](https://github.com/angular/angular.js). I
pulled it out so I could re-use this same kind of thing in other projects.
[build-badge]: https://img.shields.io/travis/kentcdodds/validate-commit-msg.svg?style=flat-square
[build]: https://travis-ci.org/kentcdodds/validate-commit-msg
[coverage-badge]: https://img.shields.io/codecov/c/github/kentcdodds/validate-commit-msg.svg?style=flat-square
[coverage]: https://codecov.io/github/kentcdodds/validate-commit-msg
[dependencyci-badge]: https://dependencyci.com/github/kentcdodds/validate-commit-msg/badge?style=flat-square
[dependencyci]: https://dependencyci.com/github/kentcdodds/validate-commit-msg
[version-badge]: https://img.shields.io/npm/v/validate-commit-msg.svg?style=flat-square
[package]: https://www.npmjs.com/package/validate-commit-msg
[downloads-badge]: https://img.shields.io/npm/dm/validate-commit-msg.svg?style=flat-square
[npm-stat]: http://npm-stat.com/charts.html?package=validate-commit-msg&from=2016-04-01
[license-badge]: https://img.shields.io/npm/l/validate-commit-msg.svg?style=flat-square
[license]: https://github.com/kentcdodds/validate-commit-msg/blob/master/LICENSE
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
[prs]: http://makeapullrequest.com
[donate-badge]: https://img.shields.io/badge/$-support-green.svg?style=flat-square
[donate]: http://kcd.im/donate
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
[coc]: https://github.com/kentcdodds/validate-commit-msg/blob/master/CODE_OF_CONDUCT.md
[github-watch-badge]: https://img.shields.io/github/watchers/kentcdodds/validate-commit-msg.svg?style=social
[github-watch]: https://github.com/kentcdodds/validate-commit-msg/watchers
[github-star-badge]: https://img.shields.io/github/stars/kentcdodds/validate-commit-msg.svg?style=social
[github-star]: https://github.com/kentcdodds/validate-commit-msg/stargazers
[twitter]: https://twitter.com/intent/tweet?text=Check%20out%20validate-commit-msg!%20https://github.com/kentcdodds/validate-commit-msg%20%F0%9F%91%8D
[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/kentcdodds/validate-commit-msg.svg?style=social
## Contributors
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />💁 [💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/validate-commit-msg/commits?author=kentcdodds) 👀 [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=kentcdodds) | [<img src="https://avatars.githubusercontent.com/u/13700?v=3" width="100px;"/><br /><sub>Remy Sharp</sub>](http://remysharp.com)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=remy) [📖](https://github.com/kentcdodds/validate-commit-msg/commits?author=remy) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=remy) | [<img src="https://avatars.githubusercontent.com/u/1692136?v=3" width="100px;"/><br /><sub>Cédric Malard</sub>](http://valdun.net)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=cmalard) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=cmalard) | [<img src="https://avatars.githubusercontent.com/u/696693?v=3" width="100px;"/><br /><sub>Mark Dalgleish</sub>](http://markdalgleish.com)<br />[📖](https://github.com/kentcdodds/validate-commit-msg/commits?author=markdalgleish) | [<img src="https://avatars.githubusercontent.com/u/1018189?v=3" width="100px;"/><br /><sub>Ryan Kimber</sub>](https://formhero.io)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=ryan-kimber) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=ryan-kimber) | [<img src="https://avatars.githubusercontent.com/u/43780?v=3" width="100px;"/><br /><sub>Javier Collado</sub>](https://github.com/jcollado)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=jcollado) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=jcollado) | [<img src="https://avatars.githubusercontent.com/u/606014?v=3" width="100px;"/><br /><sub>Jamis Charles</sub>](https://github.com/jamischarles)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=jamischarles) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=jamischarles) |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars.githubusercontent.com/u/2112202?v=3" width="100px;"/><br /><sub>Shawn Erquhart</sub>](http://www.professant.com)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=erquhart) [📖](https://github.com/kentcdodds/validate-commit-msg/commits?author=erquhart) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=erquhart) | [<img src="https://avatars.githubusercontent.com/u/194482?v=3" width="100px;"/><br /><sub>Tushar Mathur</sub>](http://tusharm.com)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=tusharmath) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=tusharmath) | [<img src="https://avatars.githubusercontent.com/u/904007?v=3" width="100px;"/><br /><sub>Jason Dreyzehner</sub>](https://twitter.com/bitjson)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=bitjson) [📖](https://github.com/kentcdodds/validate-commit-msg/commits?author=bitjson) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=bitjson) | [<img src="https://avatars.githubusercontent.com/u/9654923?v=3" width="100px;"/><br /><sub>Abimbola Idowu</sub>](http://twitter.com/hisabimbola)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=hisabimbola) | [<img src="https://avatars.githubusercontent.com/u/2212006?v=3" width="100px;"/><br /><sub>Gleb Bahmutov</sub>](https://glebbahmutov.com/)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=bahmutov) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=bahmutov) | [<img src="https://avatars.githubusercontent.com/u/332905?v=3" width="100px;"/><br /><sub>Dennis</sub>](http://dennis.io)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=ds82) | [<img src="https://avatars.githubusercontent.com/u/6425649?v=3" width="100px;"/><br /><sub>Matt Lewis</sub>](https://mattlewis.me/)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=mattlewis92) |
| [<img src="https://avatars.githubusercontent.com/u/323761?v=3" width="100px;"/><br /><sub>Tom Vincent</sub>](https://tlvince.com)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=tlvince) | [<img src="https://avatars.githubusercontent.com/u/615381?v=3" width="100px;"/><br /><sub>Anders D. Johnson</sub>](https://andrz.me/)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=AndersDJohnson) [📖](https://github.com/kentcdodds/validate-commit-msg/commits?author=AndersDJohnson) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=AndersDJohnson) | [<img src="https://avatars.githubusercontent.com/u/1643758?v=3" width="100px;"/><br /><sub>James Zetlen</sub>](http://jameszetlen.com)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=zetlen) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=zetlen) | [<img src="https://avatars.githubusercontent.com/u/235784?v=3" width="100px;"/><br /><sub>Paul Bienkowski</sub>](http://opatut.de)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=opatut) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=opatut) | [<img src="https://avatars.githubusercontent.com/u/324073?v=3" width="100px;"/><br /><sub>Barney Scott</sub>](https://github.com/bmds)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=bmds) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=bmds) | [<img src="https://avatars.githubusercontent.com/u/5572221?v=3" width="100px;"/><br /><sub>Emmanuel Murillo Sánchez</sub>](https://github.com/Emmurillo)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=Emmurillo) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=Emmurillo) | [<img src="https://avatars.githubusercontent.com/u/968267?v=3" width="100px;"/><br /><sub>Hans Kristian Flaatten</sub>](https://starefossen.github.io)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=Starefossen) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=Starefossen) |
| [<img src="https://avatars.githubusercontent.com/u/16605186?v=3" width="100px;"/><br /><sub>Bo Lingen</sub>](https://github.com/citycide)<br />[📖](https://github.com/kentcdodds/validate-commit-msg/commits?author=citycide) | [<img src="https://avatars.githubusercontent.com/u/1057324?v=3" width="100px;"/><br /><sub>Spyros Ioakeimidis</sub>](http://www.spyros.io)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=spirosikmd) [📖](https://github.com/kentcdodds/validate-commit-msg/commits?author=spirosikmd) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=spirosikmd) | [<img src="https://avatars.githubusercontent.com/u/126441?v=3" width="100px;"/><br /><sub>Matt Travi</sub>](https://matt.travi.org)<br />[🐛](https://github.com/kentcdodds/validate-commit-msg/issues?q=author%3Atravi) | [<img src="https://avatars.githubusercontent.com/u/868301?v=3" width="100px;"/><br /><sub>Jonathan Garbee</sub>](http://jonathan.garbee.me)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=Garbee) [📖](https://github.com/kentcdodds/validate-commit-msg/commits?author=Garbee) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=Garbee) | [<img src="https://avatars.githubusercontent.com/u/2978876?v=3" width="100px;"/><br /><sub>Tobias Lins</sub>](https://lins.in)<br />[📖](https://github.com/kentcdodds/validate-commit-msg/commits?author=tobiaslins) | [<img src="https://avatars1.githubusercontent.com/u/680356?v=3" width="100px;"/><br /><sub>Max Claus Nunes</sub>](http://maxcnunes.com/)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=maxcnunes) | [<img src="https://avatars3.githubusercontent.com/u/750319?v=3" width="100px;"/><br /><sub>standy</sub>](https://github.com/standy)<br />[💻](https://github.com/kentcdodds/validate-commit-msg/commits?author=standy) [⚠️](https://github.com/kentcdodds/validate-commit-msg/commits?author=standy) |
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

3
node_modules/validate-commit-msg/index.js generated vendored Executable file
View File

@@ -0,0 +1,3 @@
'use strict';
module.exports = require('./lib/validateMessage').validateMessage;

102
node_modules/validate-commit-msg/lib/cli.js generated vendored Executable file
View File

@@ -0,0 +1,102 @@
#!/usr/bin/env node
/**
* Git COMMIT-MSG hook for validating commit message
* See https://docs.google.com/document/d/1rk04jEuGfk9kYzfqCuOlPTSJw3hEDZJTBN5E5f1SALo/edit
*
* This CLI supports 3 usage ways:
* 1. Default usage is not passing any argument. It will automatically read from COMMIT_EDITMSG file.
* 2. Passing a file name argument from git directory. For instance GIT GUI stores commit msg @GITGUI_EDITMSG file.
* 3. Passing commit message as argument. Useful for testing quickly a commit message from CLI.
*
* Installation:
* >> cd <angular-repo>
* >> ln -s ../../validate-commit-msg.js .git/hooks/commit-msg
*/
'use strict';
var fs = require('fs');
var getGitFolder = require('./getGitFolder');
var validateMessage = require('../index');
// hacky start if not run by mocha :-D
// istanbul ignore next
if (process.argv.join('').indexOf('mocha') === -1) {
var bufferToString = function (buffer) {
var hasToString = buffer && typeof buffer.toString === 'function';
return hasToString && buffer.toString();
};
var getFileContent = function (filePath) {
try {
var buffer = fs.readFileSync(filePath);
return bufferToString(buffer);
} catch (err) {
// Ignore these error types because is most likely it is validating
// a commit from a text instead of a file
if(err && err.code !== 'ENOENT' && err.code !== 'ENAMETOOLONG') {
throw err;
}
}
};
var getCommit = function() {
var file;
var fileContent;
var gitDirectory;
var commitMsgFileOrText = process.argv[2];
var commitErrorLogPath = process.argv[3];
var commit = {
// if it is running from git directory or for a file from there
// these info might change ahead
message: commitMsgFileOrText,
errorLog: commitErrorLogPath || null,
file: null,
};
// On running the validation over a text instead of git files such as COMMIT_EDITMSG and GITGUI_EDITMSG
// is possible to be doing that the from anywhere. Therefore the git directory might not be available.
try {
gitDirectory = getGitFolder();
// Try to load commit from a path passed as argument
if (commitMsgFileOrText) {
file = gitDirectory + '/' + commitMsgFileOrText;
fileContent = getFileContent(file);
}
// If no file or message is available then try to load it from the default commit file
if (!fileContent && !commitMsgFileOrText) {
file = gitDirectory + '/COMMIT_EDITMSG';
fileContent = getFileContent(file);
}
// Could resolve the content from a file
if (fileContent) {
commit.file = file;
commit.message = fileContent;
}
// Default error log path
if (!commit.errorLog) {
commit.errorLog = gitDirectory + '/logs/incorrect-commit-msgs';
}
} catch (err) {}
return commit;
};
var validate = function (commit) {
if (!validateMessage(commit.message, commit.file) && commit.errorLog) {
fs.appendFileSync(commit.errorLog, commit.message + '\n');
process.exit(1);
} else {
process.exit(0);
}
};
validate(getCommit());
}

34
node_modules/validate-commit-msg/lib/config.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
'use strict';
var findup = require('findup');
var fs = require('fs');
var resolve = require('path').resolve;
function getConfigObject(filename) {
try {
var rcFile = findup.sync(process.cwd(), filename);
return JSON.parse(fs.readFileSync(resolve(rcFile, filename)));
} catch (e) {
return null;
}
}
function getRcConfig() {
return getConfigObject('.vcmrc');
}
function getPackageConfig() {
var configObject = getConfigObject('package.json');
return configObject && configObject.config && configObject.config['validate-commit-msg'];
}
function getConfig() {
return getRcConfig() || getPackageConfig() || {};
}
module.exports = {
getConfig: getConfig,
getRcConfig: getRcConfig,
getPackageConfig: getPackageConfig,
getConfigObject: getConfigObject
};

29
node_modules/validate-commit-msg/lib/getGitFolder.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
'use strict';
var fs = require('fs');
var path = require('path');
var findParentDir = require('find-parent-dir');
module.exports = function getGitFolder() {
var dir = findParentDir.sync(process.cwd(), '.git');
if (!dir) throw new Error('Cannot find .git folder');
var gitDir = path.join(dir, '.git');
var stats = fs.lstatSync(gitDir);
if (!stats.isDirectory()) {
// Expect following format
// git: pathToGit
var pathToGit = fs
.readFileSync(gitDir, 'utf-8')
.split(':')[1]
.trim();
gitDir = path.join(dir, pathToGit);
if (!fs.existsSync(gitDir)) {
throw new Error('Cannot find file ' + pathToGit);
}
}
return gitDir;
};

188
node_modules/validate-commit-msg/lib/validateMessage.js generated vendored Normal file
View File

@@ -0,0 +1,188 @@
'use strict';
var fs = require('fs');
var semverRegex = require('semver-regex');
var util = require('util');
var getConfig = require('./config').getConfig;
var config = getConfig();
var MAX_LENGTH = config.maxSubjectLength || 100;
var IGNORED = new RegExp(util.format('(^WIP)|(^%s$)', semverRegex().source));
// fixup! and squash! are part of Git, commits tagged with them are not intended to be merged, cf. https://git-scm.com/docs/git-commit
var PATTERN = /^((fixup! |squash! )?(\w+)(?:\(([^\)\s]+)\))?: (.+))(?:\n|$)/;
var MERGE_COMMIT_PATTERN = /^Merge /;
var error = function() {
// gitx does not display it
// http://gitx.lighthouseapp.com/projects/17830/tickets/294-feature-display-hook-error-message-when-hook-fails
// https://groups.google.com/group/gitx/browse_thread/thread/a03bcab60844b812
console[config.warnOnFail ? 'warn' : 'error']('INVALID COMMIT MSG: ' + util.format.apply(null, arguments));
};
exports.config = config;
exports.validateMessage = function validateMessage(raw, sourceFile) {
var types = config.types = config.types || 'conventional-commit-types';
var AUTO_FIX = config.autoFix && sourceFile;
// resolve types from a module
if (typeof types === 'string' && types !== '*') {
types = Object.keys(require(types).types);
}
var messageWithBody = (raw || '').split('\n').filter(function(str) {
return str.indexOf('#') !== 0;
}).join('\n');
var message = messageWithBody.split('\n').shift();
if (message === '') {
console.log('Aborting commit due to empty commit message.');
return false;
}
var isValid = true;
if (MERGE_COMMIT_PATTERN.test(message)) {
console.log('Merge commit detected.');
return true
}
if (IGNORED.test(message)) {
console.log('Commit message validation ignored.');
return true;
}
var match = PATTERN.exec(message);
if (!match) {
error('does not match "<type>(<scope>): <subject>" !');
isValid = false;
} else {
var firstLine = match[1];
var squashing = !!match[2];
var type = match[3];
var scope = match[4];
var subject = match[5];
var SUBJECT_PATTERN = new RegExp(config.subjectPattern || '.+');
var SUBJECT_PATTERN_ERROR_MSG = config.subjectPatternErrorMsg || 'subject does not match subject pattern!';
if (firstLine.length > MAX_LENGTH && !squashing) {
error('is longer than %d characters !', MAX_LENGTH);
isValid = false;
}
if (AUTO_FIX) {
type = lowercase(type);
}
if (types !== '*' && types.indexOf(type) === -1) {
error('"%s" is not allowed type ! Valid types are: %s', type, types.join(', '));
isValid = false;
}
isValid = validateScope(isValid, scope);
if (AUTO_FIX) {
subject = lowercaseFirstLetter(subject);
}
if (!SUBJECT_PATTERN.exec(subject)) {
error(SUBJECT_PATTERN_ERROR_MSG);
isValid = false;
}
}
// Some more ideas, do want anything like this ?
// - Validate the rest of the message (body, footer, BREAKING CHANGE annotations)
// - auto add empty line after subject ?
// - auto remove empty () ?
// - auto correct typos in type ?
// - store incorrect messages, so that we can learn
isValid = isValid || config.warnOnFail;
if (isValid) { // exit early and skip messaging logics
if (AUTO_FIX && !squashing) {
var scopeFixed = scope ? '(' + scope + ')' : '';
var firstLineFixed = type + scopeFixed + ': ' + subject;
if (firstLine !== firstLineFixed) {
var rawFixed = raw.replace(firstLine, firstLineFixed);
fs.writeFileSync(sourceFile, rawFixed);
}
}
return true;
}
var argInHelp = config.helpMessage && config.helpMessage.indexOf('%s') !== -1;
if (argInHelp) {
console.log(config.helpMessage, messageWithBody);
} else if (message) {
console.log(message);
}
if (!argInHelp && config.helpMessage) {
console.log(config.helpMessage);
}
return false;
};
function lowercase(string) {
return string.toLowerCase();
}
function lowercaseFirstLetter(string) {
return lowercase(string.charAt(0)) + string.slice(1);
}
function validateScope(isValid, scope) {
config.scope = config.scope || {};
var validateScopes = config.scope.validate || false;
var multipleScopesAllowed = config.scope.multiple || false;
var allowedScopes = config.scope.allowed || '*';
var scopeRequired = config.scope.required || false;
var scopes = scope ? scope.split(',') : [];
function validateIndividualScope(item) {
if (allowedScopes[0].trim() === '*') {
return;
}
if (allowedScopes.indexOf(item) === -1) {
error('"%s" is not an allowed scope ! Valid scope are: %s', item, allowedScopes.join(', '));
isValid = false;
}
}
if (validateScopes) {
if (scopeRequired && scopes.length === 0) {
error('a scope is required !');
isValid = false;
}
// If scope is not provided, we ignore the rest of the testing and do early
// return here.
if (scopes.length === 0) {
return isValid;
}
if (isValid && multipleScopesAllowed) {
scopes.forEach(validateIndividualScope);
}
if (isValid && !multipleScopesAllowed) {
if (scopes.length > 1) {
error('only one scope can be provided !');
isValid = false;
}
if (isValid) {
validateIndividualScope(scopes[0]);
}
}
}
return isValid;
};

View File

@@ -0,0 +1 @@
../../../findup/bin/findup.js

87
node_modules/validate-commit-msg/package.json generated vendored Normal file
View File

@@ -0,0 +1,87 @@
{
"name": "validate-commit-msg",
"description": "Script to validate a commit message follows the conventional changelog standard",
"main": "index.js",
"version": "2.14.0",
"scripts": {
"add-contributor": "all-contributors add",
"generate-contributors": "all-contributors generate",
"commit": "git-cz",
"commitmsg": "opt --in commitmsg --exec \"node ./lib/cli.js\"",
"precommit": "opt --in precommit --exec \"npm run validate\"",
"check-coverage": "istanbul check-coverage --statements 100 --branches 90 --functions 100 --lines 100",
"report-coverage": "cat ./coverage/lcov.info | codecov",
"test:watch": "istanbul cover -x test/**/*.test.js node_modules/mocha/bin/_mocha -- -R spec -w test/**/*.test.js",
"test": "istanbul cover -x test/**/*.test.js node_modules/mocha/bin/_mocha -- -R spec test/**/*.test.js",
"validate": "npm t && npm run check-coverage",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"bin": {
"validate-commit-msg": "./lib/cli.js"
},
"repository": {
"type": "git",
"url": "https://github.com/conventional-changelog/validate-commit-msg.git"
},
"keywords": [
"githook",
"commit",
"message",
"git",
"conventional",
"changelog"
],
"author": "Kent C. Dodds <kent@doddsfamily.us> (http://kentcdodds.com/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/conventional-changelog/validate-commit-msg/issues"
},
"homepage": "https://github.com/conventional-changelog/validate-commit-msg#readme",
"devDependencies": {
"all-contributors-cli": "3.0.7",
"chai": "3.4.1",
"codecov.io": "0.1.6",
"commitizen": "2.5.0",
"cz-conventional-changelog": "1.1.5",
"husky": "0.12.0",
"istanbul": "0.4.2",
"mkdirp": "^0.5.1",
"mocha": "2.3.4",
"opt-cli": "1.5.1",
"rimraf": "^2.6.1",
"semantic-release": "^6.3.2",
"sinon": "1.17.2"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
},
"validate-commit-msg": {
"helpMessage": "\nPlease fix your commit message (and consider using http://npm.im/commitizen)\n",
"types": [
"feat",
"fix",
"docs",
"style",
"refactor",
"perf",
"test",
"chore",
"revert",
"custom"
],
"warnOnFail": false,
"autoFix": true
}
},
"dependencies": {
"conventional-commit-types": "^2.0.0",
"find-parent-dir": "^0.3.0",
"findup": "0.1.5",
"semver-regex": "1.0.0"
},
"files": [
"index.js",
"lib"
]
}