@@ -237,14 +237,37 @@ class ServerlessStepFunctions {
237237 }
238238
239239 stateMachineRemove ( ) {
240- return BbPromise . bind ( this )
241- . then ( this . deleteIamRole )
242- . then ( this . getStateMachineArn )
243- . then ( this . deleteStateMachine )
244- . then ( ( ) => {
245- this . serverless . cli . log ( `Remove ${ this . options . state } ` ) ;
246- return BbPromise . resolve ( ) ;
247- } ) ;
240+ if ( this . options . state ) {
241+ return BbPromise . bind ( this )
242+ . then ( this . yamlParse )
243+ . then ( this . deleteIamRole )
244+ . then ( this . getStateMachineArn )
245+ . then ( this . deleteStateMachine )
246+ . then ( ( ) => {
247+ this . serverless . cli . log ( `Remove ${ this . options . state } ` ) ;
248+ return BbPromise . resolve ( ) ;
249+ } ) ;
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+ } ) ;
270+ }
248271 }
249272
250273 stateMachineInvoke ( ) {
@@ -394,7 +417,29 @@ class ServerlessStepFunctions {
394417 this . options . stage ,
395418 this . options . region )
396419 )
397- . then ( ( ) => BbPromise . resolve ( ) ) ;
420+ . then ( ( ) => BbPromise . resolve ( ) )
421+ . catch ( ( error ) => {
422+ if ( error . statusCode === 404 ) {
423+ return BbPromise . resolve ( ) ;
424+ }
425+ } ) ;
426+ }
427+
428+ deleteIamRoles ( ) {
429+ const promises = [ ] ;
430+ _ . forEach ( this . serverless . service . stepFunctions , ( value , key ) => {
431+ promises . push ( key ) ;
432+ } ) ;
433+
434+ return BbPromise . map ( promises , ( state ) => {
435+ return this . deleteIamRole ( state ) ;
436+ } )
437+ . then ( ( ) => BbPromise . resolve ( ) )
438+ . catch ( ( error ) => {
439+ if ( error . statusCode === 404 ) {
440+ return BbPromise . resolve ( ) ;
441+ }
442+ } ) ;
398443 }
399444
400445 getStateMachineArn ( state ) {
0 commit comments