@@ -54,60 +54,48 @@ const defaultDryRun = configOptions.defaultDryRun !== 'false';
54
54
//------------------------------------------------------------------------------
55
55
// command line options
56
56
const yargsConf = yargs
57
- . usage ( 'Usage: $0 <version> --run [--preid <identifier>]\nor\nUsage: $0 --only-docs --run' )
58
- . example ( '$0 minor --preid beta --run' , 'Release with minor version bump with pre-release tag. (npm tag `beta`)' )
59
- . example ( '$0 major --run' , 'Release with major version bump' )
60
- . example ( '$0 major --notes "This is new cool version" --run' , 'Add a custom message to release' )
61
- . example ( '$0 major' , 'Without "--run" option it will dry run' )
62
- . example ( '$0 --preid alpha --run' , 'Release same version with pre-release bump. (npm tag `alpha`)' )
63
- . example ( '$0 0.101.0 --preid rc --tag canary --run' , 'Release `v0.101.0-rc.0` pre-release version with npm tag `canary`' )
64
- . example ( '$0 ... --skip-test(s)' , 'Use this flag in case you need to skip `npm run test` step.' )
65
- . command ( 'patch --run' , 'Release patch' )
66
- . command ( 'minor --run' , 'Release minor' )
67
- . command ( 'major --run' , 'Release major' )
68
- . command ( '<version> --run' , 'Release specific version' )
57
+ . usage ( 'Usage: $0 <version> [--preid <identifier>]\nor\nUsage: $0 --only-docs' )
58
+ . example ( '$0 minor --preid beta' , 'Release with a minor version bump and a pre-release tag. (npm tag `beta`)' )
59
+ . example ( '$0 major' , 'Release with a major version bump' )
60
+ . example ( '$0 major --notes "a custom message text"' , 'Add a custom message to the release' )
61
+ . example ( '$0 --preid alpha' , 'Release the same version with a pre-release tag. (npm tag `alpha`)' )
62
+ . example ( '$0 0.101.0 --preid rc --tag canary' , 'Release pre-release version `v0.101.0-rc.0` with npm tag `canary`' )
63
+ . example ( '$0 ... --skip-test(s)' , 'Use this flag if you need to skip `npm run test` step.' )
64
+ . command ( 'patch' , 'Release patch' )
65
+ . command ( 'minor' , 'Release minor' )
66
+ . command ( 'major' , 'Release major' )
67
+ . command ( '<version>' , 'Release arbitrary version number' )
69
68
. option ( 'preid' , {
70
- demand : false ,
71
69
describe : 'pre-release identifier' ,
72
70
type : 'string'
73
71
} )
74
72
. option ( 'tag' , {
75
- demand : false ,
76
- describe : 'Npm tag name for the pre-release version.\nIf it is not provided, then `preid` value is used' ,
73
+ describe : 'Npm tag name for pre-release version.\nIf it is not provided, then `preid` value is used' ,
77
74
type : 'string'
78
75
} )
79
76
. option ( 'only-docs' , {
80
77
alias : 'docs' ,
81
- demand : false ,
82
- default : false ,
83
78
describe : 'Publish only documents'
84
79
} )
85
80
. option ( 'run' , {
86
- demand : false ,
87
- default : false ,
88
- describe : 'Actually execute command.'
81
+ describe : 'Actually execute command'
89
82
} )
90
83
. option ( 'dry-run' , {
91
84
alias : 'n' ,
92
- demand : false ,
93
- default : false ,
94
- describe : 'With "defaultDryRun" option set this toggles "dry run" mode.'
85
+ describe : 'With "defaultDryRun" option set this toggles "dry run" mode'
95
86
} )
96
87
. option ( 'verbose' , {
97
- demand : false ,
98
- default : false ,
99
88
describe : 'Increased debug output'
100
89
} )
101
90
. option ( 'skip-tests' , {
102
91
alias : 'skip-test' ,
103
- demand : false ,
104
- default : false ,
105
92
describe : 'Skip `npm run test` step'
106
93
} )
94
+ . option ( 'skip-version-bumping' , {
95
+ describe : 'Skip version bumping step'
96
+ } )
107
97
. option ( 'notes' , {
108
- demand : false ,
109
- default : false ,
110
- describe : 'A custom message for release.\nOverrides [rf|mt]changelog message'
98
+ describe : 'A custom message for the release.\nOverrides [rf|mt]changelog message'
111
99
} ) ;
112
100
113
101
const argv = yargsConf . argv ;
@@ -120,7 +108,7 @@ const versionBumpOptions = {
120
108
npmTagName : argv . tag || argv . preid
121
109
} ;
122
110
123
- if ( versionBumpOptions . type === undefined && versionBumpOptions . preid === undefined ) {
111
+ if ( ! argv . skipVersionBumping && versionBumpOptions . type === undefined && versionBumpOptions . preid === undefined ) {
124
112
console . log ( 'Must provide either a version bump type, "preid" or "--only-docs"' . red ) ;
125
113
console . log ( yargsConf . help ( ) ) ;
126
114
exit ( 1 ) ;
@@ -134,7 +122,11 @@ if (argv.run) {
134
122
}
135
123
if ( dryRunMode ) {
136
124
console . log ( 'DRY RUN' . magenta ) ;
137
- if ( defaultDryRun ) console . log ( 'For actual running of your command please add "--run" option' . yellow ) ;
125
+ if ( defaultDryRun ) {
126
+ console . log ( '------------------------------------------------------' ) ;
127
+ console . log ( 'To actually run your command please add "--run" option' . yellow ) ;
128
+ console . log ( '------------------------------------------------------' ) ;
129
+ }
138
130
}
139
131
140
132
if ( argv . preid ) console . log ( '"--preid" detected. Documents will not be published' . yellow ) ;
@@ -212,8 +204,6 @@ function releaseAdRepo(repo, srcFolder, tmpFolder, vVersion) {
212
204
}
213
205
214
206
function release ( { type, preid, npmTagName } ) {
215
- if ( type === undefined && ! preid ) printErrorAndExit ( 'Must specify version type or preid' ) ;
216
-
217
207
// ensure git repo has no pending changes
218
208
if ( exec ( 'git diff-index --name-only HEAD --' ) . output . length ) {
219
209
printErrorAndExit ( 'Git repository must be clean' ) ;
@@ -227,27 +217,32 @@ function release({ type, preid, npmTagName }) {
227
217
}
228
218
console . info ( 'Current with latest changes from remote' . cyan ) ;
229
219
230
- // version bump
220
+ // version bumping
231
221
const oldVersion = npmjson . version ;
232
222
let newVersion ;
233
223
234
- if ( type === undefined ) {
235
- newVersion = oldVersion ; // --preid
236
- } else if ( [ 'major' , 'minor' , 'patch' ] . indexOf ( type ) >= 0 ) {
237
- newVersion = semver . inc ( oldVersion , type ) ;
224
+ if ( argv . skipVersionBumping ) {
225
+ newVersion = oldVersion ;
226
+ console . log ( 'The version remains the same ' . yellow + oldVersion . green ) ;
238
227
} else {
239
- newVersion = type ; // '<version>', 'Release specific version'
240
- }
228
+ if ( type === undefined ) {
229
+ newVersion = oldVersion ; // --preid
230
+ } else if ( [ 'major' , 'minor' , 'patch' ] . indexOf ( type ) >= 0 ) {
231
+ newVersion = semver . inc ( oldVersion , type ) ;
232
+ } else {
233
+ newVersion = type ; // '<version>', 'Release specific version'
234
+ }
241
235
242
- if ( preid ) {
243
- newVersion = semver . inc ( newVersion , 'pre' , preid ) ;
244
- }
236
+ if ( preid ) {
237
+ newVersion = semver . inc ( newVersion , 'pre' , preid ) ;
238
+ }
245
239
246
- npmjson . version = newVersion ;
247
- `${ JSON . stringify ( npmjson , null , 2 ) } \n` . to ( packagePath ) ;
240
+ npmjson . version = newVersion ;
241
+ `${ JSON . stringify ( npmjson , null , 2 ) } \n` . to ( packagePath ) ;
248
242
249
- console . log ( 'Version changed from ' . cyan + oldVersion . green + ' to ' . cyan + newVersion . green ) ;
250
- safeRun ( 'git add package.json' ) ;
243
+ console . log ( 'The version changed from ' . cyan + oldVersion . green + ' to ' . cyan + newVersion . green ) ;
244
+ safeRun ( 'git add package.json' ) ;
245
+ }
251
246
252
247
if ( npmjson . scripts ) { // do not throw if there are no 'scripts' at all
253
248
if ( npmjson . scripts . test && ! argv . skipTests ) {
@@ -308,7 +303,7 @@ function release({ type, preid, npmTagName }) {
308
303
safeRun ( `git add -A ${ changelogAlpha } ` ) ;
309
304
}
310
305
311
- console . log ( 'Generated Changelog ' . cyan ) ;
306
+ console . log ( 'The changelog has been generated ' . cyan ) ;
312
307
}
313
308
314
309
safeRun ( `git commit -m "Release ${ vVersion } "` ) ;
@@ -354,10 +349,10 @@ function release({ type, preid, npmTagName }) {
354
349
if ( err ) {
355
350
console . log ( 'API request to GitHub, error has occured:' . red ) ;
356
351
console . log ( err ) ;
357
- console . log ( 'Skip GitHub releasing' . yellow ) ;
352
+ console . log ( 'Skipping GitHub releasing' . yellow ) ;
358
353
} else if ( res . statusMessage === 'Unauthorized' ) {
359
354
console . log ( `GitHub token ${ githubToken } is wrong` . red ) ;
360
- console . log ( 'Skip GitHub releasing' . yellow ) ;
355
+ console . log ( 'Skipping GitHub releasing' . yellow ) ;
361
356
} else {
362
357
console . log ( `Published at ${ body . html_url } ` . green ) ;
363
358
}
@@ -403,7 +398,7 @@ function release({ type, preid, npmTagName }) {
403
398
releaseAdRepo ( bowerRepo , bowerRoot , tmpBowerRepo , vVersion ) ;
404
399
console . log ( 'Released: ' . cyan + 'bower package' . green ) ;
405
400
} else {
406
- console . log ( 'The "bowerRepo" is not set in package.json. Not publishing bower .' . yellow ) ;
401
+ console . log ( 'The "bowerRepo" is not set in package.json. Skipping Bower package publishing .' . yellow ) ;
407
402
}
408
403
}
409
404
0 commit comments