@@ -4,14 +4,16 @@ require('./util').packageDir();
44require ( 'shelljs/global' ) ;
55
66const readlineSync = require ( 'readline-sync' ) ;
7+ const shelljs = require ( 'shelljs' ) ;
78const fs = require ( 'fs' ) ;
89const path = require ( 'path' ) ;
910const semver = require ( 'semver' ) ;
1011const packageJson = JSON . parse ( fs . readFileSync ( 'package.json' ) ) ;
1112
1213const yargs = require ( 'yargs' )
13- . option ( 'allowdirty' , {
14- description : 'Ignore dirty working copy' ,
14+ . option ( 'dryrun' , {
15+ alias : [ 'dry-run' , 'd' ] ,
16+ description : 'Dry run: Ignores dirty working copy and does not commit or publish anything.' ,
1517 boolean : true ,
1618 } )
1719 . option ( 'deps' , {
@@ -22,7 +24,9 @@ const yargs = require('yargs')
2224const util = require ( './util' ) ;
2325const _exec = util . _exec ;
2426
25- if ( ! yargs . argv . allowdirty ) {
27+ if ( yargs . argv . dryrun ) {
28+ console . log ( 'Dry run mode...' )
29+ } else {
2630 util . ensureCleanMaster ( 'master' ) ;
2731}
2832
@@ -36,8 +40,9 @@ if (!versionBump) {
3640 process . exit ( 1 ) ;
3741}
3842
43+ let version = currentVersion ;
3944if ( versionBump !== 'none' ) {
40- const version = semver . inc ( currentVersion , versionBump ) ;
45+ version = semver . inc ( currentVersion , versionBump ) ;
4146
4247 console . log ( `Bumping version: ${ version } ` ) ;
4348
@@ -47,11 +52,12 @@ if (versionBump !== 'none') {
4752
4853
4954// Generate changelog
50- if ( readlineSync . keyInYN ( 'Update CHANGELOG?' ) ) {
55+ let changelog ;
56+ if ( readlineSync . keyInYN ( '\n\nUpdate CHANGELOG?' ) ) {
5157 const depsArg = yargs . argv . deps ? `--deps ${ yargs . argv . deps } ` : '' ;
5258 const show_changelog = path . resolve ( __dirname , 'show_changelog.js' ) ;
5359
54- const changelog = _exec ( `${ show_changelog } ${ depsArg } ` , true ) . stdout ;
60+ changelog = _exec ( `${ show_changelog } ${ depsArg } ` , true ) . stdout ;
5561
5662 console . log ( 'CHANGELOG:\n\n' ) ;
5763 console . log ( changelog ) ;
@@ -67,17 +73,54 @@ if (readlineSync.keyInYN('Update CHANGELOG?')) {
6773
6874// Commit and push changes
6975if ( ! readlineSync . keyInYN ( 'Ready to publish?' ) ) {
70- console . log ( 'Undo changes:\n\ngit checkout CHANGELOG.md package.json\n\n' ) ;
76+ console . log ( '\n\nUndo changes:\n\ngit checkout CHANGELOG.md package.json\n\n' ) ;
7177 process . exit ( 1 ) ;
7278}
7379
80+ if ( ! yargs . argv . dryrun ) {
7481_exec ( `git ci -m ${ version } package.json CHANGELOG.md` ) ;
82+ }
7583
76- if ( ! yargs . argv . allowdirty ) {
84+ if ( ! yargs . argv . dryrun ) {
7785 util . ensureCleanMaster ( 'master' ) ;
7886}
7987
80- _exec ( `npm publish` ) ;
81- _exec ( `git tag ${ version } ` ) ;
82- _exec ( `git push origin master` ) ;
83- _exec ( `git push origin ${ version } ` ) ;
88+
89+ // Publish to NPM and push to github
90+ if ( ! yargs . argv . dryrun ) {
91+ _exec ( `npm publish` ) ;
92+ _exec ( `git tag ${ version } ` ) ;
93+ _exec ( `git push origin master` ) ;
94+ _exec ( `git push origin ${ version } ` ) ;
95+ }
96+
97+
98+ // Help with manual steps
99+ let githuburl = packageJson . repository && packageJson . repository . url ;
100+ githuburl = githuburl && githuburl . replace ( / ^ g i t \+ / , '' ) . replace ( / \. g i t $ / , '' ) ;
101+
102+ if ( githuburl ) {
103+ if ( changelog ) {
104+ const haspbcopy = shelljs . exec ( `which pbcopy` , true ) . code === 0 ;
105+ console . log ( `\n\n1) Update the GitHub tag with release notes/CHANGELOG` ) ;
106+
107+ if ( haspbcopy ) {
108+ fs . writeFileSync ( 'CHANGELOG.tmp' , changelog ) ;
109+ _exec ( 'pbcopy < CHANGELOG.tmp' , true ) ;
110+ fs . unlinkSync ( 'CHANGELOG.tmp' ) ;
111+ console . log ( `(The CHANGELOG has been copied to your clipboard)` ) ;
112+ } else {
113+ console . log ( 'CHANGELOG:\n\n' ) ;
114+ console . log ( changelog ) ;
115+ }
116+ console . log ( `\n${ githuburl } /releases/tag/${ version } ` ) ;
117+ }
118+
119+ console . log ( `\n\n2) Check for milestones` ) ;
120+ console . log ( `\n${ githuburl } /milestones` ) ;
121+
122+ console . log ( `\n\n\n` ) ;
123+ } else {
124+ console . log ( "Could not determine github URL from package.json" )
125+ }
126+
0 commit comments