feat(plugins): add getLastRelease hook
The code to determine the last-release is now in its own repository: https://github.com/semantic-release/last-release-npm One can overwrite that behavior by defining a "getLastRelease" plugin. This way one can decouple semantic-release from npm, e.g. by implementing a git-tag based version. This is already worked on: https://github.com/semantic-release/last-release-git-tag Closes #56
This commit is contained in:
committed by
Stephan Bönnemann
parent
77349fcdf1
commit
7ceac76689
@@ -1,26 +0,0 @@
|
||||
const SemanticReleaseError = require('@semantic-release/error')
|
||||
|
||||
const npmlog = require('npmlog')
|
||||
const RegClient = require('npm-registry-client')
|
||||
|
||||
module.exports = function ({pkg, npm}, cb) {
|
||||
npmlog.level = npm.loglevel || 'error'
|
||||
const client = new RegClient({log: npmlog})
|
||||
|
||||
client.get(`${npm.registry}${pkg.name.replace('/', '%2F')}`, {
|
||||
auth: npm.auth
|
||||
}, (err, data) => {
|
||||
if (err && err.statusCode === 404) return cb(null, {})
|
||||
if (err) return cb(err)
|
||||
|
||||
const version = data['dist-tags'][npm.tag]
|
||||
|
||||
if (!version) return cb(new SemanticReleaseError(`There is no release with the dist-tag "${npm.tag}" yet. Tag a version first.`, 'ENODISTTAG'))
|
||||
|
||||
cb(null, {
|
||||
version,
|
||||
gitHead: data.versions[version].gitHead,
|
||||
tag: npm.tag
|
||||
})
|
||||
})
|
||||
}
|
||||
+2
-1
@@ -5,7 +5,8 @@ let exports = module.exports = function (options) {
|
||||
analyzeCommits: exports.normalize(options.analyzeCommits, '@semantic-release/commit-analyzer'),
|
||||
generateNotes: exports.normalize(options.generateNotes, '@semantic-release/release-notes-generator'),
|
||||
verifyConditions: exports.normalize(options.verifyConditions, '@semantic-release/condition-travis'),
|
||||
verifyRelease: exports.normalize(options.verifyRelease, './plugin-noop')
|
||||
verifyRelease: exports.normalize(options.verifyRelease, './plugin-noop'),
|
||||
getLastRelease: exports.normalize(options.getLastRelease, '@semantic-release/last-release-npm')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -2,14 +2,14 @@ const _ = require('lodash')
|
||||
const auto = require('run-auto')
|
||||
const semver = require('semver')
|
||||
|
||||
const getLastRelease = require('./lib/last-release')
|
||||
const getCommits = require('./lib/commits')
|
||||
const getType = require('./lib/type')
|
||||
|
||||
module.exports = function (config, cb) {
|
||||
const {plugins} = config
|
||||
const { plugins } = config
|
||||
|
||||
auto({
|
||||
lastRelease: getLastRelease.bind(null, config),
|
||||
lastRelease: plugins.getLastRelease.bind(null, config),
|
||||
commits: ['lastRelease', (cb, results) => {
|
||||
getCommits(_.assign({
|
||||
lastRelease: results.lastRelease
|
||||
|
||||
Reference in New Issue
Block a user