feat: support multiple plugins for the analyzeCommits step

In case multiple plugins with a `analyzeCommits` step are configured, all of them will be executed and the highest release type (`major` > `minor`, `patch`) will be used.
This commit is contained in:
Pierre Vanduynslager
2018-11-12 15:06:46 -05:00
parent 728ea34dda
commit 5180001ae6
9 changed files with 58 additions and 170 deletions
+4 -7
View File
@@ -24,7 +24,7 @@ module.exports = (context, pluginsPath) => {
writable: false,
enumerable: true,
});
plugins[type] = [...(PLUGINS_DEFINITIONS[type].multiple ? plugins[type] || [] : []), [func, config]];
plugins[type] = [...(plugins[type] || []), [func, config]];
}
});
} else {
@@ -45,10 +45,7 @@ module.exports = (context, pluginsPath) => {
options = {...plugins, ...options};
const pluginsConf = Object.entries(PLUGINS_DEFINITIONS).reduce(
(
pluginsConf,
[type, {multiple, required, default: def, pipelineConfig, postprocess = identity, preprocess = identity}]
) => {
(pluginsConf, [type, {required, default: def, pipelineConfig, postprocess = identity, preprocess = identity}]) => {
let pluginOpts;
if (isNil(options[type]) && def) {
@@ -60,8 +57,8 @@ module.exports = (context, pluginsPath) => {
plugin ? [plugin[0], Object.assign(plugin[1], options[type])] : plugin
);
}
if (!validateStep({multiple, required}, options[type])) {
errors.push(getError('EPLUGINCONF', {type, multiple, required, pluginConf: options[type]}));
if (!validateStep({required}, options[type])) {
errors.push(getError('EPLUGINCONF', {type, required, pluginConf: options[type]}));
return pluginsConf;
}
pluginOpts = options[type];
+20 -23
View File
@@ -2,28 +2,25 @@ const {dirname} = require('path');
const {isString, isFunction, castArray, isArray, isPlainObject, isNil} = require('lodash');
const resolveFrom = require('resolve-from');
const validateStepArrayDefinition = conf =>
isArray(conf) &&
(conf.length === 1 || conf.length === 2) &&
(isString(conf[0]) || isFunction(conf[0])) &&
(isNil(conf[1]) || isPlainObject(conf[1]));
const validateSteps = conf => {
return conf.every(conf => {
if (
isArray(conf) &&
(conf.length === 1 || conf.length === 2) &&
(isString(conf[0]) || isFunction(conf[0])) &&
(isNil(conf[1]) || isPlainObject(conf[1]))
) {
return true;
}
conf = castArray(conf);
const validateSingleStep = conf => {
if (validateStepArrayDefinition(conf)) {
return true;
}
conf = castArray(conf);
if (conf.length !== 1) {
return false;
}
if (conf.length !== 1) {
return false;
}
const [name, config] = parseConfig(conf[0]);
return (isString(name) || isFunction(name)) && isPlainObject(config);
};
const validateMultipleStep = conf => {
return conf.every(conf => validateSingleStep(conf));
const [name, config] = parseConfig(conf[0]);
return (isString(name) || isFunction(name)) && isPlainObject(config);
});
};
function validatePlugin(conf) {
@@ -37,12 +34,12 @@ function validatePlugin(conf) {
);
}
function validateStep({multiple, required}, conf) {
function validateStep({required}, conf) {
conf = castArray(conf).filter(Boolean);
if (required) {
return conf.length >= 1 && (multiple ? validateMultipleStep : validateSingleStep)(conf);
return conf.length >= 1 && validateSteps(conf);
}
return conf.length === 0 || (multiple ? validateMultipleStep : validateSingleStep)(conf);
return conf.length === 0 || validateSteps(conf);
}
function loadPlugin({cwd}, name, pluginsPath) {