feat(plugins): normalize plugins and have unified function signature

This commit is contained in:
Stephan Bönnemann
2015-06-18 16:48:28 -07:00
parent da23c15ea5
commit 057e8e9759
7 changed files with 50 additions and 26 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
module.exports = class SemanticReleaseError extends Error {
constructor (message, code) {
super(message)
super()
this.message = message
this.code = code
}
}
+4
View File
@@ -0,0 +1,4 @@
/* istanbul ignore next */
module.exports = function (options, release, cb) {
cb(null)
}
+17
View File
@@ -0,0 +1,17 @@
let exports = module.exports = function (source) {
return {
analyze: exports.normalize(source.analyze, '@semantic-release/commit-analyzer'),
generateNotes: exports.normalize(source.analyze, '@semantic-release/release-notes-generator'),
verify: exports.normalize(source.verify, './plugin-noop')
}
}
exports.normalize = function (plugin, fallback) {
if (typeof plugin === 'string') return require(plugin).bind(null, {})
if (plugin && (typeof plugin.path === 'string')) {
return require(plugin.path).bind(null, plugin)
}
return require(fallback).bind(null, plugin)
}
+11 -9
View File
@@ -1,16 +1,18 @@
const SemanticReleaseError = require('./error')
module.exports = function (plugins, commits, lastRelease, cb) {
const type = plugins.analyze(commits)
plugins.analyze(commits, (err, type) => {
if (err) return cb(err)
if (!type) {
return cb(new SemanticReleaseError(
'There are no relevant changes, so no new version is released',
'ENOCHANGE'
))
}
if (!type) {
return cb(new SemanticReleaseError(
'There are no relevant changes, so no new version is released',
'ENOCHANGE'
))
}
if (!lastRelease.version) return cb(null, 'initial')
if (!lastRelease.version) return cb(null, 'initial')
cb(null, type)
cb(null, type)
})
}