-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
53 lines (40 loc) · 1.43 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
51
52
53
import Serverless, { Options } from 'serverless';
import { PipelineConfig } from './src/PluginConfig';
import { PipelineBuilder } from './src/PipelineBuilder';
type Hook = {
'before:package:initialize': () => void;
};
class ServerlessPlugin {
private readonly serverless: Serverless;
private readonly options: Options;
private readonly hooks: Hook;
public constructor(serverless: Serverless, options: Options) {
this.serverless = serverless;
this.options = options;
this.hooks = {
'before:package:initialize': this.buildPipeline.bind(this),
};
}
private async buildPipeline(): Promise<void> {
const pipelineConfig = this.getPipelineConfig();
if (pipelineConfig && pipelineConfig.enabled) {
const resources = this.getResources();
const createdResources = PipelineBuilder.build(pipelineConfig);
Object.assign(resources, createdResources);
}
}
private getPipelineConfig(): PipelineConfig | undefined {
if (this.serverless.service.custom.codepipeline) {
return new PipelineConfig(this.serverless.service.custom.codepipeline, this.serverless.service);
}
}
private getResources(): any {
const service = this.serverless.service as any;
if (!service.resources)
service.resources = { Resources: {} };
if (!service.resources.Resources)
service.resources.Resources = {};
return service.resources.Resources;
}
}
module.exports = ServerlessPlugin;