Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: bower support #134

Merged
merged 2 commits into from
Nov 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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))
}
Expand Down Expand Up @@ -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()
})
})
Expand Down
24 changes: 24 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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"')
Expand Down