@@ -15,7 +15,6 @@ module.exports = function standardVersion (argv, done) {
1515 var pkgPath = path . resolve ( process . cwd ( ) , './package.json' )
1616 var pkg = require ( pkgPath )
1717 var defaults = require ( './defaults' )
18-
1918 var args = objectAssign ( { } , defaults , argv )
2019
2120 bumpVersion ( args . releaseAs , function ( err , release ) {
@@ -29,11 +28,7 @@ module.exports = function standardVersion (argv, done) {
2928 if ( ! args . firstRelease ) {
3029 var releaseType = getReleaseType ( args . prerelease , release . releaseType , pkg . version )
3130 newVersion = semver . inc ( pkg . version , releaseType , args . prerelease )
32-
33- checkpoint ( args , 'bumping version in package.json from %s to %s' , [ pkg . version , newVersion ] )
34-
35- pkg . version = newVersion
36- fs . writeFileSync ( pkgPath , JSON . stringify ( pkg , null , 2 ) + '\n' , 'utf-8' )
31+ updateConfigs ( args , newVersion )
3732 } else {
3833 checkpoint ( args , 'skip version bump on first release' , [ ] , chalk . red ( figures . cross ) )
3934 }
@@ -52,6 +47,37 @@ module.exports = function standardVersion (argv, done) {
5247 } )
5348}
5449
50+ /**
51+ * attempt to update the version # in a collection of common config
52+ * files, e.g., package.json, bower.json.
53+ *
54+ * @param argv config object
55+ * @param newVersion version # to update to.
56+ * @return {string }
57+ */
58+ var configsToUpdate = { }
59+ function updateConfigs ( args , newVersion ) {
60+ configsToUpdate [ path . resolve ( process . cwd ( ) , './package.json' ) ] = false
61+ configsToUpdate [ path . resolve ( process . cwd ( ) , './bower.json' ) ] = false
62+ Object . keys ( configsToUpdate ) . forEach ( function ( configPath ) {
63+ try {
64+ var stat = fs . lstatSync ( configPath )
65+ if ( stat . isFile ( ) ) {
66+ var config = require ( configPath )
67+ var filename = path . basename ( configPath )
68+ config . version = newVersion
69+ fs . writeFileSync ( configPath , JSON . stringify ( config , null , 2 ) + '\n' , 'utf-8' )
70+ checkpoint ( args , 'bumping version in ' + filename + ' from %s to %s' , [ config . version , newVersion ] )
71+ // flag any config files that we modify the version # for
72+ // as having been updated.
73+ configsToUpdate [ configPath ] = true
74+ }
75+ } catch ( err ) {
76+ if ( err . code !== 'ENOENT' ) console . warn ( err . message )
77+ }
78+ } )
79+ }
80+
5581function getReleaseType ( prerelease , expectedReleaseType , currentVersion ) {
5682 if ( isString ( prerelease ) ) {
5783 if ( isInPrerelease ( currentVersion ) ) {
@@ -160,7 +186,6 @@ function outputChangelog (argv, cb) {
160186
161187function handledExec ( argv , cmd , errorCb , successCb ) {
162188 // Exec given cmd and handle possible errors
163-
164189 exec ( cmd , function ( err , stdout , stderr ) {
165190 // If exec returns content in stderr, but no error, print it as a warning
166191 // If exec returns an error, print it and exit with return code 1
@@ -178,14 +203,19 @@ function commit (argv, newVersion, cb) {
178203 var msg = 'committing %s'
179204 var args = [ argv . infile ]
180205 var verify = argv . verify === false || argv . n ? '--no-verify ' : ''
181- if ( ! argv . firstRelease ) {
182- msg += ' and %s'
183- args . unshift ( 'package.json' )
184- }
206+ var toAdd = ''
207+ // commit any of the config files that we've updated
208+ // the version # for.
209+ Object . keys ( configsToUpdate ) . forEach ( function ( p ) {
210+ if ( configsToUpdate [ p ] ) {
211+ msg += ' and %s'
212+ args . unshift ( path . basename ( p ) )
213+ toAdd += ' ' + path . relative ( process . cwd ( ) , p )
214+ }
215+ } )
185216 checkpoint ( argv , msg , args )
186-
187- handledExec ( argv , 'git add package.json ' + argv . infile , cb , function ( ) {
188- handledExec ( argv , 'git commit ' + verify + ( argv . sign ? '-S ' : '' ) + ( argv . commitAll ? '' : ( 'package.json ' + argv . infile ) ) + ' -m "' + formatCommitMessage ( argv . message , newVersion ) + '"' , cb , function ( ) {
217+ handledExec ( argv , 'git add' + toAdd + ' ' + argv . infile , cb , function ( ) {
218+ handledExec ( argv , 'git commit ' + verify + ( argv . sign ? '-S ' : '' ) + ( argv . commitAll ? '' : ( argv . infile + toAdd ) ) + ' -m "' + formatCommitMessage ( argv . message , newVersion ) + '"' , cb , function ( ) {
189219 cb ( )
190220 } )
191221 } )
0 commit comments