diff --git a/index.js b/index.js index a619c9ccb..532afaab2 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') @@ -34,6 +35,15 @@ module.exports = function standardVersion (argv, done) { 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(args, 'skip version bump on first release', [], chalk.red(figures.cross)) } @@ -178,14 +188,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 f7cb8cd76..d1cee8d57 100644 --- a/test.js +++ b/test.js @@ -49,6 +49,12 @@ function writePackageJson (version, option) { delete require.cache[require.resolve(path.join(process.cwd(), 'package.json'))] } +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') @@ -465,6 +471,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"')