@@ -78,18 +78,27 @@ function bump (manifest, type, options) {
7878 let pkgPath = path . join ( cwd , manifest ) ;
7979 const pkg = require ( pkgPath ) ;
8080
81- // Increment the version number
8281 oldVersion = pkg . version || '0.0.0' ;
83- let current = new SemVer ( oldVersion ) ;
84- current . inc ( type , options . preid || current . prerelease [ 0 ] || 'beta' ) ;
85- newVersion = pkg . version = current . version ;
8682
87- // Save the file
88- let usedIndent = indent ( fs . readFileSync ( pkgPath , 'utf8' ) ) . indent || ' ' ;
83+ if ( type === 'custom' ) {
84+ newVersion = options . newVersion ;
85+ }
86+ else {
87+ // Increment the version number
88+ let current = new SemVer ( oldVersion ) ;
89+ current . inc ( type , options . preid || current . prerelease [ 0 ] || 'beta' ) ;
90+ newVersion = current . version ;
91+ }
92+
93+ if ( newVersion !== oldVersion ) {
94+ // Save the file
95+ let usedIndent = indent ( fs . readFileSync ( pkgPath , 'utf8' ) ) . indent || ' ' ;
8996
90- fs . writeFileSync ( pkgPath , JSON . stringify ( pkg , null , usedIndent ) ) ;
97+ pkg . version = newVersion ;
98+ fs . writeFileSync ( pkgPath , JSON . stringify ( pkg , null , usedIndent ) ) ;
9199
92- console . log ( '%s Updated %s to %s' , logSymbols . success , manifest , current . version ) ;
100+ console . log ( '%s Updated %s to %s' , logSymbols . success , manifest , newVersion ) ;
101+ }
93102}
94103
95104/**
@@ -121,40 +130,46 @@ function runNpmScriptIfExists (manifest, script) {
121130 * @param {object } options - CLI options
122131 */
123132function grep ( manifests , options ) {
124- if ( options . grep ) {
125- // Separate the glob patterns into two lists: included and excluded
126- let included = [ ] , excluded = [ ] ;
127- options . grep . forEach ( ( pattern ) => {
128- if ( pattern [ 0 ] === '!' ) {
129- excluded . push ( pattern ) ;
130- }
131- else {
132- included . push ( pattern ) ;
133- }
134- } ) ;
133+ if ( newVersion === oldVersion ) {
134+ return ;
135+ }
135136
136- // Process each glob pattern
137- included . forEach ( ( pattern ) => {
138- let files = glob . sync ( pattern , { nodir : true , ignore : excluded } ) ;
139-
140- // Process each matched file
141- files . forEach ( ( file ) => {
142- // Read the file
143- let fileContents = fs . readFileSync ( file , { encoding : 'utf8' } ) ;
144-
145- // Replace the old version number with the new version number
146- let oldVersionPattern = new RegExp ( oldVersion . replace ( / \. / g, '\\.' ) , 'g' ) ;
147- let newFileContents = fileContents . replace ( oldVersionPattern , newVersion ) ;
148-
149- // Only save the file if there were changes
150- if ( newFileContents !== fileContents ) {
151- fs . writeFileSync ( file , newFileContents ) ;
152- manifests . push ( file ) ;
153- console . log ( '%s Updated %s to %s' , logSymbols . success , file , newVersion ) ;
154- }
155- } ) ;
156- } ) ;
137+ if ( ! options . grep ) {
138+ return ;
157139 }
140+
141+ // Separate the glob patterns into two lists: included and excluded
142+ let included = [ ] , excluded = [ ] ;
143+ options . grep . forEach ( ( pattern ) => {
144+ if ( pattern [ 0 ] === '!' ) {
145+ excluded . push ( pattern ) ;
146+ }
147+ else {
148+ included . push ( pattern ) ;
149+ }
150+ } ) ;
151+
152+ // Process each glob pattern
153+ included . forEach ( ( pattern ) => {
154+ let files = glob . sync ( pattern , { nodir : true , ignore : excluded } ) ;
155+
156+ // Process each matched file
157+ files . forEach ( ( file ) => {
158+ // Read the file
159+ let fileContents = fs . readFileSync ( file , { encoding : 'utf8' } ) ;
160+
161+ // Replace the old version number with the new version number
162+ let oldVersionPattern = new RegExp ( oldVersion . replace ( / \. / g, '\\.' ) , 'g' ) ;
163+ let newFileContents = fileContents . replace ( oldVersionPattern , newVersion ) ;
164+
165+ // Only save the file if there were changes
166+ if ( newFileContents !== fileContents ) {
167+ fs . writeFileSync ( file , newFileContents ) ;
168+ manifests . push ( file ) ;
169+ console . log ( '%s Updated %s to %s' , logSymbols . success , file , newVersion ) ;
170+ }
171+ } ) ;
172+ } ) ;
158173}
159174
160175/**
@@ -164,34 +179,40 @@ function grep (manifests, options) {
164179 * @param {object } options - CLI options
165180 */
166181function git ( manifests , options ) {
167- if ( options . commit || options . tag || options . push ) {
168- // Git Commit
169- let commitArgs = [ 'commit' ] ;
170- commitArgs = commitArgs . concat ( options . all ? '-a' : manifests ) ;
171- let commitMessage = 'release v' + newVersion ;
172- if ( options . commitMessage ) {
173- commitMessage = 'v' + newVersion + ' ' + options . commitMessage ;
174- }
175- commitArgs = commitArgs . concat ( [ '-m' , commitMessage ] ) ;
176- exec ( 'git' , commitArgs ) ;
177- console . log ( logSymbols . success , 'Git commit' ) ;
178-
179- // Git Tag
180- if ( options . tag ) {
181- exec ( 'git' , [ 'tag' , '-a' , 'v' + newVersion , '-m' , newVersion ] ) ;
182- console . log ( logSymbols . success , 'Git tag' ) ;
183- }
182+ if ( newVersion === oldVersion ) {
183+ return ;
184+ }
184185
185- manifests . forEach ( ( manifest ) => {
186- runNpmScriptIfExists ( manifest , 'postversion' ) ;
187- } ) ;
186+ if ( ! ( options . commit || options . tag || options . push ) ) {
187+ return ;
188+ }
188189
189- // Git Push
190- if ( options . push ) {
191- exec ( 'git' , [ 'push' ] ) ;
192- options . tag && exec ( 'git' , [ 'push' , '--tags' ] ) ;
193- console . log ( logSymbols . success , 'Git push' ) ;
194- }
190+ // Git Commit
191+ let commitArgs = [ 'commit' ] ;
192+ commitArgs = commitArgs . concat ( options . all ? '-a' : manifests ) ;
193+ let commitMessage = 'release v' + newVersion ;
194+ if ( options . commitMessage ) {
195+ commitMessage = 'v' + newVersion + ' ' + options . commitMessage ;
196+ }
197+ commitArgs = commitArgs . concat ( [ '-m' , commitMessage ] ) ;
198+ exec ( 'git' , commitArgs ) ;
199+ console . log ( logSymbols . success , 'Git commit' ) ;
200+
201+ // Git Tag
202+ if ( options . tag ) {
203+ exec ( 'git' , [ 'tag' , '-a' , 'v' + newVersion , '-m' , newVersion ] ) ;
204+ console . log ( logSymbols . success , 'Git tag' ) ;
205+ }
206+
207+ manifests . forEach ( ( manifest ) => {
208+ runNpmScriptIfExists ( manifest , 'postversion' ) ;
209+ } ) ;
210+
211+ // Git Push
212+ if ( options . push ) {
213+ exec ( 'git' , [ 'push' ] ) ;
214+ options . tag && exec ( 'git' , [ 'push' , '--tags' ] ) ;
215+ console . log ( logSymbols . success , 'Git push' ) ;
195216 }
196217}
197218
0 commit comments