diff --git a/bin/cli.js b/bin/cli.js
index ceafbcc46..70ef2d652 100755
--- a/bin/cli.js
+++ b/bin/cli.js
@@ -6,9 +6,8 @@ var cmdParser = require('../command')
if (process.version.match(/v(\d+)\./)[1] < 4) {
console.error('standard-version: Node v4 or greater is required. `standard-version` did not run.')
} else {
- standardVersion(cmdParser.argv, function (err) {
- if (err) {
+ standardVersion(cmdParser.argv)
+ .catch(() => {
process.exit(1)
- }
- })
+ })
}
diff --git a/index.js b/index.js
index 113181104..d1df0d68d 100755
--- a/index.js
+++ b/index.js
@@ -14,53 +14,42 @@ const printError = require('./lib/print-error')
const runExec = require('./lib/run-exec')
const runLifecycleHook = require('./lib/run-lifecycle-hook')
-module.exports = function standardVersion (argv, done) {
+module.exports = function standardVersion (argv) {
var pkgPath = path.resolve(process.cwd(), './package.json')
var pkg = require(pkgPath)
+ var newVersion = pkg.version
var hooks = argv.hooks || {}
var defaults = require('./defaults')
var args = Object.assign({}, defaults, argv)
- return bumpVersion(args.releaseAs, function (err, release) {
- if (err) {
- printError(args, err.message)
- return done(err)
- }
-
- var newVersion = pkg.version
-
- if (!args.firstRelease) {
- var releaseType = getReleaseType(args.prerelease, release.releaseType, pkg.version)
- newVersion = semver.valid(releaseType) || semver.inc(pkg.version, releaseType, args.prerelease)
- updateConfigs(args, newVersion)
- } else {
- checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross))
- }
- runLifecycleHook(args, 'postbump', newVersion, hooks, function (err) {
- if (err) {
- printError(args, err.message)
- return done(err)
+ return bumpVersion(args.releaseAs)
+ .then((release) => {
+ if (!args.firstRelease) {
+ var releaseType = getReleaseType(args.prerelease, release.releaseType, pkg.version)
+ newVersion = semver.valid(releaseType) || semver.inc(pkg.version, releaseType, args.prerelease)
+ updateConfigs(args, newVersion)
+ } else {
+ checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross))
}
- outputChangelog(args, function (err) {
- if (err) {
- return done(err)
- }
- runLifecycleHook(args, 'precommit', newVersion, hooks, function (err) {
- if (err) {
- printError(args, err.message)
- return done(err)
- }
- commit(args, newVersion, function (err) {
- if (err) {
- return done(err)
- }
- return tag(newVersion, pkg.private, args, done)
- })
- })
- })
+ return runLifecycleHook(args, 'postbump', newVersion, hooks)
+ })
+ .then(() => {
+ return outputChangelog(args)
+ })
+ .then(() => {
+ return runLifecycleHook(args, 'precommit', newVersion, hooks)
+ })
+ .then(() => {
+ return commit(args, newVersion)
+ })
+ .then(() => {
+ return tag(newVersion, pkg.private, args)
+ })
+ .catch((err) => {
+ printError(args, err.message)
+ throw err
})
- })
}
/**
@@ -160,47 +149,52 @@ function getTypePriority (type) {
}
function bumpVersion (releaseAs, callback) {
- if (releaseAs) {
- callback(null, {
- releaseType: releaseAs
- })
- } else {
- conventionalRecommendedBump({
- preset: 'angular'
- }, function (err, release) {
- callback(err, release)
- })
- }
+ return new Promise((resolve, reject) => {
+ if (releaseAs) {
+ return resolve({
+ releaseType: releaseAs
+ })
+ } else {
+ conventionalRecommendedBump({
+ preset: 'angular'
+ }, function (err, release) {
+ if (err) return reject(err)
+ else return resolve(release)
+ })
+ }
+ })
}
-function outputChangelog (argv, cb) {
- createIfMissing(argv)
- var header = '# Change Log\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n'
- var oldContent = fs.readFileSync(argv.infile, 'utf-8')
- // find the position of the last release and remove header:
- if (oldContent.indexOf(' {
+ createIfMissing(argv)
+ var header = '# Change Log\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n'
+ var oldContent = fs.readFileSync(argv.infile, 'utf-8')
+ // find the position of the last release and remove header:
+ if (oldContent.indexOf(' {
return runExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + (argv.commitAll ? '' : (argv.infile + toAdd)) + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"')
})
- .then(() => {
- return cb()
- })
- .catch((err) => {
- return cb(err)
- })
}
function formatCommitMessage (msg, newVersion) {
return String(msg).indexOf('%s') !== -1 ? util.format(msg, newVersion) : msg
}
-function tag (newVersion, pkgPrivate, argv, cb) {
+function tag (newVersion, pkgPrivate, argv) {
var tagOption
if (argv.sign) {
tagOption = '-s '
@@ -245,10 +233,6 @@ function tag (newVersion, pkgPrivate, argv, cb) {
if (pkgPrivate !== true) message += '; npm publish'
checkpoint(argv, 'Run `%s` to publish', [message], chalk.blue(figures.info))
- return cb()
- })
- .catch((err) => {
- return cb(err)
})
}
diff --git a/lib/run-lifecycle-hook.js b/lib/run-lifecycle-hook.js
index b6d6e9d76..caaeeba06 100644
--- a/lib/run-lifecycle-hook.js
+++ b/lib/run-lifecycle-hook.js
@@ -4,18 +4,9 @@ const figures = require('figures')
const runExec = require('./run-exec')
module.exports = function (argv, hookName, newVersion, hooks, cb) {
- if (!hooks[hookName]) {
- cb()
- return
- }
+ if (!hooks[hookName]) return Promise.resolve()
var command = hooks[hookName] + ' --new-version="' + newVersion + '"'
checkpoint(argv, 'Running lifecycle hook "%s"', [hookName])
checkpoint(argv, '- hook command: "%s"', [command], chalk.blue(figures.info))
- runExec(argv, command)
- .then(() => {
- return cb()
- })
- .catch((err) => {
- return cb(err)
- })
+ return runExec(argv, command)
}
diff --git a/package.json b/package.json
index 3c233a54b..7f21bc802 100644
--- a/package.json
+++ b/package.json
@@ -9,6 +9,9 @@
"test": "nyc mocha --timeout=20000 test.js",
"release": "bin/cli.js"
},
+ "nyc": {
+ "exclude": ["tmp/**"]
+ },
"repository": {
"type": "git",
"url": "git+https://github.com/conventional-changelog/standard-version.git"
@@ -42,7 +45,6 @@
"yargs": "^8.0.1"
},
"devDependencies": {
- "bluebird": "^3.4.6",
"chai": "^3.5.0",
"coveralls": "^2.11.9",
"mocha": "^3.1.0",
diff --git a/test.js b/test.js
index 2529b3c82..bd3977e8f 100644
--- a/test.js
+++ b/test.js
@@ -9,11 +9,10 @@ var stream = require('stream')
var mockGit = require('mock-git')
var mockery = require('mockery')
var semver = require('semver')
-var Promise = require('bluebird')
var cli = require('./command')
var standardVersion = require('./index')
-var should = require('chai').should()
+require('chai').should()
var cliPath = path.resolve(__dirname, './bin/cli.js')
@@ -38,7 +37,7 @@ function execCli (argString) {
}
function execCliAsync (argString) {
- return Promise.promisify(standardVersion)(cli.parse('standard-version ' + argString + ' --silent'))
+ return standardVersion(cli.parse('standard-version ' + argString + ' --silent'))
}
function writePackageJson (version, option) {
@@ -544,11 +543,11 @@ describe('standard-version', function () {
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('feat: new feature!')
- require('./index')({silent: true}, function (err) {
- should.exist(err)
- err.message.should.match(/bump err/)
- done()
- })
+ require('./index')({silent: true})
+ .catch((err) => {
+ err.message.should.match(/bump err/)
+ done()
+ })
})
})
@@ -574,11 +573,11 @@ describe('standard-version', function () {
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('feat: new feature!')
- require('./index')({silent: true}, function (err) {
- should.exist(err)
- err.message.should.match(/changelog err/)
- done()
- })
+ require('./index')({silent: true})
+ .catch((err) => {
+ err.message.should.match(/changelog err/)
+ return done()
+ })
})
})
@@ -587,15 +586,14 @@ describe('standard-version', function () {
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('feat: new feature!')
- require('./index')({silent: true}, function (err) {
- should.not.exist(err)
-
- // check last commit message
- shell.exec('git log --oneline -n1').stdout.should.match(/chore\(release\): 1\.1\.0/)
- // check annotated tag message
- shell.exec('git tag -l -n1 v1.1.0').stdout.should.match(/chore\(release\): 1\.1\.0/)
- done()
- })
+ require('./index')({silent: true})
+ .then(() => {
+ // check last commit message
+ shell.exec('git log --oneline -n1').stdout.should.match(/chore\(release\): 1\.1\.0/)
+ // check annotated tag message
+ shell.exec('git tag -l -n1 v1.1.0').stdout.should.match(/chore\(release\): 1\.1\.0/)
+ done()
+ })
})
describe('bower.json support', function () {
@@ -607,12 +605,12 @@ describe('standard-version', function () {
commit('feat: first commit')
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('feat: new feature!')
- require('./index')({silent: true}, function (err) {
- if (err) return done(err)
- JSON.parse(fs.readFileSync('package.json', 'utf-8')).version.should.equal('1.1.0')
- getPackageVersion().should.equal('1.1.0')
- done()
- })
+ require('./index')({silent: true})
+ .then(() => {
+ JSON.parse(fs.readFileSync('package.json', 'utf-8')).version.should.equal('1.1.0')
+ getPackageVersion().should.equal('1.1.0')
+ return done()
+ })
})
})
})