diff --git a/index.js b/index.js index 9b84494ed..0345b01fa 100755 --- a/index.js +++ b/index.js @@ -13,6 +13,7 @@ var objectAssign = require('object-assign') module.exports = function standardVersion (argv, done) { var pkgPath = path.resolve(process.cwd(), './package.json') + var bowerPath = path.resolve(process.cwd(), './bower.json') var pkg = require(pkgPath) var defaults = require('./defaults') @@ -32,6 +33,15 @@ module.exports = function standardVersion (argv, done) { checkpoint(argv, 'bumping version in package.json from %s to %s', [pkg.version, newVersion]) pkg.version = newVersion fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf-8') + try { + var stat = fs.lstatSync(bowerPath) + if (stat.isFile()) { + var bower = require(bowerPath) + bower.version = newVersion + fs.writeFileSync(bowerPath, JSON.stringify(bower, null, 2) + '\n', 'utf-8') + argv.bower = true + } + } catch (e) {} } else { checkpoint(argv, 'skip version bump on first release', [], chalk.red(figures.cross)) } @@ -97,14 +107,19 @@ function commit (argv, newVersion, cb) { var msg = 'committing %s' var args = [argv.infile] var verify = argv.verify === false || argv.n ? '--no-verify ' : '' + var bower = '' if (!argv.firstRelease) { msg += ' and %s' args.unshift('package.json') } + if (argv.bower) { + msg += ' and %s' + args.unshift('bower.json') + bower = ' bower.json' + } checkpoint(argv, msg, args) - - handledExec(argv, 'git add package.json ' + argv.infile, cb, function () { - handledExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + (argv.commitAll ? '' : ('package.json ' + argv.infile)) + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', cb, function () { + handledExec(argv, 'git add package.json ' + argv.infile + bower, cb, function () { + handledExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + (argv.commitAll ? '' : ('package.json ' + argv.infile + bower)) + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', cb, function () { cb() }) }) diff --git a/test.js b/test.js index 99d0961d8..e5209f885 100644 --- a/test.js +++ b/test.js @@ -28,6 +28,12 @@ function writePackageJson (version, option) { fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8') } +function writeBowerJson (version, option) { + option = option || {} + var bower = objectAssign(option, { version: version }) + fs.writeFileSync('bower.json', JSON.stringify(bower), 'utf-8') +} + function writeGitPreCommitHook () { fs.writeFileSync('.git/hooks/pre-commit', '#!/bin/sh\necho "precommit ran"\nexit 1', 'utf-8') fs.chmodSync('.git/hooks/pre-commit', '755') @@ -301,6 +307,24 @@ describe('standard-version', function () { }) }) + describe('with bower.json', function () { + beforeEach(function () { + writeBowerJson('1.0.0') + }) + + it('check with bower.json', function (done) { + 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) { + should.not.exist(err) + var bower = fs.readFileSync('bower.json', 'utf-8') + bower.should.match(/"version": "1\.2\.0"/) + done() + }) + }) + }) + it('formats the commit and tag messages appropriately', function (done) { commit('feat: first commit') shell.exec('git tag -a v1.0.0 -m "my awesome first release"')