@@ -15,7 +15,6 @@ module.exports = function standardVersion (argv, done) {
15
15
var pkgPath = path . resolve ( process . cwd ( ) , './package.json' )
16
16
var pkg = require ( pkgPath )
17
17
var defaults = require ( './defaults' )
18
-
19
18
var args = objectAssign ( { } , defaults , argv )
20
19
21
20
bumpVersion ( args . releaseAs , function ( err , release ) {
@@ -29,11 +28,7 @@ module.exports = function standardVersion (argv, done) {
29
28
if ( ! args . firstRelease ) {
30
29
var releaseType = getReleaseType ( args . prerelease , release . releaseType , pkg . version )
31
30
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 )
37
32
} else {
38
33
checkpoint ( args , 'skip version bump on first release' , [ ] , chalk . red ( figures . cross ) )
39
34
}
@@ -52,6 +47,37 @@ module.exports = function standardVersion (argv, done) {
52
47
} )
53
48
}
54
49
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
+
55
81
function getReleaseType ( prerelease , expectedReleaseType , currentVersion ) {
56
82
if ( isString ( prerelease ) ) {
57
83
if ( isInPrerelease ( currentVersion ) ) {
@@ -160,7 +186,6 @@ function outputChangelog (argv, cb) {
160
186
161
187
function handledExec ( argv , cmd , errorCb , successCb ) {
162
188
// Exec given cmd and handle possible errors
163
-
164
189
exec ( cmd , function ( err , stdout , stderr ) {
165
190
// If exec returns content in stderr, but no error, print it as a warning
166
191
// If exec returns an error, print it and exit with return code 1
@@ -178,14 +203,19 @@ function commit (argv, newVersion, cb) {
178
203
var msg = 'committing %s'
179
204
var args = [ argv . infile ]
180
205
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
+ } )
185
216
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 ( ) {
189
219
cb ( )
190
220
} )
191
221
} )
0 commit comments