@@ -4,14 +4,16 @@ require('./util').packageDir();
4
4
require ( 'shelljs/global' ) ;
5
5
6
6
const readlineSync = require ( 'readline-sync' ) ;
7
+ const shelljs = require ( 'shelljs' ) ;
7
8
const fs = require ( 'fs' ) ;
8
9
const path = require ( 'path' ) ;
9
10
const semver = require ( 'semver' ) ;
10
11
const packageJson = JSON . parse ( fs . readFileSync ( 'package.json' ) ) ;
11
12
12
13
const 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.' ,
15
17
boolean : true ,
16
18
} )
17
19
. option ( 'deps' , {
@@ -22,7 +24,9 @@ const yargs = require('yargs')
22
24
const util = require ( './util' ) ;
23
25
const _exec = util . _exec ;
24
26
25
- if ( ! yargs . argv . allowdirty ) {
27
+ if ( yargs . argv . dryrun ) {
28
+ console . log ( 'Dry run mode...' )
29
+ } else {
26
30
util . ensureCleanMaster ( 'master' ) ;
27
31
}
28
32
@@ -36,8 +40,9 @@ if (!versionBump) {
36
40
process . exit ( 1 ) ;
37
41
}
38
42
43
+ let version = currentVersion ;
39
44
if ( versionBump !== 'none' ) {
40
- const version = semver . inc ( currentVersion , versionBump ) ;
45
+ version = semver . inc ( currentVersion , versionBump ) ;
41
46
42
47
console . log ( `Bumping version: ${ version } ` ) ;
43
48
@@ -47,11 +52,12 @@ if (versionBump !== 'none') {
47
52
48
53
49
54
// Generate changelog
50
- if ( readlineSync . keyInYN ( 'Update CHANGELOG?' ) ) {
55
+ let changelog ;
56
+ if ( readlineSync . keyInYN ( '\n\nUpdate CHANGELOG?' ) ) {
51
57
const depsArg = yargs . argv . deps ? `--deps ${ yargs . argv . deps } ` : '' ;
52
58
const show_changelog = path . resolve ( __dirname , 'show_changelog.js' ) ;
53
59
54
- const changelog = _exec ( `${ show_changelog } ${ depsArg } ` , true ) . stdout ;
60
+ changelog = _exec ( `${ show_changelog } ${ depsArg } ` , true ) . stdout ;
55
61
56
62
console . log ( 'CHANGELOG:\n\n' ) ;
57
63
console . log ( changelog ) ;
@@ -67,17 +73,54 @@ if (readlineSync.keyInYN('Update CHANGELOG?')) {
67
73
68
74
// Commit and push changes
69
75
if ( ! 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' ) ;
71
77
process . exit ( 1 ) ;
72
78
}
73
79
80
+ if ( ! yargs . argv . dryrun ) {
74
81
_exec ( `git ci -m ${ version } package.json CHANGELOG.md` ) ;
82
+ }
75
83
76
- if ( ! yargs . argv . allowdirty ) {
84
+ if ( ! yargs . argv . dryrun ) {
77
85
util . ensureCleanMaster ( 'master' ) ;
78
86
}
79
87
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