@@ -5,28 +5,79 @@ require('shelljs/global');
5
5
6
6
const readlineSync = require ( 'readline-sync' ) ;
7
7
const fs = require ( 'fs' ) ;
8
+ const path = require ( 'path' ) ;
9
+ const semver = require ( 'semver' ) ;
10
+ const packageJson = JSON . parse ( fs . readFileSync ( 'package.json' ) ) ;
11
+
12
+ const yargs = require ( 'yargs' )
13
+ . option ( 'allowdirty' , {
14
+ description : 'Ignore dirty working copy' ,
15
+ boolean : true ,
16
+ } )
17
+ . option ( 'deps' , {
18
+ description : 'Deps to include in changelog' ,
19
+ array : true ,
20
+ } ) ;
21
+
8
22
const util = require ( './util' ) ;
9
23
const _exec = util . _exec ;
10
24
11
- let version = JSON . parse ( fs . readFileSync ( './package.json' ) ) . version ;
25
+ if ( ! yargs . argv . allowdirty ) {
26
+ util . ensureCleanMaster ( 'master' ) ;
27
+ }
28
+
29
+
30
+ // Bump version
31
+ const currentVersion = JSON . parse ( fs . readFileSync ( './package.json' ) ) . version ;
32
+ const versionBumps = [ 'patch' , 'minor' , 'major' , 'none' ] ;
12
33
13
- if ( ! readlineSync . keyInYN ( 'Did you bump the version number in package.json?' ) ) {
34
+ const versionBump = versionBumps [ readlineSync . keyInSelect ( versionBumps , `Current version: ${ currentVersion } ; bump version?` ) ] ;
35
+ if ( ! versionBump ) {
14
36
process . exit ( 1 ) ;
15
37
}
16
38
17
- if ( ! readlineSync . keyInYN ( 'Did you update CHANGELOG.md using scripts/update_changelog.js?' ) ) {
18
- process . exit ( 1 ) ;
39
+ if ( versionBump !== 'none' ) {
40
+ const version = semver . inc ( currentVersion , versionBump ) ;
41
+
42
+ console . log ( `Bumping version: ${ version } ` ) ;
43
+
44
+ packageJson . version = version ;
45
+ fs . writeFileSync ( 'package.json' , JSON . stringify ( packageJson , null , 2 ) ) ;
19
46
}
20
47
21
- if ( ! readlineSync . keyInYN ( 'Did you push all changes back to origin?' ) ) {
22
- process . exit ( 1 ) ;
48
+
49
+ // Generate changelog
50
+ if ( readlineSync . keyInYN ( 'Update CHANGELOG?' ) ) {
51
+ const depsArg = yargs . argv . deps ? `--deps ${ yargs . argv . deps } ` : '' ;
52
+ const show_changelog = path . resolve ( __dirname , 'show_changelog.js' ) ;
53
+
54
+ const changelog = _exec ( `${ show_changelog } ${ depsArg } ` , true ) . stdout ;
55
+
56
+ console . log ( 'CHANGELOG:\n\n' ) ;
57
+ console . log ( changelog ) ;
58
+
59
+ if ( ! readlineSync . keyInYN ( 'Does the CHANGELOG look OK?' ) ) {
60
+ process . exit ( 1 ) ;
61
+ }
62
+
63
+ let fullChangelog = fs . readFileSync ( 'CHANGELOG.md' ) ;
64
+ fs . writeFileSync ( 'CHANGELOG.md' , changelog + '\n' + fullChangelog ) ;
23
65
}
24
66
67
+
68
+ // Commit and push changes
25
69
if ( ! readlineSync . keyInYN ( 'Ready to publish?' ) ) {
70
+ console . log ( 'Undo changes:\n\ngit checkout CHANGELOG.md package.json\n\n' ) ;
26
71
process . exit ( 1 ) ;
27
72
}
28
73
29
- util . ensureCleanMaster ( 'master' ) ;
74
+ _exec ( `git ci -m ${ version } package.json CHANGELOG.md` ) ;
75
+
76
+ if ( ! yargs . argv . allowdirty ) {
77
+ util . ensureCleanMaster ( 'master' ) ;
78
+ }
79
+
30
80
_exec ( `npm publish` ) ;
31
81
_exec ( `git tag ${ version } ` ) ;
82
+ _exec ( `git push origin master` ) ;
32
83
_exec ( `git push origin ${ version } ` ) ;
0 commit comments