@@ -54,60 +54,48 @@ const defaultDryRun = configOptions.defaultDryRun !== 'false';
5454//------------------------------------------------------------------------------
5555// command line options
5656const 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' )
6968 . option ( 'preid' , {
70- demand : false ,
7169 describe : 'pre-release identifier' ,
7270 type : 'string'
7371 } )
7472 . 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' ,
7774 type : 'string'
7875 } )
7976 . option ( 'only-docs' , {
8077 alias : 'docs' ,
81- demand : false ,
82- default : false ,
8378 describe : 'Publish only documents'
8479 } )
8580 . option ( 'run' , {
86- demand : false ,
87- default : false ,
88- describe : 'Actually execute command.'
81+ describe : 'Actually execute command'
8982 } )
9083 . option ( 'dry-run' , {
9184 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'
9586 } )
9687 . option ( 'verbose' , {
97- demand : false ,
98- default : false ,
9988 describe : 'Increased debug output'
10089 } )
10190 . option ( 'skip-tests' , {
10291 alias : 'skip-test' ,
103- demand : false ,
104- default : false ,
10592 describe : 'Skip `npm run test` step'
10693 } )
94+ . option ( 'skip-version-bumping' , {
95+ describe : 'Skip version bumping step'
96+ } )
10797 . 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'
11199 } ) ;
112100
113101const argv = yargsConf . argv ;
@@ -120,7 +108,7 @@ const versionBumpOptions = {
120108 npmTagName : argv . tag || argv . preid
121109} ;
122110
123- if ( versionBumpOptions . type === undefined && versionBumpOptions . preid === undefined ) {
111+ if ( ! argv . skipVersionBumping && versionBumpOptions . type === undefined && versionBumpOptions . preid === undefined ) {
124112 console . log ( 'Must provide either a version bump type, "preid" or "--only-docs"' . red ) ;
125113 console . log ( yargsConf . help ( ) ) ;
126114 exit ( 1 ) ;
@@ -134,7 +122,11 @@ if (argv.run) {
134122}
135123if ( dryRunMode ) {
136124 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+ }
138130}
139131
140132if ( argv . preid ) console . log ( '"--preid" detected. Documents will not be published' . yellow ) ;
@@ -212,8 +204,6 @@ function releaseAdRepo(repo, srcFolder, tmpFolder, vVersion) {
212204}
213205
214206function release ( { type, preid, npmTagName } ) {
215- if ( type === undefined && ! preid ) printErrorAndExit ( 'Must specify version type or preid' ) ;
216-
217207 // ensure git repo has no pending changes
218208 if ( exec ( 'git diff-index --name-only HEAD --' ) . output . length ) {
219209 printErrorAndExit ( 'Git repository must be clean' ) ;
@@ -227,27 +217,32 @@ function release({ type, preid, npmTagName }) {
227217 }
228218 console . info ( 'Current with latest changes from remote' . cyan ) ;
229219
230- // version bump
220+ // version bumping
231221 const oldVersion = npmjson . version ;
232222 let newVersion ;
233223
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 ) ;
238227 } 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+ }
241235
242- if ( preid ) {
243- newVersion = semver . inc ( newVersion , 'pre' , preid ) ;
244- }
236+ if ( preid ) {
237+ newVersion = semver . inc ( newVersion , 'pre' , preid ) ;
238+ }
245239
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 ) ;
248242
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+ }
251246
252247 if ( npmjson . scripts ) { // do not throw if there are no 'scripts' at all
253248 if ( npmjson . scripts . test && ! argv . skipTests ) {
@@ -308,7 +303,7 @@ function release({ type, preid, npmTagName }) {
308303 safeRun ( `git add -A ${ changelogAlpha } ` ) ;
309304 }
310305
311- console . log ( 'Generated Changelog ' . cyan ) ;
306+ console . log ( 'The changelog has been generated ' . cyan ) ;
312307 }
313308
314309 safeRun ( `git commit -m "Release ${ vVersion } "` ) ;
@@ -354,10 +349,10 @@ function release({ type, preid, npmTagName }) {
354349 if ( err ) {
355350 console . log ( 'API request to GitHub, error has occured:' . red ) ;
356351 console . log ( err ) ;
357- console . log ( 'Skip GitHub releasing' . yellow ) ;
352+ console . log ( 'Skipping GitHub releasing' . yellow ) ;
358353 } else if ( res . statusMessage === 'Unauthorized' ) {
359354 console . log ( `GitHub token ${ githubToken } is wrong` . red ) ;
360- console . log ( 'Skip GitHub releasing' . yellow ) ;
355+ console . log ( 'Skipping GitHub releasing' . yellow ) ;
361356 } else {
362357 console . log ( `Published at ${ body . html_url } ` . green ) ;
363358 }
@@ -403,7 +398,7 @@ function release({ type, preid, npmTagName }) {
403398 releaseAdRepo ( bowerRepo , bowerRoot , tmpBowerRepo , vVersion ) ;
404399 console . log ( 'Released: ' . cyan + 'bower package' . green ) ;
405400 } 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 ) ;
407402 }
408403 }
409404
0 commit comments