forked from serverless/serverless
/
normalizeFiles.js
36 lines (32 loc) · 1.17 KB
/
normalizeFiles.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
'use strict';
const _ = require('lodash');
module.exports = {
normalizeCloudFormationTemplate(template) {
const normalizedTemplate = _.cloneDeep(template);
Object.entries(normalizedTemplate.Resources).forEach(([key, value]) => {
if (key.startsWith('ApiGatewayDeployment')) {
delete Object.assign(normalizedTemplate.Resources, {
ApiGatewayDeployment: normalizedTemplate.Resources[key],
})[key];
}
if (key.startsWith('WebsocketsDeployment') && key !== 'WebsocketsDeploymentStage') {
delete Object.assign(normalizedTemplate.Resources, {
WebsocketsDeployment: normalizedTemplate.Resources[key],
})[key];
}
if (key === 'WebsocketsDeploymentStage') {
const newVal = value;
newVal.Properties.DeploymentId.Ref = 'WebsocketsDeployment';
}
if (value.Type && value.Type === 'AWS::Lambda::Function') {
const newVal = value;
newVal.Properties.Code.S3Key = '';
}
if (value.Type && value.Type === 'AWS::Lambda::LayerVersion') {
const newVal = value;
newVal.Properties.Content.S3Key = '';
}
});
return normalizedTemplate;
},
};