@@ -204,36 +204,36 @@ class ServerlessStepFunctions {
204204 message += `${ chalk . yellow ( 'stage:' ) } ${ this . stage } \n` ;
205205 message += `${ chalk . yellow ( 'region:' ) } ${ this . region } \n\n` ;
206206 message += `${ chalk . yellow . underline ( 'State Machine Information' ) } \n` ;
207- message += `${ chalk . yellow ( this . options . state ) } ${ chalk . yellow ( ':' ) } ${ this . stateMachineArns [ this . options . state ] } \n` ;
208- this . serverless . cli . consoleLog ( message ) ;
209- return BbPromise . resolve ( ) ;
210- } ) ;
211- } else {
212- this . serverless . cli . log ( `Start to deploy all step functions...` ) ;
213- return BbPromise . bind ( this )
214- . then ( this . yamlParse )
215- . then ( this . getStateMachineNames )
216- . then ( this . getFunctionArns )
217- . then ( this . compileAll )
218- . then ( this . getIamRoles )
219- . then ( this . deleteStateMachines )
220- . then ( this . createStateMachines )
221- . then ( ( ) => {
222- this . serverless . cli . consoleLog ( '' ) ;
223- this . serverless . cli . log ( 'Finish to deploy all step functions' ) ;
224- let message = '' ;
225- message += `${ chalk . yellow . underline ( 'Service Information' ) } \n` ;
226- message += `${ chalk . yellow ( 'service:' ) } ${ this . service } \n` ;
227- message += `${ chalk . yellow ( 'stage:' ) } ${ this . stage } \n` ;
228- message += `${ chalk . yellow ( 'region:' ) } ${ this . region } \n\n` ;
229- message += `${ chalk . yellow . underline ( 'State Machine Information' ) } \n` ;
230- _ . forEach ( this . stateMachineArns , ( arn , name ) => {
231- message += `${ chalk . yellow ( name ) } ${ chalk . yellow ( ':' ) } ${ arn } \n` ;
232- } ) ;
207+ message += `${ chalk . yellow ( this . options . state ) } ${ chalk . yellow ( ':' ) } ` ;
208+ message += `${ this . stateMachineArns [ this . options . state ] } \n` ;
233209 this . serverless . cli . consoleLog ( message ) ;
234210 return BbPromise . resolve ( ) ;
235211 } ) ;
236212 }
213+ this . serverless . cli . log ( 'Start to deploy all step functions...' ) ;
214+ return BbPromise . bind ( this )
215+ . then ( this . yamlParse )
216+ . then ( this . getStateMachineNames )
217+ . then ( this . getFunctionArns )
218+ . then ( this . compileAll )
219+ . then ( this . getIamRoles )
220+ . then ( this . deleteStateMachines )
221+ . then ( this . createStateMachines )
222+ . then ( ( ) => {
223+ this . serverless . cli . consoleLog ( '' ) ;
224+ this . serverless . cli . log ( 'Finish to deploy all step functions' ) ;
225+ let message = '' ;
226+ message += `${ chalk . yellow . underline ( 'Service Information' ) } \n` ;
227+ message += `${ chalk . yellow ( 'service:' ) } ${ this . service } \n` ;
228+ message += `${ chalk . yellow ( 'stage:' ) } ${ this . stage } \n` ;
229+ message += `${ chalk . yellow ( 'region:' ) } ${ this . region } \n\n` ;
230+ message += `${ chalk . yellow . underline ( 'State Machine Information' ) } \n` ;
231+ _ . forEach ( this . stateMachineArns , ( arn , name ) => {
232+ message += `${ chalk . yellow ( name ) } ${ chalk . yellow ( ':' ) } ${ arn } \n` ;
233+ } ) ;
234+ this . serverless . cli . consoleLog ( message ) ;
235+ return BbPromise . resolve ( ) ;
236+ } ) ;
237237 }
238238
239239 stateMachineRemove ( ) {
@@ -247,27 +247,26 @@ class ServerlessStepFunctions {
247247 this . serverless . cli . log ( `Remove ${ this . options . state } ` ) ;
248248 return BbPromise . resolve ( ) ;
249249 } ) ;
250- } else {
251- return BbPromise . bind ( this )
252- . then ( this . yamlParse )
253- . then ( this . deleteIamRoles )
254- . then ( this . getStateMachineNames )
255- . then ( this . deleteStateMachines )
256- . then ( ( ) => {
257- this . serverless . cli . log ( 'Remove all state machine' ) ;
258- let message = '' ;
259- message += `${ chalk . yellow . underline ( 'Service Information' ) } \n` ;
260- message += `${ chalk . yellow ( 'service:' ) } ${ this . service } \n` ;
261- message += `${ chalk . yellow ( 'stage:' ) } ${ this . stage } \n` ;
262- message += `${ chalk . yellow ( 'region:' ) } ${ this . region } \n\n` ;
263- message += `${ chalk . yellow . underline ( 'Deleted State Machine' ) } \n` ;
264- _ . forEach ( this . stateMachineArns , ( arn , name ) => {
265- message += `${ chalk . yellow ( name ) } ${ chalk . yellow ( ':' ) } ${ arn } \n` ;
266- } ) ;
267- this . serverless . cli . consoleLog ( message ) ;
268- return BbPromise . resolve ( ) ;
269- } ) ;
270250 }
251+ return BbPromise . bind ( this )
252+ . then ( this . yamlParse )
253+ . then ( this . deleteIamRoles )
254+ . then ( this . getStateMachineNames )
255+ . then ( this . deleteStateMachines )
256+ . then ( ( ) => {
257+ this . serverless . cli . log ( 'Remove all state machine' ) ;
258+ let message = '' ;
259+ message += `${ chalk . yellow . underline ( 'Service Information' ) } \n` ;
260+ message += `${ chalk . yellow ( 'service:' ) } ${ this . service } \n` ;
261+ message += `${ chalk . yellow ( 'stage:' ) } ${ this . stage } \n` ;
262+ message += `${ chalk . yellow ( 'region:' ) } ${ this . region } \n\n` ;
263+ message += `${ chalk . yellow . underline ( 'Deleted State Machine' ) } \n` ;
264+ _ . forEach ( this . stateMachineArns , ( arn , name ) => {
265+ message += `${ chalk . yellow ( name ) } ${ chalk . yellow ( ':' ) } ${ arn } \n` ;
266+ } ) ;
267+ this . serverless . cli . consoleLog ( message ) ;
268+ return BbPromise . resolve ( ) ;
269+ } ) ;
271270 }
272271
273272 stateMachineInvoke ( ) {
@@ -303,20 +302,20 @@ class ServerlessStepFunctions {
303302 }
304303
305304 getIamRole ( state ) {
306- state = state || this . options . state ;
305+ const stateMachine = state || this . options . state ;
307306 return this . provider . request ( 'IAM' ,
308307 'getRole' ,
309308 {
310- RoleName : this . getIamRoleName ( state ) ,
309+ RoleName : this . getIamRoleName ( stateMachine ) ,
311310 } ,
312311 this . options . stage ,
313312 this . options . region )
314313 . then ( ( result ) => {
315- this . iamRoleArn [ state ] = result . Role . Arn ;
314+ this . iamRoleArn [ stateMachine ] = result . Role . Arn ;
316315 return BbPromise . resolve ( ) ;
317316 } ) . catch ( ( error ) => {
318317 if ( error . statusCode === 404 ) {
319- return this . createIamRole ( state ) ;
318+ return this . createIamRole ( stateMachine ) ;
320319 }
321320 throw new this . serverless . classes . Error ( error . message ) ;
322321 } ) ;
@@ -328,9 +327,8 @@ class ServerlessStepFunctions {
328327 promises . push ( key ) ;
329328 } ) ;
330329
331- return BbPromise . map ( promises , ( value ) => {
332- return this . getIamRole ( value ) ;
333- } ) . then ( ( ) => BbPromise . resolve ( ) ) ;
330+ return BbPromise . map ( promises , ( value ) => this . getIamRole ( value ) )
331+ . then ( ( ) => BbPromise . resolve ( ) ) ;
334332 }
335333
336334 getFunctionArns ( ) {
@@ -349,22 +347,22 @@ class ServerlessStepFunctions {
349347 }
350348
351349 createIamRole ( state ) {
352- state = state || this . options . state ;
350+ const stateMachine = state || this . options . state ;
353351 return this . provider . request ( 'IAM' ,
354352 'createRole' ,
355353 {
356354 AssumeRolePolicyDocument : this . assumeRolePolicyDocument ,
357- RoleName : this . getIamRoleName ( state ) ,
355+ RoleName : this . getIamRoleName ( stateMachine ) ,
358356 } ,
359357 this . options . stage ,
360358 this . options . region )
361359 . then ( ( result ) => {
362- this . iamRoleArn [ state ] = result . Role . Arn ;
360+ this . iamRoleArn [ stateMachine ] = result . Role . Arn ;
363361 return this . provider . request ( 'IAM' ,
364362 'createPolicy' ,
365363 {
366364 PolicyDocument : this . iamPolicyStatement ,
367- PolicyName : this . getIamPolicyName ( state ) ,
365+ PolicyName : this . getIamPolicyName ( stateMachine ) ,
368366 } ,
369367 this . options . stage ,
370368 this . options . region ) ;
@@ -373,7 +371,7 @@ class ServerlessStepFunctions {
373371 'attachRolePolicy' ,
374372 {
375373 PolicyArn : result . Policy . Arn ,
376- RoleName : this . getIamRoleName ( state ) ,
374+ RoleName : this . getIamRoleName ( stateMachine ) ,
377375 } ,
378376 this . options . stage ,
379377 this . options . region )
@@ -382,21 +380,21 @@ class ServerlessStepFunctions {
382380 }
383381
384382 deleteIamRole ( state ) {
385- state = state || this . options . state ;
383+ const stateMachine = state || this . options . state ;
386384 let policyArn ;
387385 return this . provider . request ( 'STS' ,
388386 'getCallerIdentity' ,
389387 { } ,
390388 this . options . stage ,
391389 this . options . region )
392390 . then ( ( result ) => {
393- policyArn = `arn:aws:iam::${ result . Account } :policy/${ this . getIamPolicyName ( state ) } ` ;
391+ policyArn = `arn:aws:iam::${ result . Account } :policy/${ this . getIamPolicyName ( stateMachine ) } ` ;
394392
395393 return this . provider . request ( 'IAM' ,
396394 'detachRolePolicy' ,
397395 {
398396 PolicyArn : policyArn ,
399- RoleName : this . getIamRoleName ( state ) ,
397+ RoleName : this . getIamRoleName ( stateMachine ) ,
400398 } ,
401399 this . options . stage ,
402400 this . options . region ) ;
@@ -412,7 +410,7 @@ class ServerlessStepFunctions {
412410 . then ( ( ) => this . provider . request ( 'IAM' ,
413411 'deleteRole' ,
414412 {
415- RoleName : this . getIamRoleName ( state ) ,
413+ RoleName : this . getIamRoleName ( stateMachine ) ,
416414 } ,
417415 this . options . stage ,
418416 this . options . region )
@@ -422,6 +420,7 @@ class ServerlessStepFunctions {
422420 if ( error . statusCode === 404 ) {
423421 return BbPromise . resolve ( ) ;
424422 }
423+ return BbPromise . reject ( error . message ) ;
425424 } ) ;
426425 }
427426
@@ -431,27 +430,27 @@ class ServerlessStepFunctions {
431430 promises . push ( key ) ;
432431 } ) ;
433432
434- return BbPromise . map ( promises , ( state ) => {
435- return this . deleteIamRole ( state ) ;
436- } )
433+ return BbPromise . map ( promises , ( state ) => this . deleteIamRole ( state ) )
437434 . then ( ( ) => BbPromise . resolve ( ) )
438435 . catch ( ( error ) => {
439436 if ( error . statusCode === 404 ) {
440437 return BbPromise . resolve ( ) ;
441438 }
439+ return BbPromise . reject ( error . message ) ;
442440 } ) ;
443441 }
444442
445443 getStateMachineArn ( state ) {
446- state = state || this . options . state
444+ const stateMachine = state || this . options . state ;
447445 return this . provider . request ( 'STS' ,
448446 'getCallerIdentity' ,
449447 { } ,
450448 this . options . stage ,
451449 this . options . region )
452450 . then ( ( result ) => {
453- this . stateMachineArns [ state ] =
454- `arn:aws:states:${ this . region } :${ result . Account } :stateMachine:${ this . getStateMachineName ( state ) } ` ;
451+ this . stateMachineArns [ stateMachine ] =
452+ `arn:aws:states:${ this . region } :${ result . Account } :
453+ stateMachine:${ this . getStateMachineName ( stateMachine ) } ` ;
455454 return BbPromise . resolve ( ) ;
456455 } ) ;
457456 }
@@ -465,18 +464,19 @@ class ServerlessStepFunctions {
465464 . then ( ( result ) => {
466465 _ . forEach ( this . serverless . service . stepFunctions , ( value , key ) => {
467466 this . stateMachineArns [ key ] =
468- `arn:aws:states:${ this . region } :${ result . Account } :stateMachine:${ this . getStateMachineName ( key ) } ` ;
467+ `arn:aws:states:${ this . region } :${ result . Account } :
468+ stateMachine:${ this . getStateMachineName ( key ) } ` ;
469469 } ) ;
470470 return BbPromise . resolve ( ) ;
471471 } ) ;
472472 }
473473
474474 deleteStateMachine ( state ) {
475- state = state || this . options . state ;
475+ const stateMachine = state || this . options . state ;
476476 return this . provider . request ( 'StepFunctions' ,
477477 'deleteStateMachine' ,
478478 {
479- stateMachineArn : this . stateMachineArns [ state ] ,
479+ stateMachineArn : this . stateMachineArns [ stateMachine ] ,
480480 } ,
481481 this . options . stage ,
482482 this . options . region )
@@ -489,41 +489,37 @@ class ServerlessStepFunctions {
489489 promises . push ( key ) ;
490490 } ) ;
491491
492- return BbPromise . map ( promises , ( state ) => {
493- return this . deleteStateMachine ( state ) ;
494- } ) . then ( ( ) => BbPromise . resolve ( ) ) ;
492+ return BbPromise
493+ . map ( promises , ( state ) => this . deleteStateMachine ( state ) )
494+ . then ( ( ) => BbPromise . resolve ( ) ) ;
495495 }
496496
497497 createStateMachine ( state ) {
498- state = state || this . options . state ;
498+ const stateMachine = state || this . options . state ;
499499 return this . provider . request ( 'StepFunctions' ,
500500 'createStateMachine' ,
501501 {
502- definition : this . serverless . service . stepFunctions [ state ] ,
503- name : this . getStateMachineName ( state ) ,
504- roleArn : this . iamRoleArn [ state ] ,
502+ definition : this . serverless . service . stepFunctions [ stateMachine ] ,
503+ name : this . getStateMachineName ( stateMachine ) ,
504+ roleArn : this . iamRoleArn [ stateMachine ] ,
505505 } ,
506506 this . options . stage ,
507507 this . options . region )
508- . then ( ( ) => {
509- return BbPromise . resolve ( ) ;
510- } ) . catch ( ( error ) => {
508+ . then ( ( ) => BbPromise . resolve ( ) )
509+ . catch ( ( error ) => {
511510 if ( error . message . match ( / S t a t e M a c h i n e i s b e i n g d e l e t e d / ) ) {
512511 this . serverless . cli . printDot ( ) ;
513- this . createStateMachine . bin
514- return this . setTimeout ( ) . then ( ( ) => {
515- return this . createStateMachine ( state ) ;
516- } ) ;
517- } else {
518- throw new this . serverless . classes . Error ( error . message ) ;
512+ return this . setTimeout ( )
513+ . then ( ( ) => this . createStateMachine ( stateMachine ) ) ;
519514 }
515+ throw new this . serverless . classes . Error ( error . message ) ;
520516 } ) ;
521517 }
522518
523519 setTimeout ( ) {
524- return new BbPromise ( ( resolve , reject ) => {
520+ return new BbPromise ( ( resolve ) => {
525521 setTimeout ( resolve , 5000 ) ;
526- } )
522+ } ) ;
527523 }
528524
529525 createStateMachines ( ) {
@@ -532,9 +528,9 @@ class ServerlessStepFunctions {
532528 promises . push ( key ) ;
533529 } ) ;
534530
535- return BbPromise . map ( promises , ( state ) => {
536- return this . createStateMachine ( state ) ;
537- } ) . then ( ( ) => BbPromise . resolve ( ) ) ;
531+ return BbPromise
532+ . map ( promises , ( state ) => this . createStateMachine ( state ) )
533+ . then ( ( ) => BbPromise . resolve ( ) ) ;
538534 }
539535
540536 parseInputdate ( ) {
@@ -653,7 +649,8 @@ class ServerlessStepFunctions {
653649 _ . forEach ( this . functionArns , ( value , key ) => {
654650 const regExp = new RegExp ( `"Resource":"${ key } "` , 'g' ) ;
655651 this . serverless . service . stepFunctions [ this . options . state ] =
656- this . serverless . service . stepFunctions [ this . options . state ] . replace ( regExp , `"Resource":"${ value } "` ) ;
652+ this . serverless . service . stepFunctions [ this . options . state ]
653+ . replace ( regExp , `"Resource":"${ value } "` ) ;
657654 } ) ;
658655 return BbPromise . resolve ( ) ;
659656 }
@@ -674,7 +671,8 @@ class ServerlessStepFunctions {
674671 const regExp = new RegExp ( `"Resource":"${ functionKey } "` , 'g' ) ;
675672 _ . forEach ( this . serverless . service . stepFunctions , ( stepFunctionObj , stepFunctionKey ) => {
676673 this . serverless . service . stepFunctions [ stepFunctionKey ] =
677- this . serverless . service . stepFunctions [ stepFunctionKey ] . replace ( regExp , `"Resource":"${ functionObj } "` ) ;
674+ this . serverless . service . stepFunctions [ stepFunctionKey ]
675+ . replace ( regExp , `"Resource":"${ functionObj } "` ) ;
678676 } ) ;
679677 } ) ;
680678 return BbPromise . resolve ( ) ;
0 commit comments