Compare commits

..
8 Commits
5 changed files with 93 additions and 3 deletions
+4
View File
@@ -21,6 +21,7 @@
"semver": "^4.3.3"
},
"devDependencies": {
"cracks": "^2.0.1",
"github-release-fake-server": "^1.3.0",
"lodash.defaults": "^3.0.0",
"nano-uid": "^0.2.0",
@@ -59,5 +60,8 @@
"test:style": "standard",
"test:integration": "node tests | tap-spec",
"test": "./bin/test"
},
"release": {
"verification": "cracks"
}
}
+38 -3
View File
@@ -20,10 +20,45 @@ 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)
if (res.version) {
pkg.version = semver.inc(res.version, type)
} else {
type = 'major'
pkg.version = '1.0.0'
}
var writePkg = function () {
if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n')
cb(null, pkg.version)
}
if (!plugins.verification) return writePkg()
var opts = {}
if (typeof plugins.verification === 'string') {
opts.path = plugins.verification
}
if (typeof plugins.verification === 'object') {
opts = plugins.verification
opts.path = opts.path || opts.name
}
opts.type = type
opts.commits = commits
opts.version = res.version
opts.nextVersion = pkg.version
var verification = require(opts.path)
console.log('Running verification hook...')
verification(opts, function (error, ok) {
if (!error && ok) return writePkg()
console.log('Verification failed' + (error ? ': ' + error : ''))
process.exit(1)
})
}))
}))
}
+1
View File
@@ -5,6 +5,7 @@ var test = require('tape')
var createModule = require('./lib/create-module')
require('./scenarios/custom-analyzer')(test, createModule)
require('./scenarios/custom-verification')(test, createModule)
require('./scenarios/ignore')(test, createModule)
require('./scenarios/prepublish')(test, createModule)
require('./scenarios/postpublish')(test, createModule)
+5
View File
@@ -0,0 +1,5 @@
'use strict'
module.exports = function (opts, cb) {
cb(null, !(opts.commits.length % 2))
}
+45
View File
@@ -0,0 +1,45 @@
'use strict'
var path = require('path')
var efh = require('error-first-handler')
var nixt = require('nixt')
module.exports = function (test, createModule) {
createModule({
release: {
verification: path.join(__dirname, '../lib/custom-verification')
}
}, efh()(function (name, cwd) {
test('custom-verification', function (t) {
t.test('even commit count', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.env('npm_config_registry', 'http://127.0.0.1:4873/')
.exec('git commit --allow-empty -m "feat: commit"')
.run('npm run prepublish')
.code(0)
.end(function (err) {
t.error(err, 'nixt')
})
})
t.test('odd commit count', function (t) {
t.plan(1)
nixt()
.cwd(cwd)
.env('CI', true)
.env('npm_config_registry', 'http://127.0.0.1:4873/')
.exec('git commit --allow-empty -m "feat: commit"')
.run('npm run prepublish')
.code(1)
.stdout(/Verification failed/)
.end(function (err) {
t.error(err, 'nixt')
})
})
})
}))
}