@@ -126,7 +126,7 @@ module.exports = class PM2ioHandler {
126126 if ( res !== true ) {
127127 this . authenticate ( )
128128 } else {
129- this . createBucket ( this . createBucketHandler )
129+ this . createBucket ( this . createBucketHandler . bind ( this ) )
130130 }
131131 } ) . catch ( err => {
132132 console . error ( `${ cst . PM2_IO_MSG_ERR } Failed to create to the bucket: ${ err . message } ` )
@@ -173,7 +173,7 @@ module.exports = class PM2ioHandler {
173173 }
174174 const targetURL = `https://app.pm2.io/#/bucket/${ bucket . _id } `
175175 console . log ( `${ cst . PM2_IO_MSG } Please follow the popup or go to this URL :` , '\n' , ' ' , targetURL )
176- open ( targetURL )
176+ this . open ( targetURL )
177177 return process . exit ( 0 )
178178 } )
179179 }
@@ -230,7 +230,7 @@ module.exports = class PM2ioHandler {
230230
231231 static createBucketHandler ( err , bucket ) {
232232 if ( err ) {
233- console . error ( `${ cst . PM2_IO_MSG_ERR } Failed to connect to the bucket: ${ err . message } ` )
233+ console . trace ( `${ cst . PM2_IO_MSG_ERR } Failed to connect to the bucket: ${ err . message } ` )
234234 if ( bucket ) {
235235 console . error ( `${ cst . PM2_IO_MSG_ERR } You can retry using: pm2 plus link ${ bucket . secret_id } ${ bucket . public_id } ` )
236236 }
@@ -241,17 +241,13 @@ module.exports = class PM2ioHandler {
241241 return process . exit ( 0 )
242242 }
243243 console . log ( `${ cst . PM2_IO_MSG } Successfully connected to bucket ${ bucket . name } ` )
244- console . log ( `${ cst . PM2_IO_MSG } You can use the web interface over there: https://app.pm2.io/#/bucket/${ bucket . _id } ` )
244+ var targetURL = `https://app.pm2.io/#/bucket/${ bucket . _id } `
245+ console . log ( `${ cst . PM2_IO_MSG } You can use the web interface over there: ${ targetURL } ` )
246+ this . open ( `https://app.pm2.io/` )
245247 return process . exit ( 0 )
246248 }
247249
248250 static createBucket ( cb ) {
249- console . log ( `${ cst . PM2_IO_MSG } It seems that you don't have any bucket to monitor your app currently.` )
250- console . log ( `${ cst . PM2_IO_MSG } Note: A bucket is like a organization in PM2 Plus where you connect multiples servers to it.` )
251- // currently we redirect on the UI
252- console . log ( `${ cst . PM2_IO_MSG } We have disabled new bucket creation via the cli for now. You should go to https://app.pm2.io to continue` )
253- return process . exit ( 0 )
254-
255251 console . log ( `${ cst . PM2_IO_MSG } By default we allow you to trial PM2 Plus for 14 days without any credit card.` )
256252 // do not create a bucket by default, we need their authorization
257253 promptly . confirm ( `${ cst . PM2_IO_MSG } Do you want to create a new bucket and launch the trial ? (y/n)` , ( err , value ) => {
@@ -263,7 +259,8 @@ module.exports = class PM2ioHandler {
263259 this . io . bucket . create ( {
264260 name : 'PM2 Plus Monitoring'
265261 } ) . then ( res => {
266- const bucket = res . data
262+ const bucket = res . data . bucket
263+
267264 this . io . bucket . billing . startTrial ( bucket . _id , {
268265 plan : 'plus_8'
269266 } ) . then ( res => {
@@ -345,25 +342,11 @@ module.exports = class PM2ioHandler {
345342 this . io . user . retrieve ( ) . then ( res => {
346343 const user = res . data
347344
348- if ( typeof user . email_token === 'string' ) {
349- console . log ( `${ cst . PM2_IO_MSG } You need to validate your email, you should have received an email at ${ user . email } ` )
350- console . log ( `${ cst . PM2_IO_MSG } You can also contact us to get help: [email protected] ` ) 351- process . stdout . write ( `${ cst . PM2_IO_MSG } Waiting for validation ` )
352- const interval = setInterval ( ( ) => {
353- this . io . user . retrieve ( ) . then ( res => {
354- const tmpUser = res . data
355- if ( tmpUser . email_token === null ) {
356- console . log ( `\n${ cst . PM2_IO_MSG } Successfully validated` )
357- clearInterval ( interval )
358- this . connectToBucket ( this . createBucketHandler )
359- } else {
360- process . stdout . write ( '.' )
361- }
362- } )
363- } , 2000 )
364- } else {
365- this . connectToBucket ( this . createBucketHandler )
366- }
345+ this . io . user . retrieve ( ) . then ( res => {
346+ const tmpUser = res . data
347+ console . log ( `${ cst . PM2_IO_MSG } Successfully validated` )
348+ this . connectToBucket ( this . createBucketHandler . bind ( this ) )
349+ } )
367350 } )
368351 } )
369352 }
0 commit comments