@@ -22,11 +22,25 @@ const { join } = require('path')
22
22
const minimist = require ( 'minimist' )
23
23
const chalk = require ( 'chalk' )
24
24
25
+ const helpMessage = `usage: node scripts/release-canary.js [options]
26
+
27
+ --otp <code> One-time password (required)
28
+ --reset Reset the canary version to 1
29
+ --dry-run Run everything but don't actually publish
30
+ -h, --help Show this help message`
31
+
25
32
async function release ( opts ) {
33
+ if ( opts . help ) {
34
+ console . log ( helpMessage )
35
+ process . exit ( 0 )
36
+ }
37
+
26
38
assert ( process . cwd ( ) !== __dirname , 'You should run the script from the top level directory of the repository' )
27
- assert ( typeof opts . otp === 'string' , 'Missing OTP' )
28
- const packageJson = JSON . parse ( await readFile ( join ( __dirname , '..' , 'package.json' ) , 'utf8' ) )
39
+ if ( ! opts [ 'dry-run' ] ) {
40
+ assert ( typeof opts . otp === 'string' , 'Missing OTP' )
41
+ }
29
42
43
+ const packageJson = JSON . parse ( await readFile ( join ( __dirname , '..' , 'package.json' ) , 'utf8' ) )
30
44
const originalName = packageJson . name
31
45
const originalVersion = packageJson . version
32
46
const currentCanaryVersion = packageJson . versionCanary
@@ -52,6 +66,7 @@ async function release (opts) {
52
66
const diff = execSync ( 'git diff' ) . toString ( ) . split ( '\n' ) . map ( colorDiff ) . join ( '\n' )
53
67
console . log ( diff )
54
68
const answer = await confirm ( )
69
+
55
70
// release on npm with provided otp
56
71
if ( answer ) {
57
72
execSync ( `npm publish --otp ${ opts . otp } ${ opts [ 'dry-run' ] ? '--dry-run' : '' } ` , { stdio : 'inherit' } )
@@ -73,8 +88,8 @@ async function release (opts) {
73
88
)
74
89
}
75
90
76
- function confirm ( question ) {
77
- return new Promise ( ( resolve , reject ) => {
91
+ function confirm ( ) {
92
+ return new Promise ( ( resolve ) => {
78
93
const rl = readline . createInterface ( {
79
94
input : process . stdin ,
80
95
output : process . stdout
@@ -110,12 +125,18 @@ release(
110
125
boolean : [
111
126
// Reset the canary version to '1'
112
127
'reset' ,
113
- // run all the steps but publish
114
- 'dry-run'
115
- ]
128
+
129
+ // run all the steps but don't publish
130
+ 'dry-run' ,
131
+
132
+ // help text
133
+ 'help' ,
134
+ ] ,
135
+ alias : { help : 'h' } ,
116
136
} )
117
137
)
118
138
. catch ( err => {
119
139
console . log ( err )
140
+ console . log ( '\n' + helpMessage )
120
141
process . exit ( 1 )
121
142
} )
0 commit comments