feat(plugins): normalize plugins and have unified function signature
This commit is contained in:
+2
-1
@@ -1,6 +1,7 @@
|
||||
module.exports = class SemanticReleaseError extends Error {
|
||||
constructor (message, code) {
|
||||
super(message)
|
||||
super()
|
||||
this.message = message
|
||||
this.code = code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
/* istanbul ignore next */
|
||||
module.exports = function (options, release, cb) {
|
||||
cb(null)
|
||||
}
|
||||
@@ -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
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user