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

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;
};