-
Notifications
You must be signed in to change notification settings - Fork 40
/
parse.js
72 lines (60 loc) · 2.83 KB
/
parse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const Promise = require('bluebird');
const path = require('path');
module.exports = {
getRawConfig() {
const serverlessPath = this.serverless.config.servicePath;
if (!serverlessPath) {
throw new this.serverless
.classes.Error('Could not find serverless manifest');
}
const manifestFilenames = [
'serverless.yaml',
'serverless.yml',
'serverless.json',
'serverless.js',
];
const manifestFilename = manifestFilenames.map((filename) => path.join(serverlessPath, filename))
.find((filename) => this.serverless.utils.fileExistsSync(filename));
if (!manifestFilename) {
throw new this.serverless.classes.Error('Could not find serverless manifest');
}
if (/\.json|\.js$/.test(manifestFilename)) {
return Promise.resolve(require(manifestFilename));
}
return this.serverless.yamlParser.parse(manifestFilename);
},
parseConfig() {
return this.getRawConfig()
.then((serverlessFileParam) => {
this.serverless.service.stepFunctions = {};
this.serverless.service.stepFunctions.stateMachines
= serverlessFileParam.stepFunctions
&& serverlessFileParam.stepFunctions.stateMachines
? serverlessFileParam.stepFunctions.stateMachines : {};
this.serverless.service.stepFunctions.activities
= serverlessFileParam.stepFunctions
&& serverlessFileParam.stepFunctions.activities
? serverlessFileParam.stepFunctions.activities : [];
if (!this.serverless.pluginManager.cliOptions.stage) {
this.serverless.pluginManager.cliOptions.stage = this.options.stage
|| (this.serverless.service.provider && this.serverless.service.provider.stage)
|| 'dev';
}
if (!this.serverless.pluginManager.cliOptions.region) {
this.serverless.pluginManager.cliOptions.region = this.options.region
|| (this.serverless.service.provider && this.serverless.service.provider.region)
|| 'us-east-1';
}
this.serverless.variables.populateService(this.serverless.pluginManager.cliOptions);
return Promise.resolve();
});
},
getStateMachine(stateMachineName) {
if (stateMachineName in this.serverless.service.stepFunctions.stateMachines) {
return this.serverless.service.stepFunctions.stateMachines[stateMachineName];
}
throw new this.serverless.classes
.Error(`stateMachine "${stateMachineName}" doesn't exist in this Service`);
}
};