Skip to content

Commit aa5c414

Browse files
committed
update project structure
1 parent b9a35c5 commit aa5c414

File tree

3 files changed

+57
-45
lines changed

3 files changed

+57
-45
lines changed

index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
const BbPromise = require('bluebird');
3+
const deploy = require('./lib/deploy');
4+
5+
class ServerlessStepFunctions {
6+
constructor(serverless, options) {
7+
this.serverless = serverless;
8+
this.options = options;
9+
this.provider = this.serverless.getProvider('aws');
10+
11+
Object.assign(
12+
this,
13+
deploy
14+
);
15+
16+
this.commands = {
17+
deploy: {
18+
commands: {
19+
stepf: {
20+
usage: 'Deploy Step functions',
21+
lifecycleEvents: [
22+
'deploy',
23+
],
24+
options: {
25+
statemachine: {
26+
usage: 'Name of the State Machine',
27+
shortcut: 'sm',
28+
required: true,
29+
},
30+
},
31+
},
32+
},
33+
},
34+
};
35+
36+
this.hooks = {
37+
'deploy:stepf:deploy': () => BbPromise.bind(this)
38+
.then(this.deploy),
39+
};
40+
}
41+
}
42+
module.exports = ServerlessStepFunctions;

lib/index.js renamed to lib/deploy.js

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,10 @@ const BbPromise = require('bluebird');
33
const path = require('path');
44
const _ = require('lodash');
55

6-
class AwsStepFunctionsDeploy {
7-
constructor(serverless, options) {
8-
this.serverless = serverless;
9-
this.options = options;
10-
this.provider = this.serverless.getProvider('aws');
6+
module.exports = {
7+
deploy() {
118
this.awsStateLanguage = {};
129
this.functionArns = {};
13-
this.commands = {
14-
deploy: {
15-
commands: {
16-
stepf: {
17-
usage: 'Deploy Step functions',
18-
lifecycleEvents: [
19-
'deploy',
20-
],
21-
options: {
22-
statemachine: {
23-
usage: 'Name of the State Machine',
24-
shortcut: 'sm',
25-
required: true,
26-
},
27-
},
28-
},
29-
},
30-
},
31-
};
32-
33-
this.hooks = {
34-
'deploy:stepf:deploy': this.action.bind(this),
35-
};
3610

3711
this.iamPolicyStatement = `{
3812
"Version": "2012-10-17",
@@ -47,11 +21,6 @@ class AwsStepFunctionsDeploy {
4721
]
4822
}
4923
`;
50-
this.iamRoleName = 'serverless-step-functions-executerole';
51-
}
52-
53-
action() {
54-
this.serverless.cli.consoleLog('Start Deploy Step Functions');
5524
BbPromise.bind(this)
5625
.then(this.yamlParse)
5726
.then(this.getStateMachineArn)
@@ -60,7 +29,9 @@ class AwsStepFunctionsDeploy {
6029
.then(this.getIamRole)
6130
.then(this.deleteStateMachine)
6231
.then(this.createStateMachine);
63-
}
32+
33+
return BbPromise.resolve();
34+
},
6435

6536
getIamRole() {
6637
return this.provider.request('IAM',
@@ -79,7 +50,7 @@ class AwsStepFunctionsDeploy {
7950
}
8051
return BbPromise.reject();
8152
});
82-
}
53+
},
8354

8455
getFunctionArns() {
8556
return this.provider.request('STS',
@@ -95,7 +66,7 @@ class AwsStepFunctionsDeploy {
9566
});
9667
return BbPromise.resolve();
9768
});
98-
}
69+
},
9970

10071
createIamRole() {
10172
return this.provider.request('IAM',
@@ -110,7 +81,7 @@ class AwsStepFunctionsDeploy {
11081
this.iamRoleArn = result.Role.Arn;
11182
return BbPromise.resolve();
11283
});
113-
}
84+
},
11485

11586
getStateMachineArn() {
11687
return this.provider.request('STS',
@@ -124,7 +95,7 @@ class AwsStepFunctionsDeploy {
12495
`arn:aws:states:${region}:${result.Account}:stateMachine:${this.options.statemachine}`;
12596
return BbPromise.resolve();
12697
});
127-
}
98+
},
12899

129100
yamlParse() {
130101
const servicePath = this.serverless.config.servicePath;
@@ -145,7 +116,7 @@ class AwsStepFunctionsDeploy {
145116
this.stepFunctions = serverlessFileParam.stepFunctions;
146117
return BbPromise.resolve();
147118
});
148-
}
119+
},
149120

150121
compile() {
151122
if (!this.stepFunctions) {
@@ -169,7 +140,7 @@ class AwsStepFunctionsDeploy {
169140
this.awsStateLanguage[this.options.statemachine] =
170141
JSON.stringify(this.stepFunctions[this.options.statemachine]);
171142
return BbPromise.resolve();
172-
}
143+
},
173144

174145
deleteStateMachine() {
175146
return this.provider.request('StepFunctions',
@@ -180,7 +151,7 @@ class AwsStepFunctionsDeploy {
180151
this.options.stage,
181152
this.options.region)
182153
.then(() => BbPromise.resolve());
183-
}
154+
},
184155

185156
createStateMachine() {
186157
return this.provider.request('StepFunctions',
@@ -198,6 +169,5 @@ class AwsStepFunctionsDeploy {
198169
setTimeout(this.createStateMachine.bind(this), 5000);
199170
}
200171
});
201-
}
202-
}
203-
module.exports = AwsStepFunctionsDeploy;
172+
},
173+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "serverless-step-functions",
33
"version": "0.1.0",
44
"description": "The module is AWS Step Functions plugin for Serverless Framework",
5-
"main": "lib/index.js",
5+
"main": "index.js",
66
"scripts": {
77
"test": "npm run test",
88
"lint": "eslint ."

0 commit comments

Comments
 (0)