Skip to content

Commit

Permalink
Add: bower support (#134)
Browse files Browse the repository at this point in the history
* Add: bower support

* Add: tests
  • Loading branch information
lexich authored and bcoe committed Nov 26, 2016
1 parent a513fa2 commit 219df9b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
21 changes: 18 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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))
}
Expand Down Expand Up @@ -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()
})
})
Expand Down
24 changes: 24 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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"')
Expand Down

0 comments on commit 219df9b

Please sign in to comment.