3
3
const fs = require ( 'fs' ) ;
4
4
const path = require ( 'path' ) ;
5
5
const semver = require ( 'semver' ) ;
6
- const { exec } = require ( 'child_process' ) ;
6
+ const util = require ( 'util' ) ;
7
+ const exec = util . promisify ( require ( 'child_process' ) . exec ) ;
7
8
const yesno = require ( 'yesno' ) ;
8
9
9
10
if ( process . argv . length < 3 ) {
@@ -19,26 +20,26 @@ if (semver.valid(version) == null) {
19
20
20
21
process . chdir ( __dirname ) ;
21
22
22
- // Update package.json
23
- console . log ( 'Updating package.json...' ) ;
24
- const pkg = JSON . parse ( fs . readFileSync ( './package.json' ) . toString ( ) ) ;
25
- if ( ! semver . gt ( version , pkg . version ) ) {
26
- console . error ( `New version ${ version } is not greater than current version ${ pkg . version } ` ) ;
27
- process . exit ( 1 ) ;
28
- }
29
- pkg . version = version ;
30
- fs . writeFileSync ( './package.json' , `${ JSON . stringify ( pkg , null , ' ' ) } \n` ) ;
23
+ async function update ( ) {
24
+ // Update package.json
25
+ console . log ( 'Updating package.json...' ) ;
26
+ const pkg = JSON . parse ( fs . readFileSync ( './package.json' ) . toString ( ) ) ;
27
+ if ( ! semver . gt ( version , pkg . version ) ) {
28
+ console . error ( `New version ${ version } is not greater than current version ${ pkg . version } ` ) ;
29
+ process . exit ( 1 ) ;
30
+ }
31
+ pkg . version = version ;
32
+ fs . writeFileSync ( './package.json' , `${ JSON . stringify ( pkg , null , ' ' ) } \n` ) ;
31
33
32
- // Run standard-changelog
33
- console . log ( 'Running standard-changelog...' ) ;
34
- exec ( './node_modules/.bin/standard-changelog' , err => {
35
- if ( err ) {
34
+ // Run standard-changelog
35
+ console . log ( 'Running standard-changelog...' ) ;
36
+ try {
37
+ await exec ( './node_modules/.bin/standard-changelog' ) ;
38
+ } catch ( err ) {
36
39
console . error ( err ) ;
37
40
process . exit ( 1 ) ;
38
41
}
39
- } ) ;
40
42
41
- async function commitAndPush ( ) {
42
43
// Commit to git after prompting user
43
44
let ok = await yesno ( {
44
45
question : 'Commit changes to git and add tag (y/N)?' ,
@@ -50,18 +51,19 @@ async function commitAndPush() {
50
51
process . exit ( 0 ) ;
51
52
}
52
53
53
- exec ( `git commit -a -m "release: v${ version } "` , err => {
54
- if ( err ) {
55
- console . error ( err ) ;
56
- process . exit ( 1 ) ;
57
- }
58
- } ) ;
59
- exec ( `git tag "v${ version } "` , err => {
60
- if ( err ) {
61
- console . error ( err ) ;
62
- process . exit ( 1 ) ;
63
- }
64
- } ) ;
54
+ try {
55
+ await exec ( `git commit -a -m "release: v${ version } "` ) ;
56
+ } catch ( err ) {
57
+ console . error ( err ) ;
58
+ process . exit ( 1 ) ;
59
+ }
60
+
61
+ try {
62
+ await exec ( `git tag "v${ version } "` ) ;
63
+ } catch ( err ) {
64
+ console . error ( err ) ;
65
+ process . exit ( 1 ) ;
66
+ }
65
67
66
68
// Prompt to push to origin
67
69
ok = await yesno ( {
@@ -74,19 +76,20 @@ async function commitAndPush() {
74
76
process . exit ( 0 ) ;
75
77
}
76
78
77
- exec ( `git push origin` , err => {
78
- if ( err ) {
79
- console . error ( err ) ;
80
- process . exit ( 1 ) ;
81
- }
82
- } ) ;
83
- exec ( `git push origin --tags` , err => {
84
- if ( err ) {
85
- console . error ( err ) ;
86
- process . exit ( 1 ) ;
87
- }
88
- } ) ;
79
+ try {
80
+ await exec ( `git push origin` ) ;
81
+ } catch ( err ) {
82
+ console . error ( err ) ;
83
+ process . exit ( 1 ) ;
84
+ }
85
+
86
+ try {
87
+ await exec ( `git push origin --tags` ) ;
88
+ } catch ( err ) {
89
+ console . error ( err ) ;
90
+ process . exit ( 1 ) ;
91
+ }
89
92
90
93
process . exit ( 0 ) ;
91
94
}
92
- commitAndPush ( ) ;
95
+ update ( ) ;
0 commit comments