Skip to content

Commit dc053e1

Browse files
committed
second commit
1 parent bfd4cfe commit dc053e1

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

lib/index.js

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,101 @@
11
'use strict';
2+
const BbPromise = require('bluebird');
3+
const path = require('path');
4+
const _ = require('lodash');
25

36
class AwsStepFunctionsDeploy {
47
constructor(serverless, options) {
58
this.serverless = serverless;
69
this.options = options;
10+
this.provider = this.serverless.getProvider('aws');
11+
this.awsStateLanguage = {};
712

813
this.hooks = {
9-
'deploy:deploy': this.deploy.bind(this),
14+
'before:deploy:deploy': this.action.bind(this),
1015
};
1116
}
1217

13-
deploy() {
18+
action() {
1419
this.serverless.cli.consoleLog('Start Deploy Step Functions');
20+
BbPromise.bind(this)
21+
.then(this.yamlParse)
22+
.then(this.compile)
23+
.then(this.deploy);
1524
}
25+
26+
yamlParse() {
27+
const servicePath = this.serverless.config.servicePath;
28+
29+
if (!servicePath) {
30+
return BbPromise.resolve();
31+
}
32+
33+
let serverlessYmlPath = path.join(servicePath, 'serverless.yml');
34+
if (!this.serverless.utils.fileExistsSync(serverlessYmlPath)) {
35+
serverlessYmlPath = path
36+
.join(this.serverless.config.servicePath, 'serverless.yaml');
37+
}
38+
39+
return this.serverless.yamlParser
40+
.parse(serverlessYmlPath)
41+
.then((serverlessFileParam) => {
42+
this.stepFunctions = serverlessFileParam.stepFunctions;
43+
return BbPromise.resolve();
44+
});
45+
}
46+
47+
compile() {
48+
if (!this.stepFunctions) {
49+
return BbPromise.resolve();
50+
}
51+
52+
53+
_.forEach(this.stepFunctions, function (stateMachine, stateMachineName) {
54+
if (!stateMachine.start) {
55+
const errorMessage = [
56+
' Please set `start` in stepFunctions statements in serverless.yml .',
57+
].join('');
58+
throw new this.serverless.classes
59+
.Error(errorMessage);
60+
}
61+
62+
//@todo error handling to not stateMachine.states
63+
64+
const StartAt = stateMachine.start;
65+
const Comment = stateMachine.comment;
66+
this.awsStateLanguage[stateMachineName] = {
67+
Comment: Comment || 'Step Functions Generated by Serverless Step Functions.',
68+
StartAt,
69+
States: {},
70+
};
71+
72+
_.forEach(stateMachine.states, function (state) {
73+
//@todo error handling to not type and resource
74+
const Type = state.type;
75+
const Resource = state.resource;
76+
this.awsStateLanguage[stateMachineName].States = {
77+
Type,
78+
Resource,
79+
End: 'true'
80+
}
81+
});
82+
});
83+
84+
return BbPromise.resolve();
85+
}
86+
87+
deploy() {
88+
return this.provider.request('StepFunctions',
89+
'createStateMachine',
90+
{
91+
definition: 'STRING_VALUE',
92+
name: 'STRING_VALUE',
93+
roleArn: 'STRING_VALUE'
94+
},
95+
this.options.stage,
96+
this.options.region);
97+
98+
}
99+
16100
}
17101
module.exports = AwsStepFunctionsDeploy;

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,10 @@
2727
"eslint-plugin-import": "^1.13.0",
2828
"eslint-plugin-jsx-a11y": "^2.1.0",
2929
"eslint-plugin-react": "^6.1.1"
30+
},
31+
"dependencies": {
32+
"lodash": "^4.13.1",
33+
"aws-sdk": "^2.7.19",
34+
"bluebird": "^3.4.0"
3035
}
3136
}

0 commit comments

Comments
 (0)