@@ -5,28 +5,79 @@ require('shelljs/global');
55
66const readlineSync = require ( 'readline-sync' ) ;
77const 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+
822const util = require ( './util' ) ;
923const _exec = util . _exec ;
1024
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' ] ;
1233
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 ) {
1436 process . exit ( 1 ) ;
1537}
1638
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 ) ) ;
1946}
2047
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 ) ;
2365}
2466
67+
68+ // Commit and push changes
2569if ( ! readlineSync . keyInYN ( 'Ready to publish?' ) ) {
70+ console . log ( 'Undo changes:\n\ngit checkout CHANGELOG.md package.json\n\n' ) ;
2671 process . exit ( 1 ) ;
2772}
2873
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+
3080_exec ( `npm publish` ) ;
3181_exec ( `git tag ${ version } ` ) ;
82+ _exec ( `git push origin master` ) ;
3283_exec ( `git push origin ${ version } ` ) ;
0 commit comments