From 127cb673bdc5bb4d32065991e1328908d534dc07 Mon Sep 17 00:00:00 2001 From: Christoph Witzko Date: Tue, 12 May 2015 09:27:35 +0200 Subject: [PATCH] feat(pre): verification hook --- src/pre.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/pre.js b/src/pre.js index 12872f01..e5d8f489 100644 --- a/src/pre.js +++ b/src/pre.js @@ -20,10 +20,30 @@ module.exports = function (options, plugins, cb) { var type = analyzer(commits) if (!type) return cb(null, null) - pkg.version = res.version ? semver.inc(res.version, type) : '1.0.0' - if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2)) - cb(null, pkg.version) + pkg.version = res.version ? semver.inc(res.version, type) : '1.0.0' + + var writePkg = function () { + if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2)) + cb(null, pkg.version) + } + + if (type === 'major' || !plugins.verification) return writePkg() + var opts = {} + + if (typeof plugins.verification === 'string') { + opts.name = plugins.verification + } + if (typeof plugins.verification === 'object') { + opts = plugins.verification + } + + var verification = require(opts.name) + + verification(opts, efh(cb)(function (ok) { + if (ok) return writePkg() + cb('verification failed') + })) })) })) }