-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
50 lines (42 loc) · 1.49 KB
/
index.ts
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
import * as _ from 'lodash';
import { ServerlessInstance } from './types';
class ServerlessPlugin {
private originalServicePath: string;
serverless: ServerlessInstance;
hooks: { [key: string]: Function };
constructor(serverless: ServerlessInstance) {
this.serverless = serverless;
this.hooks = {
'after:package:initialize': this.afterInit.bind(this),
'before:package:finalize': this.beforeDeploy.bind(this)
};
}
async afterInit(): Promise<void> {
const apiGatewayOverrides = this.serverless.service.custom.apiGatewayOverrides;
const template = this.serverless.service.provider.compiledCloudFormationTemplate;
const stage = this.serverless.service.provider.stage;
this.serverless.cli.log('Applying Lambda Function Name Overrides');
for (const prop in this.serverless.service.functions) {
const func = this.serverless.service.functions[prop];
if (func) {
func.name = func.name.replace(`${stage}-`, '');
}
}
}
async beforeDeploy(): Promise<void> {
const apiGatewayOverrides = this.serverless.service.custom.apiGatewayOverrides;
const template = this.serverless.service.provider.compiledCloudFormationTemplate;
this.serverless.cli.log('Applying API Gateway Overrides');
_.extend(template.Resources,
{
ApiGatewayRestApi: {
Type: 'AWS::ApiGateway::RestApi',
Properties: {
Name: apiGatewayOverrides.name
}
}
}
);
}
}
export = ServerlessPlugin