- Add a new plugin type: `publish` - Add support for multi-plugin. A plugin module can now return an object with a property for each plugin type - Uses by default [npm](https://github.com/semantic-release/npm) and [github](https://github.com/semantic-release/github) in addition of Travis for the verify condition plugin - Uses by default [npm](https://github.com/semantic-release/npm) and [github](https://github.com/semantic-release/github) for the publish plugin - `gitTag` if one can be found is passed to `generateNotes` for both `lastRelease` and `nextRelease` - `semantic-release` now verifies the plugin configuration (in the `release` property of `package.json`) and throws an error if it's invalid - `semantic-release` now verifies each plugin output and will throw an error if a plugin returns an unexpected value. BREAKING CHANGE: `githubToken`, `githubUrl` and `githubApiPathPrefix` have to be set at the [github](https://github.com/semantic-release/github) plugin level. They can be set via `GH_TOKEN`, `GH_URL` and `GH_PREFIX` environment variables. BREAKING CHANGE: the `npm` parameter is not passed to any plugin anymore. Each plugin have to read `.npmrc` if they needs to (with https://github.com/kevva/npm-conf for example).
35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
const {promisify, inspect} = require('util');
|
|
const {isString, isObject, isFunction, noop, cloneDeep} = require('lodash');
|
|
const importFrom = require('import-from');
|
|
|
|
module.exports = (pluginType, pluginConfig, logger, validator) => {
|
|
if (!pluginConfig) {
|
|
return noop;
|
|
}
|
|
const {path, ...config} = isString(pluginConfig) || isFunction(pluginConfig) ? {path: pluginConfig} : pluginConfig;
|
|
if (!isFunction(pluginConfig)) {
|
|
logger.log('Load plugin %s', path);
|
|
}
|
|
const plugin = isFunction(path) ? path : importFrom.silent(__dirname, path) || importFrom(process.cwd(), path);
|
|
|
|
let func;
|
|
if (isFunction(plugin)) {
|
|
func = promisify(plugin.bind(null, cloneDeep(config)));
|
|
} else if (isObject(plugin) && plugin[pluginType] && isFunction(plugin[pluginType])) {
|
|
func = promisify(plugin[pluginType].bind(null, cloneDeep(config)));
|
|
} else {
|
|
throw new Error(
|
|
`The ${pluginType} plugin must be a function, or an object with a function in the property ${pluginType}.`
|
|
);
|
|
}
|
|
|
|
return async input => {
|
|
const result = await func(cloneDeep(input));
|
|
|
|
if (validator && !validator.validator(result)) {
|
|
throw new Error(`${validator.message}. Received: ${inspect(result)}`);
|
|
}
|
|
return result;
|
|
};
|
|
};
|