@@ -141,7 +141,11 @@ const pkg = loadJsonFileSync(path.join(__dirname, '../', 'package.json'));
141141 } else if ( whichBumpType . includes ( 'beta' ) ) {
142142 publishTagName = 'beta' ;
143143 }
144- await publishPackage ( publishTagName , { cwd, dryRun : argv . dryRun } ) ;
144+ let otp = '' ;
145+ if ( await promptConfirmation ( `${ c . bgMagenta ( dryRunPrefix ) } Do you have OTP (One-Time-Password) enabled?` , undefined , 1 ) ) {
146+ otp = await promptOtp ( ) ;
147+ }
148+ await publishPackage ( publishTagName , { cwd, otp, dryRun : argv . dryRun } ) ;
145149 console . log ( `${ c . bgMagenta ( dryRunPrefix ) } 📦 Published to NPM - 🔗 https://www.npmjs.com/package/${ pkg . name } ` . trim ( ) )
146150 }
147151
@@ -264,7 +268,9 @@ async function promptConfirmation(message, choices, defaultIndex) {
264268 { key : 'y' , name : 'Yes' , value : true } ,
265269 { key : 'n' , name : 'No' , value : false } ,
266270 ] ;
267- defaultIndex = 0 ;
271+ if ( defaultIndex === undefined ) {
272+ defaultIndex = 0 ;
273+ }
268274 }
269275
270276 // display propmpt message and choices
@@ -274,10 +280,18 @@ async function promptConfirmation(message, choices, defaultIndex) {
274280 }
275281
276282 // get and process input
277- const input = await getConsoleInput ( " Enter value " + " (default " + ( defaultIndex + 1 ) + ') ' ) ;
283+ const input = await getConsoleInput ( ` Enter value (default ${ ( defaultIndex + 1 ) } ) ` ) ;
278284 var index = ! isNaN ( input ) && ! isNaN ( parseFloat ( input ) ) ? + input - 1 : defaultIndex ;
279285 if ( index < 0 || index >= choices . length ) {
280- throw Error ( ' The input ' + input + ' could not be matched to a selection' ) ;
286+ throw Error ( ` The input ${ input } could not be matched to a selection` ) ;
281287 }
282288 return choices [ index ] . value ;
283289}
290+
291+ async function promptOtp ( ) {
292+ const otp = await getConsoleInput ( `Enter OTP value:` ) ;
293+ if ( otp . length < 6 ) {
294+ throw new Error ( 'OTP must be 6 digits.' ) ;
295+ }
296+ return otp ;
297+ }
0 commit comments