refator: use error-first-handler
This commit is contained in:
+9
-12
@@ -8,6 +8,8 @@ var GitHubApi = require('github')
|
||||
var parseSlug = require('parse-github-repo-url')
|
||||
var parseUrl = require('github-url-from-git')
|
||||
|
||||
var efh = require('../lib/error').efh
|
||||
|
||||
var github = new GitHubApi({
|
||||
version: '3.0.0'
|
||||
})
|
||||
@@ -16,18 +18,14 @@ module.exports = function (options, cb) {
|
||||
var pkg = JSON.parse(readFile('./package.json'))
|
||||
var repository = pkg.repository ? pkg.repository.url : null
|
||||
|
||||
if (!repository) return cb('Package must have a repository')
|
||||
if (!repository) return cb(new Error('Package must have a repository'))
|
||||
|
||||
changelog({
|
||||
version: pkg.version,
|
||||
repository: parseUrl(repository),
|
||||
file: false
|
||||
}, function(err, log) {
|
||||
if (err) return cb(err)
|
||||
|
||||
exec('git rev-parse HEAD', function(err, hash) {
|
||||
if (err) return cb(err)
|
||||
|
||||
}, efh(cb)(function (log) {
|
||||
exec('git rev-parse HEAD', efh(cb)(function (hash) {
|
||||
var ghRepo = parseSlug(repository)
|
||||
var release = {
|
||||
owner: ghRepo[0],
|
||||
@@ -43,10 +41,9 @@ module.exports = function (options, cb) {
|
||||
token: options.token
|
||||
})
|
||||
|
||||
github.releases.createRelease(release, function(err) {
|
||||
if (err) return cb(err)
|
||||
github.releases.createRelease(release, efh(cb)(function () {
|
||||
cb(null, true)
|
||||
})
|
||||
})
|
||||
})
|
||||
}))
|
||||
}))
|
||||
}))
|
||||
}
|
||||
|
||||
+5
-7
@@ -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)
|
||||
})
|
||||
})
|
||||
}))
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user