refator: use error-first-handler

This commit is contained in:
Stephan Bönnemann
2015-02-03 20:45:03 +01:00
parent 19fd15c1dc
commit 019aeeabe1
8 changed files with 51 additions and 55 deletions
+5 -7
View File
@@ -6,21 +6,19 @@ var semver = require('semver')
var type = require('../lib/type')
var version = require('../lib/version')
var efh = require('../lib/error').efh
module.exports = function (options, cb) {
type(function (err, type) {
if (err) return cb(err)
type(efh(cb)(function (type) {
if (!type) return cb(null, null)
var path = './package.json'
var pkg = JSON.parse(fs.readFileSync(path))
version(pkg, function (err, version, unpublished) {
if (err) return cb(err)
version(pkg, efh(cb)(function (version, unpublished) {
pkg.version = unpublished ? '1.0.0' : semver.inc(version, type)
if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2))
cb(null, pkg.version)
})
})
}))
}))
}